forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallCommand.php
More file actions
89 lines (64 loc) · 1.96 KB
/
InstallCommand.php
File metadata and controls
89 lines (64 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
class InstallCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:install {--force}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'A fresh install of Speedtest Tracker.';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
if (! $this->option('force')) {
$this->newLine(2);
$this->info("Running the install will reset all of the application's data.");
$this->warn('!!! ALL OF THE DATA WILL BE DELETED !!!');
if (! $this->confirm('Do you wish to continue?')) {
$this->info('Install cancelled.');
return 0;
}
}
$this->info('Starting to install the application...');
$this->newLine();
$this->checkAppKey();
$this->line('⏳ Optimizing the cache...');
Artisan::call('optimize');
$this->line('✅ Optimized cache');
$this->newLine();
$this->line('⏳ Migrating the database...');
try {
Artisan::call('migrate:fresh', [
'--force' => true,
]);
} catch (\Throwable $th) {
$this->error('❌ There was an issue migrating the database, check the logs.');
return 0;
}
$this->line('✅ Database migrated');
$this->newLine();
$this->line('🚀 Finished installing the application!');
return 0;
}
public function checkAppKey()
{
if (empty(config('app.key'))) {
$this->line('🔑 Creating an application key');
Artisan::call('key:generate');
$this->line('✅ Application key created');
}
}
}