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 removeDefaultMigrations() |
22
|
|
|
{ |
23
|
|
|
$this->console->info('I remove some default migration files from laravel...'); |
24
|
|
|
@unlink(base_path('database/migrations/2014_10_12_000000_create_users_table.php')); |
|
|
|
|
25
|
|
|
@unlink(base_path('database/migrations/2014_10_12_100000_create_password_resets_table.php')); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function createVendorAtPublic() |
29
|
|
|
{ |
30
|
|
|
$this->console->info('Checking public/vendor directory...'); |
31
|
|
|
if (! file_exists(public_path('vendor'))) { |
32
|
|
|
mkdir(public_path('vendor'), 0777); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if (! is_writable(public_path('vendor'))) { |
36
|
|
|
$this->console->info('Setup aborted !'); |
37
|
|
|
$this->console->info('Please set public/vendor directory to writable 0777'); |
38
|
|
|
exit; |
|
|
|
|
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function symlinkForUpload() |
43
|
|
|
{ |
44
|
|
|
$this->console->info('Checking public/uploads symlink...'); |
45
|
|
|
if (! file_exists(public_path('uploads'))) { |
46
|
|
|
$this->console->info('Creating public/uploads symlink...'); |
47
|
|
|
app('files')->link(storage_path('app'), public_path('uploads')); |
48
|
|
|
|
49
|
|
|
return; |
50
|
|
|
} |
51
|
|
|
$uploadPath = public_path('uploads'); |
52
|
|
|
$this->console->info('Upload Path: '.$uploadPath); |
53
|
|
|
if (realpath($uploadPath) == $uploadPath) { |
54
|
|
|
$this->console->info('Remove the existing uploads dir, and create a symlink for it...'); |
55
|
|
|
$this->rrmdir(public_path('uploads')); |
56
|
|
|
app('files')->link(storage_path('app'), public_path('uploads')); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function rrmdir($dir) |
61
|
|
|
{ |
62
|
|
|
if (! is_dir($dir)) { |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
foreach (scandir($dir) as $object) { |
66
|
|
|
if (in_array($object, ['.', '..'])) { |
67
|
|
|
continue; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$objPath = $dir."/".$object; |
71
|
|
|
|
72
|
|
|
if (is_dir($objPath)) { |
73
|
|
|
$this->rrmdir($objPath); |
74
|
|
|
} else { |
75
|
|
|
unlink($objPath); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
rmdir($dir); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function symlinkForAsset() |
82
|
|
|
{ |
83
|
|
|
$this->console->info('Checking public/vendor/crudbooster symlink...'); |
84
|
|
|
|
85
|
|
|
$vendorPath = public_path('vendor'.DIRECTORY_SEPARATOR.'crudbooster'); |
86
|
|
|
|
87
|
|
|
if (! file_exists($vendorPath)) { |
88
|
|
|
$this->console->info('Creating public/vendor/crudbooster symlink...'); |
89
|
|
|
app('files')->link(__DIR__.'/../assets', public_path('vendor/crudbooster')); |
90
|
|
|
|
91
|
|
|
return; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$this->console->info('Vendor Path: '.$vendorPath); |
95
|
|
|
|
96
|
|
|
if (realpath($vendorPath) == $vendorPath) { |
97
|
|
|
$this->console->info('Removing public/vendor/crudbooster dir, instead of creating a symlink...'); |
98
|
|
|
$this->rrmdir($vendorPath); |
99
|
|
|
app('files')->link(__DIR__.'/../assets', $vendorPath); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function installCrudbooster() |
104
|
|
|
{ |
105
|
|
|
$this->console->info('Publishing CRUDBooster needs file...'); |
106
|
|
|
$this->console->callSilent('vendor:publish', ['--provider' => 'crocodicstudio\\crudbooster\\CRUDBoosterServiceProvider', '--force' => true]); |
107
|
|
|
$this->console->callSilent('vendor:publish', ['--tag' => 'cb_migration', '--force' => true]); |
108
|
|
|
$this->console->callSilent('vendor:publish', ['--tag' => 'cb_lfm', '--force' => true]); |
109
|
|
|
$this->console->callSilent('vendor:publish', ['--tag' => 'cb_localization', '--force' => true]); |
110
|
|
|
|
111
|
|
|
$this->console->info('Dumping the autoloaded files and reloading all new files...'); |
112
|
|
|
$composer = $this->findComposer(); |
113
|
|
|
$process = new Process($composer.' dumpautoload'); |
114
|
|
|
$process->setWorkingDirectory(base_path())->run(); |
115
|
|
|
|
116
|
|
|
$this->console->info('Migrating database...'); |
117
|
|
|
$this->console->call('migrate', ['--path' => '\database\migrations\crudbooster']); |
118
|
|
|
|
119
|
|
|
if (! class_exists('CBSeeder')) { |
120
|
|
|
require_once __DIR__.'/../database/seeds/CBSeeder.php'; |
121
|
|
|
} |
122
|
|
|
$this->console->callSilent('db:seed', ['--class' => 'CBSeeder']); |
123
|
|
|
$this->console->call('config:clear'); |
124
|
|
|
if (app()->version() < 5.6) { |
|
|
|
|
125
|
|
|
$this->console->call('optimize'); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$this->console->info('Installing CRUDBooster Is Completed ! Thank You :)'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
/* |
133
|
|
|
* http://stackoverflow.com/questions/3338123/how-do-i-recursively-delete-a-directory-and-its-entire-contents-files-sub-dir |
134
|
|
|
*/ |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Get the composer command for the environment. |
138
|
|
|
* |
139
|
|
|
* @return string |
140
|
|
|
*/ |
141
|
|
|
protected function findComposer() |
142
|
|
|
{ |
143
|
|
|
if (file_exists(getcwd().'/composer.phar')) { |
144
|
|
|
return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar'; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return 'composer'; |
148
|
|
|
} |
149
|
|
|
} |
If you suppress an error, we recommend checking for the error condition explicitly: