diff --git a/app/Services/Database.php b/app/Services/Database.php index 519a398e..bc6688aa 100644 --- a/app/Services/Database.php +++ b/app/Services/Database.php @@ -29,9 +29,9 @@ class Database * @param string $table_name * @param array $config */ - function __construct($table_name = '', $config = null) + function __construct($table_name = '', $config = null, $no_prefix = false) { - $config = is_null($config) ? (require BASE_DIR.'/config/database.php') : $config; + $config = is_null($config) ? Config::getDbConfig() : $config; @$this->connection = new \mysqli( $config['host'], $config['username'], @@ -41,11 +41,11 @@ class Database ); if ($this->connection->connect_error) - throw new E("Could not connect to MySQL database. Check your config.php:". + throw new E("Could not connect to MySQL database. Check your configuration:". $this->connection->connect_error, $this->connection->connect_errno, true); $this->connection->query("SET names 'utf8'"); - $this->table_name = $config['prefix'].$table_name; + $this->table_name = $no_prefix ? $table_name : $config['prefix'].$table_name; } public function query($sql) @@ -89,11 +89,6 @@ class Database } - public function has($key, $value, $table = null) - { - return ($this->getNumRows($key, $value, $table) != 0) ? true : false; - } - public function insert($data, $table = null) { $keys = ""; @@ -114,6 +109,17 @@ class Database return $this->query($sql); } + public function has($key, $value, $table = null) + { + return ($this->getNumRows($key, $value, $table) != 0) ? true : false; + } + + public function hasTable($table_name) + { + $sql = "SELECT table_name FROM `INFORMATION_SCHEMA`.`TABLES` WHERE (table_name = '$table_name') AND TABLE_SCHEMA='".Config::getDbConfig()['database']."'"; + return ($this->query($sql)->num_rows != 0) ? true : false; + } + public function update($key, $value, $condition = null, $table = null) { $table = is_null($table) ? $this->table_name : $table; diff --git a/resources/views/setup/migrations/import-v2-textures.tpl b/resources/views/setup/migrations/import-v2-textures.tpl index 4ee01fa1..1ab5d6db 100644 --- a/resources/views/setup/migrations/import-v2-textures.tpl +++ b/resources/views/setup/migrations/import-v2-textures.tpl @@ -69,8 +69,8 @@ } else { $_POST['uploader_uid'] = ($_POST['uploader_uid'] == "") ? 0 : (int)$_POST['uploader_uid']; - if (!Schema::hasTable($_POST['v2_table_name'])) { - Http::redirect('index.php?action=import-v2-textures&step=1', '不存在的数据表'); + if (!(new Database)->hasTable($_POST['v2_table_name'])) { + Http::redirect('index.php?action=import-v2-textures&step=1', "数据表 {$_POST['v2_table_name']} 不存在"); } } } else { @@ -83,6 +83,7 @@

已导入 {{ $result['imported'] }} 个材质到皮肤库,{{ $result['duplicated'] }} 个材质因重复而未导入。

+

注意:请将 v2 的 textures 文件夹内容复制到 v3 的 textures 文件夹中

导入完成 diff --git a/setup/migrations/import_v2_textures.php b/setup/migrations/import_v2_textures.php index 13b834c0..9eff89c0 100644 --- a/setup/migrations/import_v2_textures.php +++ b/setup/migrations/import_v2_textures.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-08-09 21:44:13 * @Last Modified by: printempw - * @Last Modified time: 2016-08-10 18:00:38 + * @Last Modified time: 2016-08-10 22:41:24 * * There are still some coupling relationships here but, * Just let it go :) @@ -16,7 +16,7 @@ $imported = 0; $duplicated = 0; // use db helper instead of fat ORM -$db = new Database($v2_table_name); +$db = new Database($v2_table_name, null, true); $steps = ceil($db->getRecordNum() / 250); @@ -62,7 +62,7 @@ for ($i = 0; $i <= $steps; $i++) { 'name' => $name, 'type' => 'alex', 'likes' => 0, - 'hash' => $row['hash_steve'], + 'hash' => $row['hash_alex'], 'size' => 0, 'uploader' => $_POST['uploader_uid'], 'public' => '1', @@ -85,7 +85,7 @@ for ($i = 0; $i <= $steps; $i++) { 'name' => $name, 'type' => 'cape', 'likes' => 0, - 'hash' => $row['hash_steve'], + 'hash' => $row['hash_cape'], 'size' => 0, 'uploader' => $_POST['uploader_uid'], 'public' => '1',