1 | <?php |
||
2 | |||
3 | namespace Wingsline\Blog\Console; |
||
4 | |||
5 | use Illuminate\Console\Command; |
||
6 | use Illuminate\Support\Facades\Schema; |
||
7 | use Spatie\Backup\BackupServiceProvider; |
||
8 | use Spatie\Csp\CspServiceProvider; |
||
9 | use Spatie\Feed\FeedServiceProvider; |
||
10 | use Spatie\MediaLibrary\MediaLibraryServiceProvider; |
||
11 | use Spatie\MissingPageRedirector\MissingPageRedirectorServiceProvider; |
||
12 | use Spatie\ResponseCache\ResponseCacheServiceProvider; |
||
13 | use Spatie\Tags\TagsServiceProvider; |
||
14 | use Wingsline\Blog\Database\Seeds\UsersTableSeeder; |
||
15 | |||
16 | class InstallCommand extends Command |
||
17 | { |
||
18 | /** |
||
19 | * The console command description. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $description = 'Install the blog.'; |
||
24 | /** |
||
25 | * The name and signature of the console command. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $signature = 'blog:install'; |
||
30 | |||
31 | /** |
||
32 | * Create a new command instance. |
||
33 | */ |
||
34 | public function __construct() |
||
35 | { |
||
36 | parent::__construct(); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Execute the console command. |
||
41 | * |
||
42 | * @return mixed |
||
43 | */ |
||
44 | public function handle() |
||
45 | { |
||
46 | $this->comment('Publishing the blog assets...'); |
||
47 | // Backup |
||
48 | $this->callSilent( |
||
49 | 'vendor:publish', |
||
50 | [ |
||
51 | '--provider' => BackupServiceProvider::class, |
||
52 | ] |
||
53 | ); |
||
54 | // CSP |
||
55 | $this->callSilent( |
||
56 | 'vendor:publish', |
||
57 | [ |
||
58 | '--tag' => 'config', |
||
59 | '--provider' => CspServiceProvider::class, |
||
60 | ] |
||
61 | ); |
||
62 | // RSS Feed |
||
63 | $this->callSilent( |
||
64 | 'vendor:publish', |
||
65 | [ |
||
66 | '--tag' => 'config', |
||
67 | '--provider' => FeedServiceProvider::class, |
||
68 | ] |
||
69 | ); |
||
70 | // media library |
||
71 | $this->callSilent( |
||
72 | 'vendor:publish', |
||
73 | [ |
||
74 | '--tag' => 'config', |
||
75 | '--provider' => MediaLibraryServiceProvider::class, |
||
76 | ] |
||
77 | ); |
||
78 | // check if media table exists |
||
79 | if (! Schema::hasTable('media')) { |
||
80 | $this->callSilent( |
||
81 | 'vendor:publish', |
||
82 | [ |
||
83 | '--tag' => 'migrations', |
||
84 | '--provider' => MediaLibraryServiceProvider::class, |
||
85 | ] |
||
86 | ); |
||
87 | } |
||
88 | |||
89 | // Missing page redirector |
||
90 | $this->callSilent( |
||
91 | 'vendor:publish', |
||
92 | [ |
||
93 | '--provider' => MissingPageRedirectorServiceProvider::class, |
||
94 | ] |
||
95 | ); |
||
96 | // Response Cache |
||
97 | $this->callSilent( |
||
98 | 'vendor:publish', |
||
99 | [ |
||
100 | '--provider' => ResponseCacheServiceProvider::class, |
||
101 | ] |
||
102 | ); |
||
103 | // tags |
||
104 | $this->callSilent( |
||
105 | 'vendor:publish', |
||
106 | [ |
||
107 | '--tag' => 'config', |
||
108 | '--provider' => TagsServiceProvider::class, |
||
109 | ] |
||
110 | ); |
||
111 | if (! Schema::hasTable('tags')) { |
||
112 | $this->callSilent( |
||
113 | 'vendor:publish', |
||
114 | [ |
||
115 | '--tag' => 'migrations', |
||
116 | '--provider' => TagsServiceProvider::class, |
||
117 | ] |
||
118 | ); |
||
119 | } |
||
120 | // Blog migrations |
||
121 | $this->callSilent('vendor:publish', ['--tag' => 'blog.config']); |
||
122 | $this->callSilent('vendor:publish', ['--tag' => 'blog.migrations']); |
||
123 | $this->callSilent('vendor:publish', ['--tag' => 'blog.assets']); |
||
124 | $this->info('Blog scaffolding installed successfully.'); |
||
125 | // run the migrations and seeds |
||
126 | $this->comment('Running the database migrations...'); |
||
127 | $this->call('migrate'); |
||
128 | |||
129 | if (! file_exists(public_path('storage'))) { |
||
130 | $this->call('storage:link'); |
||
131 | } |
||
132 | // Link the theme? |
||
133 | if ($this->confirm('Link the theme\'s public assets?')) { |
||
134 | $this->call('blog:theme-publish'); |
||
135 | } |
||
136 | // Seed the database |
||
137 | if ($this->confirm('Seed the database (recommended for new installations)')) { |
||
138 | $this->comment('Seeding the database with default data...'); |
||
139 | $this->call('db:seed', ['--class' => UsersTableSeeder::class]); |
||
140 | } |
||
141 | |||
142 | $admin_url = url(config('blog.prefix')); |
||
143 | $this->info('Installation complete. You can login to the admin '.$admin_url); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
144 | } |
||
145 | } |
||
146 |