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;
|
2018-03-02 11:59:58 +08:00
|
|
|
use DB;
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
$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
|
|
|
}
|
|
|
|
}
|