|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copy theme files |
|
4
|
|
|
* |
|
5
|
|
|
* @author Hesham A. Meneisi [email protected] |
|
6
|
|
|
* @copyright 2019 Hesham Meneisi |
|
7
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Lumener\Console; |
|
11
|
|
|
|
|
12
|
|
|
use Illuminate\Console\Command; |
|
13
|
|
|
use Lumener\Helpers\ShellHelper; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* A command to require/update a plugin |
|
17
|
|
|
* |
|
18
|
|
|
* @author Charles A. Peterson <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
class PluginCommand extends Command |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var String $theme |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $theme; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var String $plugin_path |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $plugin_path; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The name and signature of the console command. |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $signature = 'lumener:plugin {--file=} {--url=}'; |
|
38
|
|
|
|
|
39
|
|
|
public function __construct() |
|
40
|
|
|
{ |
|
41
|
|
|
parent::__construct(); |
|
42
|
|
|
$this->plugin_path = LUMENER_STORAGE.'/plugins'; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Execute the console command. |
|
47
|
|
|
* |
|
48
|
|
|
* @return void |
|
49
|
|
|
*/ |
|
50
|
|
|
public function handle() |
|
51
|
|
|
{ |
|
52
|
|
|
$url = $this->option('url'); |
|
53
|
|
|
$path = $this->option('file'); |
|
54
|
|
|
if ($path) { |
|
55
|
|
|
$fname = basename($path); |
|
56
|
|
|
$this->info("Copying plugin file..."); |
|
57
|
|
|
} else { |
|
58
|
|
|
if ($url) { |
|
59
|
|
|
$this->info("Downloading plugin..."); |
|
60
|
|
|
} else { |
|
61
|
|
|
$url = config( |
|
62
|
|
|
'lumener.adminer.plugins.plugin_php', |
|
63
|
|
|
'https://raw.github.com/vrana/adminer/master/plugins/plugin.php' |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
$fname = basename($url); |
|
67
|
|
|
$path = tempnam(sys_get_temp_dir(), $fname); |
|
68
|
|
|
$response = ShellHelper::get($url, ['sink' => $path]); |
|
69
|
|
|
if ($response && $response->getStatusCode() == '200') { |
|
70
|
|
|
$this->info("Lumener: Plugin downloaded."); |
|
71
|
|
|
} else { |
|
72
|
|
|
$this->error('Lumener: Could not retrieve plugin file. ' |
|
73
|
|
|
. |
|
74
|
|
|
($response ? "\r\n[{$response->getStatusCode()}] {$response->getReasonPhrase()} {(string)$response->getBody()}" : "Connection Failed.\r\n".ShellHelper::$LastError)); |
|
75
|
|
|
return; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
if (!is_dir($this->plugin_path)) { |
|
79
|
|
|
mkdir($this->plugin_path); |
|
80
|
|
|
} |
|
81
|
|
|
ShellHelper::copy($path, $this->plugin_path."/{$fname}"); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|