mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-05 07:20:58 +08:00
add getMysqlColumnInfo()
This commit is contained in:
@@ -11,7 +11,6 @@ use App\Repositories\ExamRepository;
|
||||
use App\Repositories\SearchBoxRepository;
|
||||
use App\Repositories\TorrentRepository;
|
||||
use Carbon\Carbon;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -51,14 +50,7 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// $r = \Illuminate\Support\Facades\Schema::getColumnListing('torrents');
|
||||
// $r = urldecode('%b5%8f%7c%a9%85%ed%e2%bb%09%fd1%ab%8d%11%e5%11%bb%18%deD');
|
||||
// $r = bin2hex($r);
|
||||
$str = 'passkey=bef88d0cbe4ccbc1569b8404d09c4c5a&info_hash=%cd%8d%5b%09%08%d7%1d%01_o8%c0%e1Wd%ff%95%84J%e1&peer_id=-TR3000-zxcl8rs3my5o&port=51416&uploaded=0&downloaded=0&left=0&numwant=80&key=2d2ebd37&compact=1&supportcrypto=1&ipv6=240e%3A3b1%3A6400%3Ac20%3A211%3A32ff%3Afebb%3A9fb1';
|
||||
$firstNeedle = "info_hash=";
|
||||
$start = strpos($str, $firstNeedle) + strlen($firstNeedle);
|
||||
$end = strpos($str, "&", $start);
|
||||
$r = substr($str, $start, $end - $start);
|
||||
$r = \Nexus\Database\DB::getConnection();
|
||||
dd($r);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,9 +53,6 @@ class DB
|
||||
if (!$result) {
|
||||
throw new DatabaseException(sprintf('[%s]: %s', $this->errno(), $this->error()));
|
||||
}
|
||||
$this->driver->query("SET NAMES UTF8");
|
||||
$this->driver->query("SET collation_connection = 'utf8_general_ci'");
|
||||
$this->driver->query("SET sql_mode=''");
|
||||
$this->isConnected = true;
|
||||
return true;
|
||||
}
|
||||
@@ -233,5 +230,21 @@ class DB
|
||||
return Capsule::table($table);
|
||||
}
|
||||
|
||||
public static function getMysqlColumnInfo($table, $column)
|
||||
{
|
||||
static $driver;
|
||||
$config = nexus_config('nexus.mysql');
|
||||
if (is_null($driver)) {
|
||||
$driver = new DBMysqli();
|
||||
$driver->connect($config['host'], $config['username'], $config['password'], 'information_schema', $config['port']);
|
||||
}
|
||||
$sql = sprintf(
|
||||
"select * from COLUMNS where TABLE_SCHEMA = '%s' and TABLE_NAME = '%s' and COLUMN_NAME = '%s'",
|
||||
$config['database'], $table, $column
|
||||
);
|
||||
$res = $driver->query($sql);
|
||||
return $driver->fetchAssoc($res);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@ class DBMysqli implements DBInterface
|
||||
if (mysqli_connect_errno()) {
|
||||
throw new DatabaseException(mysqli_connect_error());
|
||||
}
|
||||
$mysqli->query("SET NAMES UTF8");
|
||||
$mysqli->query("SET collation_connection = 'utf8_general_ci'");
|
||||
$mysqli->query("SET sql_mode=''");
|
||||
|
||||
/* activate reporting */
|
||||
$driver = new \mysqli_driver();
|
||||
$driver->report_mode = MYSQLI_REPORT_ALL & ~MYSQLI_REPORT_INDEX;
|
||||
@@ -82,4 +86,4 @@ class DBMysqli implements DBInterface
|
||||
return $mysqliResult->free_result();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -164,6 +164,7 @@ if ($currentStep == 3) {
|
||||
|
||||
$update->nextStep();
|
||||
} catch (\Exception $exception) {
|
||||
$update->doLog($exception->getMessage() . $exception->getTraceAsString());
|
||||
$error = $exception->getMessage();
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user