1
|
|
|
<?php namespace crocodicstudio\crudbooster\commands; |
2
|
|
|
|
3
|
|
|
use App; |
4
|
|
|
use Cache; |
5
|
|
|
use Illuminate\Support\Facades\DB; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
use Illuminate\Support\Str; |
8
|
|
|
use Symfony\Component\Process\Process; |
9
|
|
|
|
10
|
|
|
class Install extends Command |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* The console command name. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $signature = 'crudbooster:install'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'CRUDBooster Installation Command'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Execute the console command. |
28
|
|
|
* |
29
|
|
|
* @return mixed |
30
|
|
|
*/ |
31
|
|
|
public function handle() |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
$this->header(); |
35
|
|
|
|
36
|
|
|
$this->checkRequirements(); |
37
|
|
|
|
38
|
|
|
$this->info('Installing: '); |
39
|
|
|
|
40
|
|
|
if ($this->confirm('Do you have setting the database configuration at .env ?')) { |
41
|
|
|
|
42
|
|
|
if (! file_exists(public_path('vendor')) ) { |
43
|
|
|
mkdir(public_path('vendor')); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$this->info('Please wait CRUDBooster publish assets...'); |
47
|
|
|
$this->call('vendor:publish', ['--tag' => 'cb_config']); |
48
|
|
|
$this->call('vendor:publish', ['--tag' => 'cb_hook']); |
49
|
|
|
$this->call('vendor:publish', ['--tag' => 'cb_asset', '--force' => true]); |
50
|
|
|
$this->call('vendor:publish', ['--tag' => 'cb_migration', '--force' => true]); |
51
|
|
|
|
52
|
|
|
/* |
53
|
|
|
* Create CBPlugins |
54
|
|
|
*/ |
55
|
|
|
if(!file_exists(app_path("CBPlugins"))) { |
56
|
|
|
mkdir(app_path("CBPlugins")); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/* |
60
|
|
|
* Create storage dir on public |
61
|
|
|
* We need it to change default laravel local filesystem from storage to public |
62
|
|
|
* We won't use symlink because of a security issue in many server |
63
|
|
|
*/ |
64
|
|
|
if(!file_exists(public_path("storage"))) { |
65
|
|
|
$this->info("Create storage directory on /public"); |
66
|
|
|
mkdir(public_path("storage")); |
67
|
|
|
file_put_contents(public_path("storage/.gitignore"),"!.gitignore"); |
68
|
|
|
file_put_contents(public_path("storage/index.html")," "); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/* |
72
|
|
|
* We want to add more security to your Laravel |
73
|
|
|
* Disable index listing |
74
|
|
|
* Disable php execution on /vendor/* |
75
|
|
|
*/ |
76
|
|
|
$this->info("Tweak some security for your laravel"); |
77
|
|
|
file_put_contents(base_path(".htaccess"), "\n\n# Generated by CRUDBooster\nServerSignature Off\nIndexIgnore *\nRewriteRule ^(.*)/vendor/.*\.(php|rb|py)$ - [F,L,NC]\nRewriteRule ^vendor/.*\.(php|rb|py)$ - [F,L,NC]\n<FilesMatch \"^\.\">\nOrder allow,deny\nDeny from all\n</FilesMatch>",FILE_APPEND); |
78
|
|
|
file_put_contents(public_path(".htaccess"), "\n\n# Generated by CRUDBooster\nServerSignature Off\nIndexIgnore *\nRewriteRule ^(.*)/vendor/.*\.(php|rb|py)$ - [F,L,NC]\nRewriteRule ^vendor/.*\.(php|rb|py)$ - [F,L,NC]\n<FilesMatch \"^\.\">\nOrder allow,deny\nDeny from all\n</FilesMatch>",FILE_APPEND); |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
$this->info('Dumping the autoloaded files and reloading all new files...'); |
82
|
|
|
$composer = $this->findComposer(); |
83
|
|
|
$process = new Process($composer.' dump-autoload'); |
|
|
|
|
84
|
|
|
$process->setWorkingDirectory(base_path())->run(); |
85
|
|
|
|
86
|
|
|
$this->info('Migrating database...'); |
87
|
|
|
$this->call('migrate'); |
88
|
|
|
|
89
|
|
|
$this->call('config:clear'); |
90
|
|
|
if (app()->version() < 5.6) { |
|
|
|
|
91
|
|
|
$this->call('optimize'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$this->info('Installing CRUDBooster Is Completed ! Thank You :)'); |
95
|
|
|
} else { |
96
|
|
|
$this->info('Setup Aborted !'); |
97
|
|
|
$this->info('Please setting the database configuration for first !'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$this->footer(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
private function header() |
104
|
|
|
{ |
105
|
|
|
$this->info(" |
106
|
|
|
# __________ __ ______ ____ __ |
107
|
|
|
# / ____/ __ \/ / / / __ \/ __ )____ ____ _____/ /____ _____ |
108
|
|
|
# / / / /_/ / / / / / / / __ / __ \/ __ \/ ___/ __/ _ \/ ___/ |
109
|
|
|
# / /___/ _, _/ /_/ / /_/ / /_/ / /_/ / /_/ (__ ) /_/ __/ / |
110
|
|
|
# \____/_/ |_|\____/_____/_____/\____/\____/____/\__/\___/_/ |
111
|
|
|
# |
112
|
|
|
"); |
113
|
|
|
$this->info('--------- :===: Thanks for choosing CRUDBooster :==: ---------------'); |
114
|
|
|
$this->info('===================================================================='); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
private function checkRequirements() |
118
|
|
|
{ |
119
|
|
|
$this->info('System Requirements Checking:'); |
120
|
|
|
$system_failed = 0; |
121
|
|
|
$laravel = app(); |
122
|
|
|
|
123
|
|
|
if ($laravel::VERSION >= 5.6) { |
|
|
|
|
124
|
|
|
$this->info('Laravel Version (>= 5.6): [Good]'); |
125
|
|
|
} else { |
126
|
|
|
$this->warn('Laravel Version (>= 5.6): [Bad]'); |
127
|
|
|
$system_failed++; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
if (version_compare(phpversion(), '7.1.3', '>=')) { |
131
|
|
|
$this->info('PHP Version (>= 7.*): [Good]'); |
132
|
|
|
} else { |
133
|
|
|
$this->warn('PHP Version (>= 7.*): [Bad] Yours: '.phpversion()); |
134
|
|
|
$system_failed++; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
if (extension_loaded('mbstring')) { |
138
|
|
|
$this->info('Mbstring extension: [Good]'); |
139
|
|
|
} else { |
140
|
|
|
$this->warn('Mbstring extension: [Bad]'); |
141
|
|
|
$system_failed++; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
if (extension_loaded('openssl')) { |
145
|
|
|
$this->info('OpenSSL extension: [Good]'); |
146
|
|
|
} else { |
147
|
|
|
$this->warn('OpenSSL extension: [Bad]'); |
148
|
|
|
$system_failed++; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
if (extension_loaded('pdo')) { |
152
|
|
|
$this->info('PDO extension: [Good]'); |
153
|
|
|
} else { |
154
|
|
|
$this->warn('PDO extension: [Bad]'); |
155
|
|
|
$system_failed++; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
if (extension_loaded('tokenizer')) { |
159
|
|
|
$this->info('Tokenizer extension: [Good]'); |
160
|
|
|
} else { |
161
|
|
|
$this->warn('Tokenizer extension: [Bad]'); |
162
|
|
|
$system_failed++; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
if (extension_loaded('xml')) { |
166
|
|
|
$this->info('XML extension: [Good]'); |
167
|
|
|
} else { |
168
|
|
|
$this->warn('XML extension: [Bad]'); |
169
|
|
|
$system_failed++; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
if (extension_loaded('gd')) { |
173
|
|
|
$this->info('GD extension: [Good]'); |
174
|
|
|
} else { |
175
|
|
|
$this->warn('GD extension: [Bad]'); |
176
|
|
|
$system_failed++; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
if (extension_loaded('fileinfo')) { |
180
|
|
|
$this->info('PHP Fileinfo extension: [Good]'); |
181
|
|
|
} else { |
182
|
|
|
$this->warn('PHP Fileinfo extension: [Bad]'); |
183
|
|
|
$system_failed++; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
if (is_writable(base_path('public'))) { |
187
|
|
|
$this->info('public dir is writable: [Good]'); |
188
|
|
|
} else { |
189
|
|
|
$this->warn('public dir is writable: [Bad]'); |
190
|
|
|
$system_failed++; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
if ($system_failed != 0) { |
194
|
|
|
$this->warn('Sorry unfortunately your system is not meet with our requirements !'); |
195
|
|
|
$this->footer(false); |
196
|
|
|
} |
197
|
|
|
$this->info('--'); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
private function footer($success = true) |
201
|
|
|
{ |
202
|
|
|
|
203
|
|
|
$this->info('--'); |
204
|
|
|
|
205
|
|
|
(new DeveloperCommandService($this))->create(); |
206
|
|
|
|
207
|
|
|
$this->info("--"); |
208
|
|
|
$this->info('Homepage : http://crudbooster.com'); |
209
|
|
|
$this->info('Github : https://github.com/crocodic-studio/crudbooster'); |
210
|
|
|
$this->info('===================================================================='); |
211
|
|
|
if ($success == true) { |
212
|
|
|
$this->info('------------------- :===: Completed !! :===: ------------------------'); |
213
|
|
|
} else { |
214
|
|
|
$this->info('------------------- :===: Failed !! :===: ------------------------'); |
215
|
|
|
} |
216
|
|
|
exit; |
|
|
|
|
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Get the composer command for the environment. |
221
|
|
|
* |
222
|
|
|
* @return string |
223
|
|
|
*/ |
224
|
|
|
protected function findComposer() |
225
|
|
|
{ |
226
|
|
|
if (file_exists(getcwd().'/composer.phar')) { |
227
|
|
|
return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar'; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
return 'composer'; |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|