2020-03-17 11:06:30 -05:00
|
|
|
<?php
|
2021-03-28 04:43:07 -05:00
|
|
|
/*
|
2020-06-30 13:33:08 -05:00
|
|
|
* ConfigSeeder.php
|
2021-03-28 04:43:07 -05:00
|
|
|
* Copyright (c) 2021 james@firefly-iii.org
|
2020-06-30 13:33:08 -05:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2020-03-17 11:06:30 -05:00
|
|
|
declare(strict_types=1);
|
2018-05-11 03:08:34 -05:00
|
|
|
|
2020-11-01 23:20:49 -06:00
|
|
|
namespace Database\Seeders;
|
|
|
|
|
2018-03-07 13:21:36 -06:00
|
|
|
use FireflyIII\Models\Configuration;
|
|
|
|
use Illuminate\Database\Seeder;
|
2020-11-01 23:20:49 -06:00
|
|
|
use Log;
|
2018-03-07 13:21:36 -06:00
|
|
|
|
|
|
|
/**
|
2020-03-17 11:06:30 -05:00
|
|
|
* Class ConfigSeeder.
|
2018-03-07 13:21:36 -06:00
|
|
|
*/
|
|
|
|
class ConfigSeeder extends Seeder
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*/
|
2019-03-17 03:06:45 -05:00
|
|
|
public function run(): void
|
2018-03-07 13:21:36 -06:00
|
|
|
{
|
|
|
|
$entry = Configuration::where('name', 'db_version')->first();
|
2018-04-02 07:17:11 -05:00
|
|
|
if (null === $entry) {
|
2018-03-07 13:21:36 -06:00
|
|
|
Log::warning('No database version entry is present. Database is assumed to be OLD (version 1).');
|
|
|
|
// FF old or no version present. Put at 1:
|
|
|
|
Configuration::create(
|
|
|
|
[
|
|
|
|
'name' => 'db_version',
|
|
|
|
'data' => 1,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2018-04-02 07:17:11 -05:00
|
|
|
if (null !== $entry) {
|
2022-03-29 08:01:12 -05:00
|
|
|
$version = (int) config('firefly.db_version');
|
2018-03-07 13:21:36 -06:00
|
|
|
$entry->data = $version;
|
|
|
|
$entry->save();
|
|
|
|
|
|
|
|
Log::warning(sprintf('Database entry exists. Update to latest version (%d)', $version));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|