109 lines
2.7 KiB
PHP
109 lines
2.7 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
namespace App\Console\Commands;
|
|||
|
|
|
|||
|
|
use Illuminate\Console\Command;
|
|||
|
|
use Illuminate\Support\Facades\Artisan;
|
|||
|
|
|
|||
|
|
class SystemCommand extends Command
|
|||
|
|
{
|
|||
|
|
/**
|
|||
|
|
* The name and signature of the console command.
|
|||
|
|
*
|
|||
|
|
* @var string
|
|||
|
|
*/
|
|||
|
|
protected $signature = 'system {type?}';
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* The console command description.
|
|||
|
|
*
|
|||
|
|
* @var string
|
|||
|
|
*/
|
|||
|
|
protected $description = '系统安装/更新';
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Create a new command instance.
|
|||
|
|
*
|
|||
|
|
* @return void
|
|||
|
|
*/
|
|||
|
|
public function __construct()
|
|||
|
|
{
|
|||
|
|
parent::__construct();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Execute the console command.
|
|||
|
|
*
|
|||
|
|
* @return false|void
|
|||
|
|
*/
|
|||
|
|
public function handle()
|
|||
|
|
{
|
|||
|
|
$type = $this->argument('type');
|
|||
|
|
switch ($type) {
|
|||
|
|
case 'ready':
|
|||
|
|
if (!app()->isLocal()) {
|
|||
|
|
$this->error('非法环境');
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
$this->language();
|
|||
|
|
$this->comment('准备发布完成:)');
|
|||
|
|
break;
|
|||
|
|
case 'install':
|
|||
|
|
if (file_exists(__DIR__ . '/../../../install.lock')) {
|
|||
|
|
$this->error('如需重装,请删除“install.lock”文件!');
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$this->migrate();
|
|||
|
|
$this->keyGenerate();
|
|||
|
|
$this->queueRestart();
|
|||
|
|
|
|||
|
|
file_put_contents('install.lock', 'Install on ' . date('Y-m-d H:i:s'));
|
|||
|
|
$this->comment('安装完成:)');
|
|||
|
|
break;
|
|||
|
|
case 'update':
|
|||
|
|
$this->migrate();
|
|||
|
|
$this->queueRestart();
|
|||
|
|
|
|||
|
|
$this->comment('更新完成:)');
|
|||
|
|
break;
|
|||
|
|
|
|||
|
|
default:
|
|||
|
|
$this->error('只允许type参数类型为“ready”、“install”、“update”');
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private function keyGenerate(): void
|
|||
|
|
{
|
|||
|
|
if ($this->laravel['config']['app.key']) {
|
|||
|
|
$this->comment('Laravel Key 已存在' . PHP_EOL);
|
|||
|
|
} else {
|
|||
|
|
Artisan::call('key:generate', [
|
|||
|
|
'--ansi' => true,
|
|||
|
|
], $this->output);
|
|||
|
|
$this->comment('Laravel Key 已生成' . PHP_EOL);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private function migrate(): void
|
|||
|
|
{
|
|||
|
|
Artisan::call('migrate', [], $this->output);
|
|||
|
|
$this->comment('数据库迁移完成' . PHP_EOL);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private function queueRestart(): void
|
|||
|
|
{
|
|||
|
|
Artisan::call('queue:restart');
|
|||
|
|
$this->comment('队列已重启' . PHP_EOL);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private function language(): void
|
|||
|
|
{
|
|||
|
|
Artisan::call('lang:add', [
|
|||
|
|
'locales' => ['en', 'zh_CN'],
|
|||
|
|
], $this->output);
|
|||
|
|
$this->comment('Laravel语言包更新完成' . PHP_EOL);
|
|||
|
|
}
|
|||
|
|
}
|