catchAdmin/extend/catcher/command/Tools/ExportDataCommand.php

47 lines
1.2 KiB
PHP
Raw Normal View History

2020-04-29 15:05:49 +08:00
<?php
declare (strict_types = 1);
namespace catcher\command\Tools;
2020-05-22 14:09:59 +08:00
use catcher\facade\Http;
2020-04-29 15:06:13 +08:00
use catcher\Tree;
2020-05-22 14:09:59 +08:00
use catcher\Utils;
2020-04-29 15:05:49 +08:00
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Db;
2020-04-29 15:06:13 +08:00
class ExportDataCommand extends Command
2020-04-29 15:05:49 +08:00
{
protected $table;
protected function configure()
{
// 指令配置
2020-04-29 15:06:13 +08:00
$this->setName('export')
->addArgument('table', Argument::REQUIRED, 'export tables')
->addOption('pid', '-p', Option::VALUE_REQUIRED, 'parent level name')
->setDescription('Just for catchAdmin export data');
2020-04-29 15:05:49 +08:00
}
protected function execute(Input $input, Output $output)
{
2020-05-22 14:09:59 +08:00
$table = Utils::tablePrefix() . $input->getArgument('table');
2020-04-29 15:06:13 +08:00
$parent = $input->getOption('pid');
$data = Db::name($table)->where('deleted_at', 0)->select()->toArray();
if ($parent) {
$data = Tree::done($data, 0, $parent);
}
2020-06-18 17:45:04 +08:00
file_put_contents(root_path() . DIRECTORY_SEPARATOR . $table . '.php', "<?php\r\n return " . var_export($data, true) . ';');
2020-04-29 15:06:13 +08:00
2020-04-29 15:05:49 +08:00
$output->info('succeed!');
}
}
2020-04-29 15:06:13 +08:00