|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Enomotodev\LaractiveAdmin\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Illuminate\Contracts\Filesystem\FileNotFoundException; |
|
7
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
8
|
|
|
use Illuminate\Support\Composer; |
|
9
|
|
|
|
|
10
|
|
|
class InstallCommand extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $name = 'laractive-admin:install'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $description = 'Install LaractiveAdmin'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \Illuminate\Filesystem\Filesystem |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $files; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var \Illuminate\Support\Composer |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $composer; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param \Illuminate\Filesystem\Filesystem $files |
|
34
|
|
|
* @param \Illuminate\Support\Composer $composer |
|
35
|
|
|
* @return void |
|
36
|
|
|
*/ |
|
37
|
11 |
|
public function __construct(Filesystem $files, Composer $composer) |
|
38
|
|
|
{ |
|
39
|
11 |
|
parent::__construct(); |
|
40
|
|
|
|
|
41
|
11 |
|
$this->files = $files; |
|
42
|
11 |
|
$this->composer = $composer; |
|
43
|
11 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return void |
|
47
|
|
|
*/ |
|
48
|
|
|
public function handle() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->createMigration(); |
|
51
|
|
|
$this->createAdminUser(); |
|
52
|
|
|
$this->createDashboard(); |
|
53
|
|
|
|
|
54
|
|
|
$this->info('LaractiveAdmin install successfully!'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function createMigration() |
|
61
|
|
|
{ |
|
62
|
|
|
$migrations = [ |
|
63
|
|
|
'create_admin_users_table', |
|
64
|
|
|
'create_laractive_admin_comments_table', |
|
65
|
|
|
]; |
|
66
|
|
|
|
|
67
|
|
|
try { |
|
68
|
|
|
foreach ($migrations as $migration) { |
|
69
|
|
|
$fullPath = $this->createBaseMigration($migration); |
|
70
|
|
|
$this->files->put($fullPath, $this->files->get(__DIR__ . "/stubs/{$migration}.stub")); |
|
71
|
|
|
} |
|
72
|
|
|
$this->composer->dumpAutoloads(); |
|
73
|
|
|
} catch (FileNotFoundException $exception) { |
|
74
|
|
|
$this->error($exception->getMessage()); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param string $name |
|
80
|
|
|
* @return mixed |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function createBaseMigration($name) |
|
83
|
|
|
{ |
|
84
|
|
|
$path = $this->laravel->databasePath().'/migrations'; |
|
85
|
|
|
|
|
86
|
|
|
return $this->laravel['migration.creator']->create($name, $path); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return void |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function createAdminUser() |
|
93
|
|
|
{ |
|
94
|
|
|
if (! is_dir($directory = app_path('Admin'))) { |
|
95
|
|
|
mkdir($directory, 0755, true); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
copy(__DIR__.'/stubs/AdminUser.stub', "{$directory}/AdminUser.php"); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return void |
|
103
|
|
|
*/ |
|
104
|
|
|
protected function createDashboard() |
|
105
|
|
|
{ |
|
106
|
|
|
if (! is_dir($directory = app_path('Admin'))) { |
|
107
|
|
|
mkdir($directory, 0755, true); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
copy(__DIR__.'/stubs/Dashboard.stub', "{$directory}/Dashboard.php"); |
|
111
|
|
|
|
|
112
|
|
|
if (! is_dir($directory = resource_path('views/admin'))) { |
|
113
|
|
|
mkdir($directory, 0755, true); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
copy(__DIR__.'/stubs/dashboard.blade.stub', "{$directory}/dashboard.blade.php"); |
|
117
|
|
|
} |
|
118
|
|
|
} |