firefly-iii/app/Console/Commands/Upgrade/UpgradeDatabase.php

97 lines
3.4 KiB
PHP
Raw Normal View History

2019-03-18 10:53:05 -05:00
<?php
/**
* UpgradeDatabase.php
2020-01-23 13:35:02 -06:00
* Copyright (c) 2020 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/>.
*/
2019-08-17 05:09:03 -05:00
declare(strict_types=1);
2019-03-18 10:53:05 -05:00
namespace FireflyIII\Console\Commands\Upgrade;
2019-03-23 12:58:06 -05:00
set_time_limit(0);
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
2019-03-18 10:53:05 -05:00
use Illuminate\Console\Command;
/**
* Class UpgradeDatabase
*/
class UpgradeDatabase extends Command
{
use ShowsFriendlyMessages;
2019-03-23 02:10:59 -05:00
protected $description = 'Upgrades the database to the latest version.';
protected $signature = 'firefly-iii:upgrade-database {--F|force : Force all upgrades.}';
2019-03-18 10:53:05 -05:00
/**
* Execute the console command.
*/
2019-06-07 10:57:46 -05:00
public function handle(): int
2019-03-18 10:53:05 -05:00
{
2019-08-05 10:07:19 -05:00
$this->callInitialCommands();
2019-03-18 10:53:05 -05:00
$commands = [
'firefly-iii:transaction-identifiers',
2019-06-22 22:53:01 -05:00
'firefly-iii:migrate-to-groups',
2019-03-18 10:53:05 -05:00
'firefly-iii:account-currencies',
'firefly-iii:transfer-currencies',
'firefly-iii:other-currencies',
2019-03-20 12:31:00 -05:00
'firefly-iii:migrate-notes',
'firefly-iii:migrate-attachments',
'firefly-iii:bills-to-rules',
'firefly-iii:bl-currency',
'firefly-iii:cc-liabilities',
2019-03-18 10:53:05 -05:00
'firefly-iii:back-to-journals',
2019-08-04 00:41:32 -05:00
'firefly-iii:rename-account-meta',
'firefly-iii:migrate-recurrence-meta',
'firefly-iii:migrate-tag-locations',
2021-03-11 23:30:40 -06:00
'firefly-iii:migrate-recurrence-type',
2021-05-01 23:39:18 -05:00
'firefly-iii:upgrade-liabilities',
2023-01-15 09:09:02 -06:00
'firefly-iii:liabilities-600',
2023-04-16 00:33:12 -05:00
'firefly-iii:budget-limit-periods',
'firefly-iii:migrate-rule-actions',
2023-06-11 23:24:30 -05:00
'firefly-iii:restore-oauth-keys',
2023-08-01 02:54:09 -05:00
// also just in case, some integrity commands:
'firefly-iii:create-group-memberships',
'firefly-iii:upgrade-group-information',
2023-10-28 08:03:33 -05:00
'firefly-iii:upgrade-currency-preferences',
'firefly-iii:correct-database',
2019-03-18 10:53:05 -05:00
];
$args = [];
if ($this->option('force')) {
$args = ['--force' => true];
}
foreach ($commands as $command) {
$this->friendlyLine(sprintf('Now executing %s', $command));
2023-04-16 00:33:12 -05:00
$this->call($command, $args);
2019-03-18 10:53:05 -05:00
}
2019-08-05 10:07:19 -05:00
// set new DB version.
2022-10-30 06:24:51 -05:00
app('fireflyconfig')->set('db_version', (int)config('firefly.db_version'));
2019-08-05 10:07:19 -05:00
// index will set FF3 version.
2022-10-30 06:24:51 -05:00
app('fireflyconfig')->set('ff3_version', (string)config('firefly.version'));
2020-03-21 09:43:41 -05:00
2019-06-07 10:57:46 -05:00
return 0;
2019-03-18 10:53:05 -05:00
}
2019-08-05 10:07:19 -05:00
private function callInitialCommands(): void
{
2023-05-07 13:17:29 -05:00
$this->call('migrate', ['--seed' => true, '--force' => true, '--no-interaction' => true]);
2023-04-16 00:33:12 -05:00
$this->call('firefly-iii:fix-pgsql-sequences');
$this->call('firefly-iii:decrypt-all');
2019-08-05 10:07:19 -05:00
}
2019-03-18 10:53:05 -05:00
}