1
|
|
|
<?php namespace crocodicstudio\crudbooster\commands; |
2
|
|
|
|
3
|
|
|
use Illuminate\Console\Command; |
|
|
|
|
4
|
|
|
use Illuminate\Foundation\Inspiring; |
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
|
|
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
|
|
|
7
|
|
|
use Symfony\Component\Process\Process; |
|
|
|
|
8
|
|
|
use DB; |
9
|
|
|
use Cache; |
10
|
|
|
use Request; |
11
|
|
|
use CRUDBooster; |
|
|
|
|
12
|
|
|
use App; |
13
|
|
|
|
14
|
|
|
class CrudboosterInstallationCommand extends Command |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* The console command name. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $name = 'crudbooster:install'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The console command description. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $description = 'CRUDBooster Installation Command'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Execute the console command. |
32
|
|
|
* |
33
|
|
|
* @return mixed |
34
|
|
|
*/ |
35
|
|
|
public function handle() |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
$this->printHeader(); |
39
|
|
|
|
40
|
|
|
$passes = (new RequirementChecker())->check(); |
41
|
|
|
if(!$passes) { |
42
|
|
|
$this->info('Sorry unfortunately your system is not meet with our requirements !'); |
43
|
|
|
$this->printFooter(false); |
44
|
|
|
$this->info('--'); |
45
|
|
|
exit; |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$this->info('Installing: '); |
49
|
|
|
/* Removing the default user and password reset, it makes you ambigous when using CRUDBooster */ |
50
|
|
|
$this->removeDefaultMigrations(); |
51
|
|
|
|
52
|
|
|
//Create vendor folder at public |
53
|
|
|
$this->createVendorAtPublic(); |
54
|
|
|
|
55
|
|
|
//Create symlink for uploads path |
56
|
|
|
$this->symlinkForUpload(); |
57
|
|
|
|
58
|
|
|
//Crate symlink for assets |
59
|
|
|
$this->symlinkForAsset(); |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
if($this->confirm('Do you have setting the database configuration at .env ?')) { |
63
|
|
|
$this->installCrudbooster(); |
64
|
|
|
}else{ |
65
|
|
|
$this->info('Setup Aborted !'); |
66
|
|
|
$this->info('Please setting the database configuration for first !'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$this->printFooter(); |
70
|
|
|
exit; |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
private function printHeader() { |
74
|
|
|
$this->info(" |
75
|
|
|
|
76
|
|
|
# __________ __ ______ ____ __ |
77
|
|
|
# / ____/ __ \/ / / / __ \/ __ )____ ____ _____/ /____ _____ |
78
|
|
|
# / / / /_/ / / / / / / / __ / __ \/ __ \/ ___/ __/ _ \/ ___/ |
79
|
|
|
# / /___/ _, _/ /_/ / /_/ / /_/ / /_/ / /_/ (__ ) /_/ __/ / |
80
|
|
|
# \____/_/ |_|\____/_____/_____/\____/\____/____/\__/\___/_/ |
81
|
|
|
# |
82
|
|
|
"); |
83
|
|
|
$this->info('--------- :===: Thanks for choosing CRUDBooster :==: ---------------'); |
84
|
|
|
$this->info('===================================================================='); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
private function printFooter($success = true) |
88
|
|
|
{ |
89
|
|
|
$this->info('--'); |
90
|
|
|
$this->info('Homepage : http://www.crudbooster.com'); |
91
|
|
|
$this->info('Github : https://github.com/crocodic-studio/crudbooster'); |
92
|
|
|
$this->info('Documentation : https://github.com/crocodic-studio/crudbooster/blob/master/docs/en/index.md'); |
93
|
|
|
$this->info('===================================================================='); |
94
|
|
|
if ($success == true) { |
95
|
|
|
$this->info('------------------- :===: Completed !! :===: ------------------------'); |
96
|
|
|
} else { |
97
|
|
|
$this->info('------------------- :===: Failed !! :===: ------------------------'); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get the composer command for the environment. |
103
|
|
|
* |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
protected function findComposer() |
107
|
|
|
{ |
108
|
|
|
if (file_exists(getcwd().'/composer.phar')) { |
109
|
|
|
return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar'; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return 'composer'; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
private function symlinkForUpload() |
116
|
|
|
{ |
117
|
|
|
$this->info('Checking public/uploads symlink...'); |
118
|
|
|
if (!file_exists(public_path('uploads'))) { |
|
|
|
|
119
|
|
|
$this->info('Creating public/uploads symlink...'); |
120
|
|
|
app('files')->link(storage_path('app'), public_path('uploads')); |
|
|
|
|
121
|
|
|
return; |
122
|
|
|
} |
123
|
|
|
$uploadPath = public_path('uploads'); |
124
|
|
|
$this->info('Upload Path: '.$uploadPath); |
125
|
|
|
if (realpath($uploadPath) == $uploadPath) { |
126
|
|
|
$this->info('Remove the existing uploads dir, and create a symlink for it...'); |
127
|
|
|
rrmdir(public_path('uploads')); |
128
|
|
|
app('files')->link(storage_path('app'), public_path('uploads')); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
private function symlinkForAsset() |
133
|
|
|
{ |
134
|
|
|
$this->info('Checking public/vendor/crudbooster symlink...'); |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
$vendorPath = public_path('vendor'.DIRECTORY_SEPARATOR.'crudbooster'); |
|
|
|
|
138
|
|
|
|
139
|
|
|
if (!file_exists($vendorPath)) { |
140
|
|
|
$this->info('Creating public/vendor/crudbooster symlink...'); |
141
|
|
|
app('files')->link(__DIR__.'/../assets', public_path('vendor/crudbooster')); |
|
|
|
|
142
|
|
|
return ; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$this->info('Vendor Path: '.$vendorPath); |
146
|
|
|
|
147
|
|
|
if (realpath($vendorPath) == $vendorPath) { |
148
|
|
|
$this->info('Removing public/vendor/crudbooster dir, instead of creating a symlink...'); |
149
|
|
|
rrmdir($vendorPath); |
150
|
|
|
app('files')->link(__DIR__.'/../assets', $vendorPath); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
private function removeDefaultMigrations() |
155
|
|
|
{ |
156
|
|
|
$this->info('I remove some default migration files from laravel...'); |
157
|
|
|
@unlink(base_path('database/migrations/2014_10_12_000000_create_users_table.php')); |
|
|
|
|
158
|
|
|
@unlink(base_path('database/migrations/2014_10_12_100000_create_password_resets_table.php')); |
159
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
private function installCrudbooster() |
163
|
|
|
{ |
164
|
|
|
$this->info('Publishing CRUDBooster needs file...'); |
165
|
|
|
$this->callSilent('vendor:publish', ['--provider' => 'crocodicstudio\\crudbooster\\CRUDBoosterServiceProvider', '--force' => true]); |
166
|
|
|
$this->callSilent('vendor:publish', ['--tag' => 'cb_migration', '--force' => true]); |
167
|
|
|
$this->callSilent('vendor:publish', ['--tag' => 'cb_lfm', '--force' => true]); |
168
|
|
|
$this->callSilent('vendor:publish', ['--tag' => 'cb_localization', '--force' => true]); |
169
|
|
|
|
170
|
|
|
$this->info('Dumping the autoloaded files and reloading all new files...'); |
171
|
|
|
$composer = $this->findComposer(); |
172
|
|
|
$process = new Process($composer.' dumpautoload'); |
173
|
|
|
$process->setWorkingDirectory(base_path())->run(); |
|
|
|
|
174
|
|
|
|
175
|
|
|
$this->info('Migrating database...'); |
176
|
|
|
$this->call('migrate', ['--path'=> '\database\migrations\crudbooster']); |
177
|
|
|
|
178
|
|
|
if (! class_exists('CBSeeder')) { |
179
|
|
|
require_once __DIR__.'/../database/seeds/CBSeeder.php'; |
180
|
|
|
} |
181
|
|
|
$this->callSilent('db:seed', ['--class' => 'CBSeeder']); |
182
|
|
|
$this->call('config:clear'); |
183
|
|
|
$this->call('optimize'); |
184
|
|
|
|
185
|
|
|
$this->info('Installing CRUDBooster Is Completed ! Thank You :)'); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
private function createVendorAtPublic() |
189
|
|
|
{ |
190
|
|
|
$this->info('Checking public/vendor directory...'); |
191
|
|
|
if (! file_exists(public_path('vendor'))) { |
|
|
|
|
192
|
|
|
mkdir(public_path('vendor'), 0777); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
if (! is_writable(public_path('vendor'))) { |
196
|
|
|
$this->info('Setup aborted !'); |
197
|
|
|
$this->info('Please set public/vendor directory to writable 0777'); |
198
|
|
|
exit; |
|
|
|
|
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths