phpvms/app/Console/Commands/YamlExport.php

53 lines
1.1 KiB
PHP
Raw Normal View History

2018-03-02 11:59:58 +08:00
<?php
namespace App\Console\Commands;
use App\Console\Command;
2018-03-02 11:59:58 +08:00
use App\Services\DatabaseService;
use DB;
use Symfony\Component\Yaml\Yaml;
/**
* Class YamlExport
* @package App\Console\Commands
*/
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';
/**
* YamlExport constructor.
* @param DatabaseService $dbSvc
*/
2018-03-02 11:59:58 +08:00
public function __construct(DatabaseService $dbSvc)
{
parent::__construct();
}
/**
* 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();
}
$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);
print($yaml);
}
}