Merge branch 'master' of https://gitee.com/jaguarjack/catchAdmin
This commit is contained in:
commit
ecae3e90f1
@ -5,6 +5,7 @@ use catcher\command\InstallCommand;
|
||||
use catcher\command\MigrateRunCommand;
|
||||
use catcher\command\ModelGeneratorCommand;
|
||||
use catcher\command\ModuleCacheCommand;
|
||||
use catcher\command\SeedRunCommand;
|
||||
use catcher\validates\Sometimes;
|
||||
use think\facade\Validate;
|
||||
use think\Service;
|
||||
@ -23,6 +24,7 @@ class CatchAdminService extends Service
|
||||
ModuleCacheCommand::class,
|
||||
MigrateRunCommand::class,
|
||||
ModelGeneratorCommand::class,
|
||||
SeedRunCommand::class
|
||||
]);
|
||||
|
||||
$this->registerValidates();
|
||||
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Seeder;
|
||||
|
||||
class Abc extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run Method.
|
||||
*
|
||||
* Write your database seeder using this method.
|
||||
*
|
||||
* More information on writing seeders is available here:
|
||||
* http://docs.phinx.org/en/latest/seeding.html
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
30
catchAdmin/user/database/seeds/UserSeeder.php
Normal file
30
catchAdmin/user/database/seeds/UserSeeder.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Seeder;
|
||||
|
||||
class UserSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run Method.
|
||||
*
|
||||
* Write your database seeder using this method.
|
||||
*
|
||||
* More information on writing seeders is available here:
|
||||
* http://docs.phinx.org/en/latest/seeding.html
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$row = [
|
||||
'username' => 'wuyanwen',
|
||||
'password' => password_hash('password',PASSWORD_DEFAULT),
|
||||
'email' => 'njphper@gmail.com',
|
||||
'status' => 1,
|
||||
'last_login_ip' => ip2long('127.0.0.1'),
|
||||
'last_login_time' => time(),
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
'deleted_at' => '',
|
||||
];
|
||||
$this->table('users')->insert($row)->save();
|
||||
}
|
||||
}
|
64
extend/catcher/command/SeedRunCommand.php
Normal file
64
extend/catcher/command/SeedRunCommand.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace catcher\command;
|
||||
|
||||
use catcher\CatchAdmin;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Argument as InputArgument;
|
||||
use think\console\input\Option;
|
||||
use think\console\input\Option as InputOption;
|
||||
use think\console\Output;
|
||||
use think\migration\command\seed\Run;
|
||||
|
||||
class SeedRunCommand extends Run
|
||||
{
|
||||
protected $module;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('catch-seed:run')
|
||||
->setDescription('the catch-seed:run command to Run database seeders')
|
||||
->addArgument('module', Argument::REQUIRED, 'seed the module database')
|
||||
->addOption('--seed', '-s', InputOption::VALUE_REQUIRED, 'What is the name of the seeder?')
|
||||
->setHelp(<<<EOT
|
||||
The <info>catch-seed:run</info> command runs all available or individual seeders
|
||||
<info>php think catch-seed:run module</info>
|
||||
<info>php think catch-seed:run -s UserSeeder</info>
|
||||
<info>php think catch-seed:run -v</info>
|
||||
|
||||
EOT
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$this->module = strtolower($input->getArgument('module'));
|
||||
$seed = $input->getOption('seed');
|
||||
|
||||
// run the seed(ers)
|
||||
$start = microtime(true);
|
||||
$this->seed($seed);
|
||||
$end = microtime(true);
|
||||
|
||||
$output->writeln(CatchAdmin::moduleSeedsDirectory($this->module));
|
||||
$output->writeln('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 获取 seeder path
|
||||
* @return string
|
||||
* @param $module
|
||||
* @date: 2019/12/10 14:01
|
||||
*/
|
||||
protected function getPath()
|
||||
{
|
||||
return CatchAdmin::moduleSeedsDirectory($this->module);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user