|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\Base\app\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Symfony\Component\Process\Exception\ProcessFailedException; |
|
7
|
|
|
use Symfony\Component\Process\Process; |
|
8
|
|
|
|
|
9
|
|
|
class Install extends Command |
|
10
|
|
|
{ |
|
11
|
|
|
protected $progressBar; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* The name and signature of the console command. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $signature = 'backpack:base:install |
|
19
|
|
|
{--timeout=300} : How many seconds to allow each process to run. |
|
20
|
|
|
{--debug} : Show process output or not. Useful for debugging.'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The console command description. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $description = 'Require dev packages and publish files for Backpack\Base to work'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Create a new command instance. |
|
31
|
|
|
* |
|
32
|
|
|
* @return void |
|
|
|
|
|
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct() |
|
35
|
|
|
{ |
|
36
|
|
|
parent::__construct(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Execute the console command. |
|
41
|
|
|
* |
|
42
|
|
|
* @return mixed |
|
43
|
|
|
*/ |
|
44
|
|
|
public function handle() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->progressBar = $this->output->createProgressBar(8); |
|
47
|
|
|
$this->progressBar->start(); |
|
48
|
|
|
$this->info(" Backpack\Base installation started. Please wait..."); |
|
49
|
|
|
$this->progressBar->advance(); |
|
50
|
|
|
|
|
51
|
|
|
$this->line(' Installing backpack/generators'); |
|
52
|
|
|
$this->executeProcess('composer require backpack/generators:"1.2.*" --dev'); |
|
53
|
|
|
|
|
54
|
|
|
$this->line(' Installing laracasts/generators'); |
|
55
|
|
|
$this->executeProcess('composer require laracasts/generators:dev-master --dev'); |
|
56
|
|
|
|
|
57
|
|
|
$this->line(' Publishing configs, langs, views and AdminLTE files'); |
|
58
|
|
|
$this->executeProcess('php artisan vendor:publish --provider="Backpack\Base\BaseServiceProvider" --tag=minimum'); |
|
59
|
|
|
|
|
60
|
|
|
$this->line(' Publishing config for notifications - prologue/alerts'); |
|
61
|
|
|
$this->executeProcess('php artisan vendor:publish --provider="Prologue\Alerts\AlertsServiceProvider"'); |
|
62
|
|
|
|
|
63
|
|
|
$this->line(" Generating users table (using Laravel's default migrations)"); |
|
64
|
|
|
$this->executeProcess('php artisan migrate'); |
|
65
|
|
|
|
|
66
|
|
|
$this->line(" Creating App\Models\BackpackUser.php"); |
|
67
|
|
|
$this->executeProcess('php artisan backpack:base:publish-user-model'); |
|
68
|
|
|
|
|
69
|
|
|
$this->line(" Creating App\Http\Middleware\CheckIfAdmin.php"); |
|
70
|
|
|
$this->executeProcess('php artisan backpack:base:publish-middleware'); |
|
71
|
|
|
|
|
72
|
|
|
$this->progressBar->finish(); |
|
73
|
|
|
$this->info(" Backpack\Base installation finished."); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Run a SSH command. |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $command The SSH command that needs to be run |
|
80
|
|
|
* @param bool $beforeNotice Information for the user before the command is run |
|
81
|
|
|
* @param bool $afterNotice Information for the user after the command is run |
|
82
|
|
|
* |
|
83
|
|
|
* @return mixed Command-line output |
|
84
|
|
|
*/ |
|
85
|
|
|
public function executeProcess($command, $beforeNotice = false, $afterNotice = false) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->echo('info', $beforeNotice ? ' '.$beforeNotice : $command); |
|
88
|
|
|
|
|
89
|
|
|
$process = new Process($command, null, null, null, $this->option('timeout'), null); |
|
|
|
|
|
|
90
|
|
|
$process->run(function ($type, $buffer) { |
|
91
|
|
|
if (Process::ERR === $type) { |
|
92
|
|
|
$this->echo('comment', $buffer); |
|
93
|
|
|
} else { |
|
94
|
|
|
$this->echo('line', $buffer); |
|
95
|
|
|
} |
|
96
|
|
|
}); |
|
97
|
|
|
|
|
98
|
|
|
// executes after the command finishes |
|
99
|
|
|
if (!$process->isSuccessful()) { |
|
100
|
|
|
throw new ProcessFailedException($process); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
if ($this->progressBar) { |
|
104
|
|
|
$this->progressBar->advance(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if ($afterNotice) { |
|
108
|
|
|
$this->echo('info', $afterNotice); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Write text to the screen for the user to see. |
|
114
|
|
|
* |
|
115
|
|
|
* @param [string] $type line, info, comment, question, error |
|
|
|
|
|
|
116
|
|
|
* @param [string] $content |
|
|
|
|
|
|
117
|
|
|
*/ |
|
118
|
|
|
public function echo($type, $content) |
|
119
|
|
|
{ |
|
120
|
|
|
if ($this->option('debug') == false) { |
|
121
|
|
|
return; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
// skip empty lines |
|
125
|
|
|
if (trim($content)) { |
|
126
|
|
|
$this->{$type}($content); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.