firefly-iii/database/seeds/ConfigSeeder.php

57 lines
1.7 KiB
PHP
Raw Normal View History

2018-03-11 14:41:03 -05:00
<?php declare(strict_types=1);
2018-03-07 13:21:36 -06:00
2018-05-11 03:08:34 -05:00
/**
* ConfigSeeder.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
2018-03-07 13:21:36 -06:00
use FireflyIII\Models\Configuration;
use Illuminate\Database\Seeder;
/**
* Class ConfigSeeder
*/
class ConfigSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run()
{
$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) {
$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));
}
}
}