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

142 lines
4.4 KiB
PHP
Raw Normal View History

2019-03-18 16:53:05 +01:00
<?php
/**
* UpgradeDatabase.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* 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 Illuminate\Console\Command;
/**
* Class UpgradeDatabase
2019-06-13 07:17:31 +02:00
* @codeCoverageIgnore
2019-03-18 16:53:05 +01:00
*/
class UpgradeDatabase extends Command
{
/**
* The console command description.
*
* @var string
*/
2019-03-23 08:10:59 +01:00
protected $description = 'Upgrades the database to the latest version.';
2019-03-18 16:53:05 +01:00
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:upgrade-database {--F|force : Force all upgrades.}';
/**
* 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 = [
// there are 14 upgrade commands.
2019-03-18 16:53:05 +01:00
'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',
2019-08-04 07:41:32 +02:00
2019-12-28 06:58:49 +01:00
// there are 16 verify commands.
2019-08-04 07:41:32 +02:00
'firefly-iii:fix-piggies',
'firefly-iii:create-link-types',
'firefly-iii:create-access-tokens',
'firefly-iii:remove-bills',
'firefly-iii:enable-currencies',
'firefly-iii:fix-transfer-budgets',
'firefly-iii:fix-uneven-amount',
'firefly-iii:delete-zero-amount',
'firefly-iii:delete-orphaned-transactions',
'firefly-iii:delete-empty-journals',
'firefly-iii:delete-empty-groups',
'firefly-iii:fix-account-types',
'firefly-iii:rename-meta-fields',
'firefly-iii:fix-ob-currencies',
2019-09-21 07:33:13 +02:00
'firefly-iii:fix-long-descriptions',
2019-12-28 06:58:49 +01:00
'firefly-iii:fix-recurring-transactions',
2019-08-04 07:41:32 +02:00
// two report commands
'firefly-iii:report-empty-objects',
'firefly-iii:report-sum',
2019-09-21 11:03:00 +02:00
'firefly-iii:restore-oauth-keys',
2019-08-04 07:41:32 +02:00
// instructions
'firefly:instructions update',
2019-03-18 16:53:05 +01:00
];
$args = [];
if ($this->option('force')) {
$args = ['--force' => true];
}
foreach ($commands as $command) {
$this->line(sprintf('Now executing %s', $command));
Artisan::call($command, $args);
$result = Artisan::output();
echo $result;
}
2019-08-05 17:07:19 +02:00
// set new DB version.
app('fireflyconfig')->set('db_version', (int)config('firefly.db_version'));
2019-08-05 17:07:19 +02:00
// index will set FF3 version.
app('fireflyconfig')->set('ff3_version', (string)config('firefly.version'));
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
private function callInitialCommands(): void
{
$this->line('Now seeding the database...');
Artisan::call('migrate', ['--seed' => true, '--force' => true]);
$result = Artisan::output();
echo $result;
$this->line('Now decrypting the database (if necessary)...');
2019-08-05 17:07:19 +02:00
Artisan::call('firefly-iii:decrypt-all');
$result = Artisan::output();
echo $result;
$this->line('Now installing OAuth2 keys...');
2019-08-10 07:18:18 +02:00
Artisan::call('passport:install');
$result = Artisan::output();
echo $result;
$this->line('Done!');
2019-08-05 17:07:19 +02:00
}
2019-03-18 16:53:05 +01:00
}