phpvms/app/Console/Commands/YamlExport.php

56 lines
1.2 KiB
PHP
Raw Normal View History

2018-03-02 11:59:58 +08:00
<?php
namespace App\Console\Commands;
use App\Contracts\Command;
2020-10-24 21:26:14 +08:00
use Illuminate\Support\Facades\DB;
2018-03-02 11:59:58 +08:00
use Symfony\Component\Yaml\Yaml;
/**
* Class YamlExport
*/
class YamlExport extends Command
2018-03-02 11:59:58 +08:00
{
2018-03-21 05:10:52 +08:00
protected $signature = 'phpvms:yaml-export {tables*}';
2018-03-02 11:59:58 +08:00
protected $description = 'YAML table export';
/**
* Run dev related commands
*/
public function handle()
{
$tables = $this->argument('tables');
if (empty($tables)) {
2018-03-02 11:59:58 +08:00
$this->error('No tables specified');
exit();
}
2020-10-24 21:26:14 +08:00
// A "preset" for exporting the base set of data
if ($tables[0] === 'base') {
$tables = [
'airlines',
'aircraft',
'subfleets',
'subfleet_fare',
'subfleet_rank',
'bids',
'fares',
'flights',
];
}
2018-03-02 11:59:58 +08:00
$export_tables = [];
foreach ($tables as $table) {
2018-03-02 11:59:58 +08:00
$export_tables[$table] = [];
$rows = DB::table($table)->get();
foreach ($rows as $row) {
2018-03-02 11:59:58 +08:00
$export_tables[$table][] = (array) $row;
}
}
$yaml = Yaml::dump($export_tables, 4, 2);
2018-08-27 00:40:04 +08:00
echo $yaml;
2018-03-02 11:59:58 +08:00
}
}