Files
hdk-admin/src/Install/UpdateCommand.php
李东云 2625bd2826 chore: 修改文件权限并添加脚本和CI配置
修改多个文件的权限为755,添加release.sh和docker-env.sh脚本,配置Gitea的CI工作流和版本更新日志配置文件
2025-04-16 15:47:06 +08:00

45 lines
1.3 KiB
PHP
Executable File

<?php
namespace HyperfAdmin\Admin\Install;
use Composer\Semver\Comparator;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\DbConnection\Db;
use Hyperf\Utils\Composer;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
class UpdateCommand extends HyperfCommand
{
protected $name = 'hyperf-admin:admin-update';
protected function configure()
{
$this->setDescription('update db for hyperf-admin.')
->addArgument('version', InputArgument::REQUIRED, 'the update db version.');
}
public function handle()
{
$version = $this->input->getArgument('version');
$db_conf = config('databases.hyperf_admin');
if (!$db_conf || !$db_conf['host']) {
$this->output->error('place set hyperf_admin db config in env');
return 1;
}
$update_sql_file = __DIR__ . "/update_{$version}.sql";
if (!file_exists($update_sql_file)) {
$this->output->error("the version {$version} file not found");
return 1;
}
$sql = file_get_contents($update_sql_file);
$re = Db::connection('hyperf_admin')->getPdo()->exec($sql);
$this->output->success('hyperf-admin db update success');
}
}