Move seed data into separate file with importer; fix admin panel js being broken
This commit is contained in:
@@ -11,17 +11,9 @@ use App\Models\Pirep;
|
||||
|
||||
class DevCommands extends BaseCommand
|
||||
{
|
||||
protected $signature = 'phpvms {cmd} {--file=?}';
|
||||
protected $signature = 'phpvms {cmd}';
|
||||
protected $description = 'Developer commands';
|
||||
|
||||
protected $dbSvc;
|
||||
|
||||
public function __construct(DatabaseService $dbSvc)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbSvc = $dbSvc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run dev related commands
|
||||
*/
|
||||
@@ -37,7 +29,6 @@ class DevCommands extends BaseCommand
|
||||
$commands = [
|
||||
'clear-acars' => 'clearAcars',
|
||||
'compile-assets' => 'compileAssets',
|
||||
'import' => 'importYaml',
|
||||
];
|
||||
|
||||
if(!array_key_exists($command, $commands)) {
|
||||
@@ -76,12 +67,4 @@ class DevCommands extends BaseCommand
|
||||
$this->runCommand('npm update');
|
||||
$this->runCommand('npm run dev');
|
||||
}
|
||||
|
||||
/**
|
||||
* Import data from a YAML file
|
||||
*/
|
||||
protected function importYaml()
|
||||
{
|
||||
$this->info('importing '. $this->argument('file'));
|
||||
}
|
||||
}
|
||||
|
||||
53
app/Console/Commands/ImportCommand.php
Normal file
53
app/Console/Commands/ImportCommand.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use DB;
|
||||
use App\Console\BaseCommand;
|
||||
use App\Services\DatabaseService;
|
||||
|
||||
class ImportCommand extends BaseCommand
|
||||
{
|
||||
protected $signature = 'phpvms:import {files*}';
|
||||
protected $description = 'Developer commands';
|
||||
|
||||
protected $dbSvc;
|
||||
|
||||
public function __construct(DatabaseService $dbSvc)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbSvc = $dbSvc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run dev related commands
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$files = $this->argument('files');
|
||||
if(empty($files)) {
|
||||
$this->error('No files to import specified!');
|
||||
exit();
|
||||
}
|
||||
|
||||
$ignore_errors = true;
|
||||
/*$ignore_errors = $this->option('ignore_errors');
|
||||
if(!$ignore_errors) {
|
||||
$ignore_errors = false;
|
||||
}*/
|
||||
|
||||
foreach($files as $file) {
|
||||
if(!file_exists($file)) {
|
||||
$this->error('File ' . $file .' doesn\'t exist');
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->info('Importing ' . $file);
|
||||
|
||||
$imported = $this->dbSvc->seed_from_yaml_file($file, $ignore_errors);
|
||||
foreach($imported as $table => $count) {
|
||||
$this->info('Imported '.$count.' records from "'.$table.'"');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel
|
||||
Commands\AcarsReplay::class,
|
||||
Commands\CreateDatabase::class,
|
||||
Commands\DevCommands::class,
|
||||
Commands\ImportCommand::class,
|
||||
Commands\Install::class,
|
||||
Commands\NavdataCommand::class,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user