Files
speedtest-tracker/app/Console/Commands/InstallCommand.php
T
Alex Justesen ce21ae24db Laravel 11.x Shift (#1389)
Co-authored-by: Shift <shift@laravelshift.com>
2024-05-06 08:00:29 -04:00

90 lines
2.1 KiB
PHP

<?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.
*/
public function handle(): void
{
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;
}
}
$this->info('Starting to install the application...');
$this->newLine();
$this->checkAppKey();
$this->line('⏳ Optimizing the cache...');
if (app()->environment('production') || app()->environment('testing')) {
Artisan::call('view:clear');
Artisan::call('filament:cache-components');
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;
}
$this->line('✅ Database migrated');
$this->newLine();
$this->line('🚀 Finished installing the application!');
}
public function checkAppKey()
{
if (empty(config('app.key'))) {
$this->line('🔑 Creating an application key');
Artisan::call('key:generate');
$this->line('✅ Application key created');
}
}
}