add getMysqlColumnInfo()

This commit is contained in:
xiaomlove
2021-06-06 13:41:05 +08:00
parent 38869ea196
commit eca64ec4c0
5 changed files with 42 additions and 16 deletions

View File

@@ -4,6 +4,8 @@ namespace Nexus\Install;
use App\Models\Category;
use App\Models\Icon;
use App\Models\Setting;
use Illuminate\Support\Str;
use Nexus\Database\DB;
class Update extends Install
@@ -64,6 +66,7 @@ class Update extends Install
$id = DB::insert($table, $insert);
$this->doLog("[ADD CUSTOM FIELD MENU] insert: " . json_encode($insert) . " to table: $table, id: $id");
}
//since beta8
if (WITH_LARAVEL && DB::schema()->hasColumn('categories', 'icon_id')) {
$this->doLog('[INIT CATEGORY ICON_ID]');
$icon = Icon::query()->orderBy('id', 'asc')->first();
@@ -71,11 +74,24 @@ class Update extends Install
Category::query()->where('icon_id', 0)->update(['icon_id' => $icon->id]);
}
}
//fix base url, since beta8
if (WITH_LARAVEL && DB::schema()->hasTable('settings')) {
$settingBasic = get_setting('basic');
if (isset($settingBasic['BASEURL']) && Str::startsWith($settingBasic['BASEURL'], 'localhost')) {
$this->doLog('[RESET CONFIG basic.BASEURL]');
Setting::query()->where('name', 'basic.BASEURL')->update(['value' => '']);
}
if (isset($settingBasic['announce_url']) && Str::startsWith($settingBasic['announce_url'], 'localhost')) {
$this->doLog('[RESET CONFIG basic.announce_url]');
Setting::query()->where('name', 'basic.announce_url')->update(['value' => '']);
}
}
//torrent support sticky second level
if (WITH_LARAVEL) {
$columnType = DB::schema()->getColumnType('torrents', 'pos_state');
$this->doLog("[TORRENT POS_STATE], column type: $columnType");
if ($columnType == 'enum') {
$columnInfo = DB::getMysqlColumnInfo('torrents', 'pos_state');
$this->doLog("[TORRENT POS_STATE], column info: " . json_encode($columnInfo));
if ($columnInfo['DATA_TYPE'] == 'enum') {
$sql = "alter table torrents modify `pos_state` varchar(32) NOT NULL DEFAULT 'normal'";
$this->doLog("[ALTER TORRENT POS_STATE TYPE TO VARCHAR], $sql");
sql_query($sql);