Files
firefly-iii/database/seeders/ConfigSeeder.php

82 lines
2.6 KiB
PHP
Raw Normal View History

2020-03-17 16:06:30 +00:00
<?php
2018-03-07 20:21:36 +01:00
2020-06-30 20:33:08 +02:00
/**
* ConfigSeeder.php
* 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/>.
*/
2020-03-17 16:06:30 +00:00
declare(strict_types=1);
2018-05-11 10:08:34 +02:00
/**
* ConfigSeeder.php
2020-03-17 16:06:30 +00:00
* Copyright (c) 2019 james@firefly-iii.org.
2018-05-11 10:08:34 +02:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-05-11 10:08:34 +02:00
*
* 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.
2018-05-11 10:08:34 +02:00
*
* This program is distributed in the hope that it will be useful,
2018-05-11 10:08:34 +02:00
* 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.
2018-05-11 10:08:34 +02:00
*
* 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/>.
2018-05-11 10:08:34 +02:00
*/
2020-11-02 06:20:49 +01:00
namespace Database\Seeders;
2018-03-07 20:21:36 +01:00
use FireflyIII\Models\Configuration;
use Illuminate\Database\Seeder;
2020-11-02 06:20:49 +01:00
use Log;
2018-03-07 20:21:36 +01:00
/**
2020-03-17 16:06:30 +00:00
* Class ConfigSeeder.
2018-03-07 20:21:36 +01:00
*/
class ConfigSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
2018-03-07 20:21:36 +01:00
{
$entry = Configuration::where('name', 'db_version')->first();
2018-04-02 14:17:11 +02:00
if (null === $entry) {
2018-03-07 20:21:36 +01: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 14:17:11 +02:00
if (null !== $entry) {
2020-11-02 06:20:49 +01:00
$version = (int)config('firefly.db_version');
2018-03-07 20:21:36 +01:00
$entry->data = $version;
$entry->save();
Log::warning(sprintf('Database entry exists. Update to latest version (%d)', $version));
}
}
}