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

103 lines
3.3 KiB
PHP
Raw Normal View History

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