1
|
|
|
<?php namespace crocodicstudio\crudbooster\commands; |
2
|
|
|
|
3
|
|
|
use App; |
4
|
|
|
use Cache; |
5
|
|
|
use CRUDBooster; |
|
|
|
|
6
|
|
|
use DB; |
7
|
|
|
use Illuminate\Console\Command; |
8
|
|
|
use Request; |
9
|
|
|
use Symfony\Component\Process\Process; |
10
|
|
|
|
11
|
|
|
class CrudboosterInstallationCommand extends Command |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The console command name. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $name = 'crudbooster:install'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The console command description. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $description = 'CRUDBooster Installation Command'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Execute the console command. |
29
|
|
|
* |
30
|
|
|
* @return mixed |
31
|
|
|
*/ |
32
|
|
|
public function handle() |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
$this->header(); |
36
|
|
|
|
37
|
|
|
$this->checkRequirements(); |
38
|
|
|
|
39
|
|
|
$this->info('Installing: '); |
40
|
|
|
/* Removing the default user and password reset, it makes you ambigous when using CRUDBooster */ |
41
|
|
|
$this->info('I remove some default migration files from laravel...'); |
42
|
|
|
if (file_exists(base_path('database/migrations/2014_10_12_000000_create_users_table.php'))) { |
43
|
|
|
@unlink(base_path('database/migrations/2014_10_12_000000_create_users_table.php')); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
if (file_exists(base_path('database/migrations/2014_10_12_100000_create_password_resets_table.php'))) { |
46
|
|
|
@unlink(base_path('database/migrations/2014_10_12_100000_create_password_resets_table.php')); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if ($this->confirm('Do you have setting the database configuration at .env ?')) { |
50
|
|
|
|
51
|
|
|
if (! file_exists(public_path('vendor'))) { |
52
|
|
|
mkdir(public_path('vendor'), 0777); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$this->info('Publishing CRUDBooster needs file...'); |
56
|
|
|
$this->call('vendor:publish', ['--provider' => 'crocodicstudio\crudbooster\CRUDBoosterServiceProvider']); |
57
|
|
|
$this->call('vendor:publish', ['--provider' => 'Unisharp\Laravelfilemanager\LaravelFilemanagerServiceProvider']); |
58
|
|
|
$this->call('vendor:publish', ['--tag' => 'cb_migration', '--force' => true]); |
59
|
|
|
$this->call('vendor:publish', ['--tag' => 'cb_localization', '--force' => true]); |
60
|
|
|
|
61
|
|
|
$configLFM = config_path('lfm.php'); |
62
|
|
|
$configLFM = file_get_contents($configLFM); |
63
|
|
|
$configLFMModified = str_replace("['web','auth']", "['web','\crocodicstudio\crudbooster\middlewares\CBBackend']", $configLFM); |
64
|
|
|
$configLFMModified = str_replace('Unisharp\Laravelfilemanager\Handlers\ConfigHandler::class', 'function() {return Session::get("admin_id");}', $configLFMModified); |
65
|
|
|
$configLFMModified = str_replace('auth()->user()->id', 'Session::get("admin_id")', $configLFMModified); |
66
|
|
|
$configLFMModified = str_replace("'alphanumeric_filename' => false", "'alphanumeric_filename' => true", $configLFMModified); |
67
|
|
|
$configLFMModified = str_replace("'alphanumeric_directory' => false", "'alphanumeric_directory' => true", $configLFMModified); |
68
|
|
|
$configLFMModified = str_replace("'alphanumeric_directory' => false", "'alphanumeric_directory' => true", $configLFMModified); |
69
|
|
|
$configLFMModified = str_replace("'base_directory' => 'public'", "'base_directory' => 'storage/app'", $configLFMModified); |
70
|
|
|
$configLFMModified = str_replace("'images_folder_name' => 'photos'", "'images_folder_name' => 'uploads'", $configLFMModified); |
71
|
|
|
$configLFMModified = str_replace("'files_folder_name' => 'files'", "'files_folder_name' => 'uploads'", $configLFMModified); |
72
|
|
|
file_put_contents(config_path('lfm.php'), $configLFMModified); |
73
|
|
|
|
74
|
|
|
$this->info('Dumping the autoloaded files and reloading all new files...'); |
75
|
|
|
$composer = $this->findComposer(); |
76
|
|
|
$process = new Process($composer.' dumpautoload'); |
|
|
|
|
77
|
|
|
$process->setWorkingDirectory(base_path())->run(); |
78
|
|
|
|
79
|
|
|
$this->info('Migrating database...'); |
80
|
|
|
$this->call('migrate'); |
81
|
|
|
|
82
|
|
|
if (! class_exists('CBSeeder')) { |
83
|
|
|
require_once __DIR__.'/../database/seeds/CBSeeder.php'; |
84
|
|
|
} |
85
|
|
|
$this->call('db:seed', ['--class' => 'CBSeeder']); |
86
|
|
|
$this->call('config:clear'); |
87
|
|
|
if (app()->version() < 5.6) { |
|
|
|
|
88
|
|
|
$this->call('optimize'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$this->info('Installing CRUDBooster Is Completed ! Thank You :)'); |
92
|
|
|
} else { |
93
|
|
|
$this->info('Setup Aborted !'); |
94
|
|
|
$this->info('Please setting the database configuration for first !'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$this->footer(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
private function header() |
101
|
|
|
{ |
102
|
|
|
$this->info(" |
103
|
|
|
# __________ __ ______ ____ __ |
104
|
|
|
# / ____/ __ \/ / / / __ \/ __ )____ ____ _____/ /____ _____ |
105
|
|
|
# / / / /_/ / / / / / / / __ / __ \/ __ \/ ___/ __/ _ \/ ___/ |
106
|
|
|
# / /___/ _, _/ /_/ / /_/ / /_/ / /_/ / /_/ (__ ) /_/ __/ / |
107
|
|
|
# \____/_/ |_|\____/_____/_____/\____/\____/____/\__/\___/_/ |
108
|
|
|
# |
109
|
|
|
"); |
110
|
|
|
$this->info('--------- :===: Thanks for choosing CRUDBooster :==: ---------------'); |
111
|
|
|
$this->info('===================================================================='); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
private function checkRequirements() |
115
|
|
|
{ |
116
|
|
|
$this->info('System Requirements Checking:'); |
117
|
|
|
$system_failed = 0; |
118
|
|
|
$laravel = app(); |
119
|
|
|
|
120
|
|
|
if ($laravel::VERSION >= 5.3) { |
|
|
|
|
121
|
|
|
$this->info('Laravel Version (>= 5.3.*): [Good]'); |
122
|
|
|
} else { |
123
|
|
|
$this->info('Laravel Version (>= 5.3.*): [Bad]'); |
124
|
|
|
$system_failed++; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
if (version_compare(phpversion(), '5.6.0', '>=')) { |
128
|
|
|
$this->info('PHP Version (>= 5.6.*): [Good]'); |
129
|
|
|
} else { |
130
|
|
|
$this->info('PHP Version (>= 5.6.*): [Bad] Yours: '.phpversion()); |
131
|
|
|
$system_failed++; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
if (extension_loaded('mbstring')) { |
135
|
|
|
$this->info('Mbstring extension: [Good]'); |
136
|
|
|
} else { |
137
|
|
|
$this->info('Mbstring extension: [Bad]'); |
138
|
|
|
$system_failed++; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
if (extension_loaded('openssl')) { |
142
|
|
|
$this->info('OpenSSL extension: [Good]'); |
143
|
|
|
} else { |
144
|
|
|
$this->info('OpenSSL extension: [Bad]'); |
145
|
|
|
$system_failed++; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
if (extension_loaded('pdo')) { |
149
|
|
|
$this->info('PDO extension: [Good]'); |
150
|
|
|
} else { |
151
|
|
|
$this->info('PDO extension: [Bad]'); |
152
|
|
|
$system_failed++; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
if (extension_loaded('tokenizer')) { |
156
|
|
|
$this->info('Tokenizer extension: [Good]'); |
157
|
|
|
} else { |
158
|
|
|
$this->info('Tokenizer extension: [Bad]'); |
159
|
|
|
$system_failed++; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
if (extension_loaded('xml')) { |
163
|
|
|
$this->info('XML extension: [Good]'); |
164
|
|
|
} else { |
165
|
|
|
$this->info('XML extension: [Bad]'); |
166
|
|
|
$system_failed++; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
if (extension_loaded('gd')) { |
170
|
|
|
$this->info('GD extension: [Good]'); |
171
|
|
|
} else { |
172
|
|
|
$this->info('GD extension: [Bad]'); |
173
|
|
|
$system_failed++; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
if (extension_loaded('fileinfo')) { |
177
|
|
|
$this->info('PHP Fileinfo extension: [Good]'); |
178
|
|
|
} else { |
179
|
|
|
$this->info('PHP Fileinfo extension: [Bad]'); |
180
|
|
|
$system_failed++; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
if (is_writable(base_path('public'))) { |
184
|
|
|
$this->info('public dir is writable: [Good]'); |
185
|
|
|
} else { |
186
|
|
|
$this->info('public dir is writable: [Bad]'); |
187
|
|
|
$system_failed++; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
if ($system_failed != 0) { |
191
|
|
|
$this->info('Sorry unfortunately your system is not meet with our requirements !'); |
192
|
|
|
$this->footer(false); |
193
|
|
|
} |
194
|
|
|
$this->info('--'); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
private function footer($success = true) |
198
|
|
|
{ |
199
|
|
|
$this->info('--'); |
200
|
|
|
$this->info('Homepage : http://www.crudbooster.com'); |
201
|
|
|
$this->info('Github : https://github.com/crocodic-studio/crudbooster'); |
202
|
|
|
$this->info('Documentation : https://github.com/crocodic-studio/crudbooster/blob/master/docs/en/index.md'); |
203
|
|
|
$this->info('===================================================================='); |
204
|
|
|
if ($success == true) { |
205
|
|
|
$this->info('------------------- :===: Completed !! :===: ------------------------'); |
206
|
|
|
} else { |
207
|
|
|
$this->info('------------------- :===: Failed !! :===: ------------------------'); |
208
|
|
|
} |
209
|
|
|
exit; |
|
|
|
|
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Get the composer command for the environment. |
214
|
|
|
* |
215
|
|
|
* @return string |
216
|
|
|
*/ |
217
|
|
|
protected function findComposer() |
218
|
|
|
{ |
219
|
|
|
if (file_exists(getcwd().'/composer.phar')) { |
220
|
|
|
return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar'; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
return 'composer'; |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
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