Passed
Push — master ( 72fffe...b949dd )
by Ferry
04:19
created

Install::findComposer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 0
1
<?php namespace crocodicstudio\crudbooster\commands;
2
3
use App;
4
use Cache;
5
use crocodicstudio\crudbooster\helpers\ComposerHelper;
6
use Illuminate\Support\Facades\DB;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Str;
9
use Symfony\Component\Process\Process;
10
11
class Install extends Command
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $signature = '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
41
        if ($this->confirm('Do you have setting the database configuration at .env ?')) {
42
43
            if (! file_exists(public_path('vendor')) ) {
44
                mkdir(public_path('vendor'));
45
            }
46
47
            $this->info('Please wait CRUDBooster publish assets...');
48
            $this->call('vendor:publish', ['--tag' => 'cb_config']);
49
            $this->call('vendor:publish', ['--tag' => 'cb_hook']);
50
            $this->call('vendor:publish', ['--tag' => 'cb_asset', '--force' => true]);
51
            $this->call('vendor:publish', ['--tag' => 'cb_migration', '--force' => true]);
52
53
            /*
54
             * Add some env for CB
55
             */
56
            setEnvironmentValue([
57
                "APP_DEBUG"=> false
58
            ]);
59
60
            /*
61
             * Create CBPlugins
62
             */
63
            if(!file_exists(app_path("CBPlugins"))) {
64
                mkdir(app_path("CBPlugins"));
65
            }
66
67
            /*
68
             * Create storage dir on public
69
             * We need it to change default laravel local filesystem from storage to public
70
             * We won't use symlink because of a security issue in many server
71
             */
72
            if(!file_exists(public_path("storage"))) {
73
                $this->info("Create storage directory on /public");
74
                mkdir(public_path("storage"));
75
                file_put_contents(public_path("storage/.gitignore"),"!.gitignore");
76
                file_put_contents(public_path("storage/index.html"),"&nbsp;");
77
            }
78
79
            /*
80
             * We want to add more security to your Laravel
81
             * Disable index listing
82
             * Disable php execution on /vendor/*
83
             */
84
            $this->info("Tweak some security for your laravel");
85
            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);
86
            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);
87
88
89
            $this->info('Dumping the autoloaded files and reloading all new files...');
90
            ComposerHelper::dumpAutoLoad();
91
92
            $this->info('Migrating database...');
93
            $this->call('migrate');
94
95
            $this->call('config:clear');
96
            if (app()->version() < 5.6) {
0 ignored issues
show
introduced by
The method version() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

96
            if (app()->/** @scrutinizer ignore-call */ version() < 5.6) {
Loading history...
97
                $this->call('optimize');
98
            }
99
100
            $this->info('Installing CRUDBooster Is Completed ! Thank You :)');
101
        } else {
102
            $this->info('Setup Aborted !');
103
            $this->info('Please setting the database configuration for first !');
104
        }
105
106
        $this->footer();
107
    }
108
109
    private function header()
110
    {
111
        $this->info("
112
#     __________  __  ______  ____                   __           
113
#    / ____/ __ \/ / / / __ \/ __ )____  ____  _____/ /____  _____
114
#   / /   / /_/ / / / / / / / __  / __ \/ __ \/ ___/ __/ _ \/ ___/
115
#  / /___/ _, _/ /_/ / /_/ / /_/ / /_/ / /_/ (__  ) /_/  __/ /    
116
#  \____/_/ |_|\____/_____/_____/\____/\____/____/\__/\___/_/     
117
#                                                                                                                       
118
			");
119
        $this->info('--------- :===: Thanks for choosing CRUDBooster :==: ---------------');
120
        $this->info('====================================================================');
121
    }
122
123
    private function checkRequirements()
124
    {
125
        $this->info('System Requirements Checking:');
126
        $system_failed = 0;
127
        $laravel = app();
128
129
        if ($laravel::VERSION >= 5.6) {
0 ignored issues
show
Bug introduced by
The constant Illuminate\Container\Container::VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
130
            $this->info('Laravel Version (>= 5.6): [Good]');
131
        } else {
132
            $this->warn('Laravel Version (>= 5.6): [Bad]');
133
            $system_failed++;
134
        }
135
136
        if (version_compare(phpversion(), '7.1.3', '>=')) {
137
            $this->info('PHP Version (>= 7.*): [Good]');
138
        } else {
139
            $this->warn('PHP Version (>= 7.*): [Bad] Yours: '.phpversion());
140
            $system_failed++;
141
        }
142
143
        if (extension_loaded('mbstring')) {
144
            $this->info('Mbstring extension: [Good]');
145
        } else {
146
            $this->warn('Mbstring extension: [Bad]');
147
            $system_failed++;
148
        }
149
150
        if (extension_loaded('openssl')) {
151
            $this->info('OpenSSL extension: [Good]');
152
        } else {
153
            $this->warn('OpenSSL extension: [Bad]');
154
            $system_failed++;
155
        }
156
157
        if (extension_loaded('pdo')) {
158
            $this->info('PDO extension: [Good]');
159
        } else {
160
            $this->warn('PDO extension: [Bad]');
161
            $system_failed++;
162
        }
163
164
        if (extension_loaded('tokenizer')) {
165
            $this->info('Tokenizer extension: [Good]');
166
        } else {
167
            $this->warn('Tokenizer extension: [Bad]');
168
            $system_failed++;
169
        }
170
171
        if (extension_loaded('xml')) {
172
            $this->info('XML extension: [Good]');
173
        } else {
174
            $this->warn('XML extension: [Bad]');
175
            $system_failed++;
176
        }
177
178
        if (extension_loaded('gd')) {
179
            $this->info('GD extension: [Good]');
180
        } else {
181
            $this->warn('GD extension: [Bad]');
182
            $system_failed++;
183
        }
184
185
        if (extension_loaded('fileinfo')) {
186
            $this->info('PHP Fileinfo extension: [Good]');
187
        } else {
188
            $this->warn('PHP Fileinfo extension: [Bad]');
189
            $system_failed++;
190
        }
191
192
        if (is_writable(base_path('public'))) {
193
            $this->info('public dir is writable: [Good]');
194
        } else {
195
            $this->warn('public dir is writable: [Bad]');
196
            $system_failed++;
197
        }
198
199
        if ($system_failed != 0) {
200
            $this->warn('Sorry unfortunately your system is not meet with our requirements !');
201
            $this->footer(false);
202
        }
203
        $this->info('--');
204
    }
205
206
    private function footer($success = true)
207
    {
208
209
        $this->info('--');
210
211
        (new DeveloperCommandService($this))->create();
212
213
        $this->info("--");
214
        $this->info('Homepage : http://crudbooster.com');
215
        $this->info('Github : https://github.com/crocodic-studio/crudbooster');
216
        $this->info('====================================================================');
217
        if ($success == true) {
218
            $this->info('------------------- :===: Completed !! :===: ------------------------');
219
        } else {
220
            $this->info('------------------- :===: Failed !!    :===: ------------------------');
221
        }
222
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
223
    }
224
225
}
226