forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppStartupCommand.php
More file actions
107 lines (82 loc) · 2.43 KB
/
AppStartupCommand.php
File metadata and controls
107 lines (82 loc) · 2.43 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\Process\Process;
class AppStartupCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:startup';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Runs when the app is started to make sure everything is ok';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$this->info('🐇 Starting up Speedtest Tracker...');
$this->newLine();
$this->clearAppCache();
// $this->checkAppKey();
// $this->checkAppDatabase();
// $this->migrateDatabase();
$this->line('🚀 Speedtest Tracker is ready to roll!');
return 0;
}
private function checkAppDatabase()
{
if (! Storage::exists('database.sqlite')) {
$this->line('🙄 Database not found, creating a new one...');
$process = new Process(['touch', 'storage/app/database.sqlite']);
$process->run();
if (! Storage::exists('database.sqlite')) {
$this->error('❌ There was an issue creating the database, check the logs');
}
$this->line('✅ done');
$this->newLine();
}
}
private function checkAppKey()
{
if (blank(config('app.key'))) {
$this->line('🔑 Generating a key...');
Artisan::call('key:generate');
$this->line('✅ done');
$this->newLine();
}
}
private function clearAppCache()
{
$this->line('💵 Clearing the cache...');
Artisan::call('optimize');
$this->line('✅ done');
$this->newLine();
}
private function migrateDatabase()
{
$this->line('⏳ Migrating the database...');
try {
Artisan::call('migrate', [
'--database' => 'sqlite',
'--force' => true,
]);
} catch (\Throwable $th) {
$this->error('❌ There was an issue migrating the database, check the logs');
Log::info($th);
}
$this->line('✅ done');
$this->newLine();
}
}