mirror of
https://github.com/brufdev/many-notes.git
synced 2026-01-23 19:38:46 -06:00
79 lines
1.6 KiB
PHP
79 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Console\Commands\Upgrade;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class RunCommand extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'upgrade:run';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Run all upgrade commands';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
$this->init();
|
|
$this->processLinks();
|
|
$this->syncDatabaseNotes();
|
|
}
|
|
|
|
private function init(): void
|
|
{
|
|
if (DB::table('upgrades')->count()) {
|
|
return;
|
|
}
|
|
|
|
DB::table('upgrades')->insert([
|
|
'executed' => 0,
|
|
]);
|
|
}
|
|
|
|
private function processLinks(): void
|
|
{
|
|
/** @var object{executed: int} $upgrades */
|
|
$upgrades = DB::table('upgrades')->first();
|
|
|
|
if ($upgrades->executed !== 0) {
|
|
return;
|
|
}
|
|
|
|
$this->call('upgrade:process-links');
|
|
|
|
DB::table('upgrades')->update([
|
|
'executed' => 1,
|
|
]);
|
|
}
|
|
|
|
private function syncDatabaseNotes(): void
|
|
{
|
|
/** @var object{executed: int} $upgrades */
|
|
$upgrades = DB::table('upgrades')->first();
|
|
|
|
if ($upgrades->executed !== 1) {
|
|
return;
|
|
}
|
|
|
|
$this->call('upgrade:sync-database-notes');
|
|
|
|
DB::table('upgrades')->update([
|
|
'executed' => 2,
|
|
]);
|
|
}
|
|
}
|