v2board/app/Console/Commands/V2boardUpdate.php

62 lines
1.3 KiB
PHP
Raw Normal View History

2019-11-23 23:35:54 +08:00
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
2019-12-19 21:20:51 +08:00
use Illuminate\Support\Facades\DB;
2019-11-23 23:35:54 +08:00
2019-12-19 21:20:51 +08:00
class V2boardUpdate extends Command
2019-11-23 23:35:54 +08:00
{
/**
* The name and signature of the console command.
*
* @var string
*/
2019-12-19 21:20:51 +08:00
protected $signature = 'v2board:update';
2019-11-23 23:35:54 +08:00
/**
* The console command description.
*
* @var string
*/
2019-12-19 21:20:51 +08:00
protected $description = 'v2board 更新';
2019-11-23 23:35:54 +08:00
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
2019-12-19 22:00:03 +08:00
\Artisan::call('config:cache');
2020-01-11 13:36:52 +08:00
DB::connection()->getPdo();
2020-01-29 17:10:10 +08:00
$file = \File::get(base_path() . '/database/update.sql');
2020-01-11 13:36:52 +08:00
if (!$file) {
abort(500, '数据库文件不存在');
}
$sql = str_replace("\n", "", $file);
$sql = preg_split("/;/", $sql);
if (!is_array($sql)) {
abort(500, '数据库文件格式有误');
2019-12-19 22:22:31 +08:00
}
$this->info('正在导入数据库请稍等...');
2020-01-11 13:36:52 +08:00
foreach ($sql as $item) {
try {
DB::select(DB::raw($item));
} catch (\Exception $e) {
}
}
2019-12-19 22:22:31 +08:00
$this->info('更新完毕');
2019-11-23 23:35:54 +08:00
}
}