新增tools

This commit is contained in:
JaguarJack 2020-04-29 15:06:13 +08:00
parent 514bb6b520
commit 610f48b4ec
4 changed files with 26 additions and 10 deletions

View File

@ -1,8 +1,8 @@
<?php <?php
namespace catcher; namespace catcher;
use catcher\command\BackupCommand; use catcher\command\Tools\BackupCommand;
use catcher\command\CompressPackageCommand; use catcher\command\Tools\CompressPackageCommand;
use catcher\command\CreateModuleCommand; use catcher\command\CreateModuleCommand;
use catcher\command\install\InstallProjectCommand; use catcher\command\install\InstallProjectCommand;
use catcher\command\MigrateCreateCommand; use catcher\command\MigrateCreateCommand;
@ -11,6 +11,7 @@ use catcher\command\MigrateRunCommand;
use catcher\command\ModelGeneratorCommand; use catcher\command\ModelGeneratorCommand;
use catcher\command\ModuleCacheCommand; use catcher\command\ModuleCacheCommand;
use catcher\command\SeedRunCommand; use catcher\command\SeedRunCommand;
use catcher\command\Tools\ExportDataCommand;
use catcher\command\worker\WsWorkerCommand; use catcher\command\worker\WsWorkerCommand;
use think\exception\Handle; use think\exception\Handle;
use think\facade\Validate; use think\facade\Validate;
@ -64,6 +65,7 @@ class CatchAdminService extends Service
MigrateRollbackCommand::class, MigrateRollbackCommand::class,
MigrateCreateCommand::class, MigrateCreateCommand::class,
WsWorkerCommand::class, WsWorkerCommand::class,
ExportDataCommand::class
]); ]);
} }
/** /**

View File

@ -1,7 +1,7 @@
<?php <?php
declare (strict_types = 1); declare (strict_types = 1);
namespace catcher\command; namespace catcher\command\Tools;
use catcher\CatchAdmin; use catcher\CatchAdmin;
use think\console\Command; use think\console\Command;

View File

@ -1,7 +1,7 @@
<?php <?php
declare (strict_types = 1); declare (strict_types = 1);
namespace catcher\command; namespace catcher\command\Tools;
use catcher\CatchAdmin; use catcher\CatchAdmin;
use think\console\Command; use think\console\Command;

View File

@ -3,7 +3,7 @@ declare (strict_types = 1);
namespace catcher\command\Tools; namespace catcher\command\Tools;
use catcher\CatchAdmin; use catcher\Tree;
use think\console\Command; use think\console\Command;
use think\console\Input; use think\console\Input;
use think\console\input\Argument; use think\console\input\Argument;
@ -11,22 +11,36 @@ use think\console\input\Option;
use think\console\Output; use think\console\Output;
use think\facade\Db; use think\facade\Db;
class BackUpDataCommand extends Command class ExportDataCommand extends Command
{ {
protected $table; protected $table;
protected function configure() protected function configure()
{ {
// 指令配置 // 指令配置
$this->setName('backup:data') $this->setName('export')
->addArgument('tables', Argument::REQUIRED, 'backup tables') ->addArgument('table', Argument::REQUIRED, 'export tables')
->addOption('zip', '-z',Option::VALUE_NONE, 'is need zip') ->addOption('pid', '-p', Option::VALUE_REQUIRED, 'parent level name')
->setDescription('backup data you need'); ->setDescription('Just for catchAdmin export data');
} }
protected function execute(Input $input, Output $output) protected function execute(Input $input, Output $output)
{ {
$table = \config('database.connections.mysql.prefix') . $input->getArgument('table');
$parent = $input->getOption('pid');
$data = Db::name($table)->where('deleted_at', 0)->select()->toArray();
if ($parent) {
$data = Tree::done($data, 0, $parent);
}
file_put_contents(root_path() . DIRECTORY_SEPARATOR . $table . '.php', "<?php\r\n return " . var_export($data, true));
$output->info('succeed!'); $output->info('succeed!');
} }
} }