mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 完成安装脚本,全部流程
This commit is contained in:
parent
0f420a0715
commit
daf1d965e7
@ -16,8 +16,6 @@ class Install extends Command {
|
||||
// 指令配置
|
||||
$this->setName('apiadmin:install')
|
||||
->addOption('db', null, Option::VALUE_REQUIRED, '数据库连接参数,格式为:数据库类型://用户名:密码@数据库地址:数据库端口/数据库名#字符集')
|
||||
->addOption('username', null, Option::VALUE_REQUIRED, '超管账号名', 'root')
|
||||
->addOption('password', null, Option::VALUE_REQUIRED, '超管账号密码', '123456')
|
||||
->setDescription('ApiAdmin安装脚本');
|
||||
}
|
||||
|
||||
@ -40,9 +38,6 @@ class Install extends Command {
|
||||
}
|
||||
|
||||
if ($input->hasOption('db')) {
|
||||
$user = $input->getOption('username');
|
||||
$pass = $input->getOption('password');
|
||||
|
||||
try {
|
||||
$options = $options = $this->parseDsnConfig($input->getOption('db'));
|
||||
Connection::instance($options)->getTables($options['database']);
|
||||
@ -68,7 +63,7 @@ class Install extends Command {
|
||||
$output->info('ApiAdmin配置更新成功');
|
||||
|
||||
//生成lock文件,并且写入用户名密码
|
||||
file_put_contents($lockFile, "<?php return ['username' => '{$user}', 'password' => '{$pass}'];");
|
||||
file_put_contents($lockFile, "lock");
|
||||
$output->info('lock文件初始化成功');
|
||||
} catch (\PDOException $e) {
|
||||
$output->highlight($e->getMessage());
|
||||
|
50
database/migrations/20190515031308_ini_admin_user.php
Normal file
50
database/migrations/20190515031308_ini_admin_user.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use think\facade\Env;
|
||||
use think\migration\Migrator;
|
||||
use \app\util\Strs;
|
||||
use \app\util\Tools;
|
||||
|
||||
class IniAdminUser extends Migrator {
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
|
||||
public function up() {
|
||||
$pass = Strs::randString(8);
|
||||
$data = [
|
||||
'id' => 1,
|
||||
'username' => 'root',
|
||||
'nickname' => 'root',
|
||||
'password' => Tools::userMd5($pass),
|
||||
'create_time' => time(),
|
||||
'create_ip' => ip2long('127.0.0.1'),
|
||||
'update_time' => time(),
|
||||
'status' => 1,
|
||||
'openid' => null
|
||||
];
|
||||
|
||||
$this->table('admin_user')->insert($data)->saveData();
|
||||
|
||||
$lockFile = Env::get('app_path') . 'install' . DIRECTORY_SEPARATOR . 'lock.php';
|
||||
file_put_contents($lockFile, "username:{root}, password:{{$pass}}");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user