2018-03-02 11:59:58 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
2019-09-17 01:08:26 +08:00
|
|
|
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;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* 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');
|
2018-03-20 09:50:40 +08:00
|
|
|
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 = [];
|
2018-03-20 09:50:40 +08:00
|
|
|
foreach ($tables as $table) {
|
2018-03-02 11:59:58 +08:00
|
|
|
$export_tables[$table] = [];
|
|
|
|
|
|
|
|
$rows = DB::table($table)->get();
|
2018-03-20 09:50:40 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|