firefly-iii/database/seeds/TestDataSeeder.php

54 lines
1.2 KiB
PHP
Raw Normal View History

2015-02-05 21:41:00 -06:00
<?php
2016-02-05 08:01:33 -06:00
declare(strict_types = 1);
2016-05-20 01:57:45 -05:00
2016-02-05 08:01:33 -06:00
/**
* TestDataSeeder.php
2016-04-01 09:46:11 -05:00
* Copyright (C) 2016 thegrumpydictator@gmail.com
2016-02-05 08:01:33 -06:00
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
2016-01-16 02:15:24 -06:00
2016-01-30 00:36:11 -06:00
use FireflyIII\Support\Migration\TestData;
2015-02-11 00:35:10 -06:00
use Illuminate\Database\Seeder;
2015-02-05 21:41:00 -06:00
/**
* Class TestDataSeeder
*/
class TestDataSeeder extends Seeder
{
2016-01-24 13:38:58 -06:00
/**
* TestDataSeeder constructor.
*/
public function __construct()
{
}
2015-02-05 21:41:00 -06:00
/**
2016-01-16 02:15:24 -06:00
* Run the database seeds.
2015-06-29 08:23:50 -05:00
*
2016-01-16 02:15:24 -06:00
* @return void
2015-02-05 21:41:00 -06:00
*/
public function run()
{
2016-05-15 08:01:29 -05:00
$disk = Storage::disk('database');
$env = App::environment();
Log::debug('Environment is ' . $env);
2016-05-14 14:49:16 -05:00
$fileName = 'seed.' . $env . '.json';
if ($disk->exists($fileName)) {
2016-05-15 08:01:29 -05:00
Log::debug('Now seeding ' . $fileName);
2016-05-14 14:49:16 -05:00
$file = json_decode($disk->get($fileName), true);
2016-05-15 08:01:29 -05:00
2016-08-11 11:44:11 -05:00
if (is_array($file)) {
// run the file:
TestData::run($file);
return;
}
Log::error('No valid data found (' . $fileName . ') for environment ' . $env);
2016-05-15 08:01:29 -05:00
return;
2016-08-11 11:44:11 -05:00
2016-02-05 08:01:33 -06:00
}
2016-05-15 08:01:29 -05:00
Log::info('No seed file (' . $fileName . ') for environment ' . $env);
2016-01-20 03:47:29 -06:00
}
2015-03-29 01:14:32 -05:00
}