2023-04-07 20:54:15 +02:00
|
|
|
<?php
|
2023-04-16 07:33:12 +02:00
|
|
|
/*
|
|
|
|
* ForceMigration.php
|
|
|
|
* Copyright (c) 2023 james@firefly-iii.org
|
|
|
|
*
|
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2023-04-07 20:54:15 +02:00
|
|
|
|
2023-04-08 08:43:41 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2023-04-16 07:33:12 +02:00
|
|
|
namespace FireflyIII\Console\Commands\System;
|
2023-04-07 20:54:15 +02:00
|
|
|
|
2023-06-20 07:16:56 +02:00
|
|
|
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
2023-04-16 07:33:12 +02:00
|
|
|
use FireflyIII\Console\Commands\VerifiesAccessToken;
|
2023-04-07 20:54:15 +02:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\Artisan;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
|
2023-07-04 13:29:19 +02:00
|
|
|
/**
|
|
|
|
* Class ForceMigration
|
|
|
|
*/
|
2023-04-07 20:54:15 +02:00
|
|
|
class ForceMigration extends Command
|
|
|
|
{
|
2023-06-20 07:16:56 +02:00
|
|
|
use ShowsFriendlyMessages;
|
2023-04-07 20:54:15 +02:00
|
|
|
use VerifiesAccessToken;
|
|
|
|
|
2023-05-07 20:17:29 +02:00
|
|
|
protected $description = 'This command will force-run all database migrations.';
|
2023-11-05 09:54:53 +01:00
|
|
|
|
2024-01-01 14:43:56 +01:00
|
|
|
protected $signature = 'firefly-iii:force-migrations
|
2023-05-07 20:17:29 +02:00
|
|
|
{--user=1 : The user ID.}
|
|
|
|
{--token= : The user\'s access token.}';
|
2023-04-07 20:54:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
2023-05-29 13:56:55 +02:00
|
|
|
*
|
2023-04-07 20:54:15 +02:00
|
|
|
* @throws FireflyException
|
|
|
|
*/
|
|
|
|
public function handle(): int
|
|
|
|
{
|
|
|
|
if (!$this->verifyAccessToken()) {
|
2023-06-20 07:16:56 +02:00
|
|
|
$this->friendlyError('Invalid access token.');
|
2023-04-07 20:54:15 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-06-20 07:16:56 +02:00
|
|
|
$this->friendlyError('Running this command is dangerous and can cause data loss.');
|
|
|
|
$this->friendlyError('Please do not continue.');
|
2023-04-07 20:54:15 +02:00
|
|
|
$question = $this->confirm('Do you want to continue?');
|
|
|
|
if (true === $question) {
|
|
|
|
$user = $this->getUser();
|
|
|
|
Log::channel('audit')->info(sprintf('User #%d ("%s") forced migrations.', $user->id, $user->email));
|
|
|
|
$this->forceMigration();
|
2023-05-29 13:56:55 +02:00
|
|
|
|
2023-04-07 20:54:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2023-05-29 13:56:55 +02:00
|
|
|
|
2023-04-07 20:54:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function forceMigration(): void
|
|
|
|
{
|
2023-04-10 07:19:10 +02:00
|
|
|
DB::commit();
|
2023-06-20 07:16:56 +02:00
|
|
|
$this->friendlyLine('Dropping "migrations" table...');
|
2023-04-07 20:54:15 +02:00
|
|
|
sleep(2);
|
|
|
|
Schema::dropIfExists('migrations');
|
2023-06-20 07:16:56 +02:00
|
|
|
$this->friendlyLine('Re-run all migrations...');
|
2024-11-18 04:18:51 +01:00
|
|
|
Artisan::call('migrate', ['--seed' => true, '--force' => true]);
|
2023-04-07 20:54:15 +02:00
|
|
|
sleep(2);
|
2023-06-20 07:16:56 +02:00
|
|
|
$this->friendlyLine('');
|
|
|
|
$this->friendlyWarning('There is a good chance you just saw a lot of error messages.');
|
|
|
|
$this->friendlyWarning('No need to panic yet. First try to access Firefly III (again).');
|
|
|
|
$this->friendlyWarning('The issue, whatever it was, may have been solved now.');
|
|
|
|
$this->friendlyLine('');
|
2023-04-07 20:54:15 +02:00
|
|
|
}
|
|
|
|
}
|