|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Crocodicstudio\Crudbooster\CBCoreModule\Installer; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Process\Process; |
|
6
|
|
|
|
|
7
|
|
|
class CbInstaller |
|
8
|
|
|
{ |
|
9
|
|
|
private $console; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* ConsolePrinter constructor. |
|
13
|
|
|
* |
|
14
|
|
|
* @param $console |
|
15
|
|
|
*/ |
|
16
|
|
|
public function __construct($console) |
|
17
|
|
|
{ |
|
18
|
|
|
$this->console = $console; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function createVendorAtPublic() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->console->info('Checking public/vendor directory...'); |
|
24
|
|
|
if (! file_exists(public_path('vendor'))) { |
|
25
|
|
|
mkdir(public_path('vendor'), 0777); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
if (! is_writable(public_path('vendor'))) { |
|
29
|
|
|
$this->console->info('Setup aborted !'); |
|
30
|
|
|
$this->console->info('Please set public/vendor directory to writable 0777'); |
|
31
|
|
|
exit; |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function installCrudbooster() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->publishFiles(); |
|
38
|
|
|
$this->composerDumpAutoload(); |
|
39
|
|
|
$this->migrateDatabase(); |
|
40
|
|
|
$this->seedDatabase(); |
|
41
|
|
|
$this->console->call('config:clear'); |
|
42
|
|
|
if (app()->version() < 5.6) { |
|
|
|
|
|
|
43
|
|
|
$this->console->call('optimize'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$this->console->info('Installing CRUDBooster Is Completed ! Thank You :)'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get the composer command for the environment. |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
private function findComposer() |
|
55
|
|
|
{ |
|
56
|
|
|
if (file_exists(getcwd().'/composer.phar')) { |
|
57
|
|
|
return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar'; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return 'composer'; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
private function publishFiles() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->console->info('Publishing CRUDBooster needs file...'); |
|
66
|
|
|
$this->console->callSilent('vendor:publish', ['--provider' => 'Crocodicstudio\\Crudbooster\\CRUDBoosterServiceProvider', '--force' => true]); |
|
67
|
|
|
$this->console->callSilent('vendor:publish', ['--tag' => 'cb_migration', '--force' => true]); |
|
68
|
|
|
$this->console->callSilent('vendor:publish', ['--tag' => 'cb_lfm', '--force' => true]); |
|
69
|
|
|
$this->console->callSilent('vendor:publish', ['--tag' => 'cb_localization', '--force' => true]); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
private function migrateDatabase() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->console->info('Migrating Database...'); |
|
75
|
|
|
$this->console->callSilent('migrate', ['--path' => '\database\migrations\crudbooster']); |
|
76
|
|
|
$this->console->callSilent('migrate'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
private function seedDatabase() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->console->info('Seeding Database...'); |
|
82
|
|
|
$this->console->callSilent('db:seed', ['--class' => '\Crocodicstudio\Crudbooster\Modules\EmailTemplates\Seeder']); |
|
83
|
|
|
$this->console->callSilent('db:seed', ['--class' => '\Crocodicstudio\Crudbooster\Modules\SettingModule\Seeder']); |
|
84
|
|
|
$this->console->callSilent('db:seed', ['--class' => '\Crocodicstudio\Crudbooster\Modules\PrivilegeModule\Seeder']); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
private function composerDumpAutoload() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->console->info('Dumping the autoloaded files and reloading all new files...'); |
|
90
|
|
|
$composer = $this->findComposer(); |
|
91
|
|
|
$process = new Process($composer.' dumpautoload'); |
|
|
|
|
|
|
92
|
|
|
$process->setWorkingDirectory(base_path())->run(); |
|
93
|
|
|
} |
|
94
|
|
|
} |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.