diff --git a/app/Controllers/SkinlibController.php b/app/Controllers/SkinlibController.php index 6a6e80fb..8962df89 100644 --- a/app/Controllers/SkinlibController.php +++ b/app/Controllers/SkinlibController.php @@ -96,7 +96,7 @@ class SkinlibController extends BaseController { if (!isset($_GET['tid'])) Http::abort(404, 'No specified tid.'); $texture = Texture::find($_GET['tid']); -/* + if (!$texture || $texture && !\Storage::exist(BASE_DIR."/textures/".$texture->hash)) { if (Option::get('auto_del_invalid_texture') == "1") { if ($texture) $texture->delete(); @@ -104,7 +104,7 @@ class SkinlibController extends BaseController } Http::abort(404, '请求的材质文件已经被删除,请联系管理员删除该条目'); } -*/ + if ($texture->public == "0") { if (is_null($this->user) || ($this->user->uid != $texture->uploader && !$this->user->is_admin)) Http::abort(404, '请求的材质已经设为隐私,仅上传者和管理员可查看'); diff --git a/app/Services/Storage.php b/app/Services/Storage.php index 4f980ce2..906d1cec 100644 --- a/app/Services/Storage.php +++ b/app/Services/Storage.php @@ -37,6 +37,15 @@ class Storage return $new_fname; } + public static function size($filename) + { + if (self::exist($filename)) { + return filesize($filename); + } else { + return 0; + } + } + /** * Remove a file * diff --git a/resources/views/setup/migrations/import-v2-both.tpl b/resources/views/setup/migrations/import-v2-both.tpl new file mode 100644 index 00000000..efee3228 --- /dev/null +++ b/resources/views/setup/migrations/import-v2-both.tpl @@ -0,0 +1,97 @@ +@extends('setup.migrations.master') + +@section('content') + + + +{{-- Step 1: --}} + +@if ($step == '1') +

同时导入用户数据以及用户材质

+ +

将同时导入用户数据以及材质,逻辑比单独导入更加完善。

+

导入后材质的上传者将被设置为 v2 的原用户,上传时间将被设置为 v2 用户的最后修改时间。导入后的材质会被自动添加至原上传者的衣柜中,并应用至其所属角色。

+

注意: 请先将 v2 的 users 表改名导入到当前 v3 的同一数据库中

+ +
+ +
+ + + + + + + + + + + + + + + +
+ +

就是你改名过的 v2 的 users 表现在的名字

+
+ +

+ + {username} 表示材质原本的上传者用户名,{model} 表示原来材质的模型 + +

+
私密材质 + +
+ + + @if (isset($_SESSION['msg'])) + + + @endif + +

+ +

+
+@endif + +{{-- Step 2: --}} + +@if ($step == '2') + + + +

导入成功

+ + + +

已导入 {{ $result['user']['imported'] }} 个用户,{{ $result['user']['duplicated'] }} 个用户因重复而未导入。

+

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

+ +

+导入完成 +

+ +@endif + +@endsection diff --git a/resources/views/setup/migrations/import-v2-textures.tpl b/resources/views/setup/migrations/import-v2-textures.tpl index 48de5db2..192dbd5e 100644 --- a/resources/views/setup/migrations/import-v2-textures.tpl +++ b/resources/views/setup/migrations/import-v2-textures.tpl @@ -10,7 +10,7 @@

导入皮肤库

本功能用于导入 v2 用户皮肤至 v3 的皮肤库

-

请先将 v2 的 users 表改名导入到当前 v3 的同一数据库中

+

注意:请先将 v2 的 users 表改名导入到当前 v3 的同一数据库中

diff --git a/resources/views/setup/migrations/import-v2-users.tpl b/resources/views/setup/migrations/import-v2-users.tpl index 0ef1252e..0faf670d 100644 --- a/resources/views/setup/migrations/import-v2-users.tpl +++ b/resources/views/setup/migrations/import-v2-users.tpl @@ -10,6 +10,7 @@

导入用户数据

本功能用于导入 v2 的用户账户数据至 v3,请先将 v2 的 users 表改名导入到当前 v3 的同一数据库中

+

仅导入用户数据将会丢失用户的材质信息,如需保存原来的材质信息,请 同时导入用户和材质

注意: v3 当前设置的密码加密方式必须和之前 v2 的一致,否则导入后的用户将无法登录。


diff --git a/resources/views/setup/migrations/index.tpl b/resources/views/setup/migrations/index.tpl index c2d6de99..83837734 100644 --- a/resources/views/setup/migrations/index.tpl +++ b/resources/views/setup/migrations/index.tpl @@ -13,5 +13,6 @@

导入 v2 皮肤库 导入 v2 用户数据 + 同时导入

@endsection diff --git a/setup/migrations/import_v2_both.php b/setup/migrations/import_v2_both.php new file mode 100644 index 00000000..0e1a965d --- /dev/null +++ b/setup/migrations/import_v2_both.php @@ -0,0 +1,139 @@ +getRecordNum() / 250); + +$score = Option::get('user_initial_score'); + +$public = isset($_POST['import_as_private']) ? '0' : '1'; + +// chunked (optionally) +for ($i = 0; $i <= $steps; $i++) { + $start = $i * 250; + + $sql = "SELECT * FROM `$v2_table_name` ORDER BY `uid` LIMIT $start, 250"; + $result = $db->query($sql); + + while ($row = $result->fetch_array()) { + // compile patterns + $name = str_replace('{username}', $row['username'], $_POST['texture_name_pattern']); + + if (!$db->has('player_name', $row['username'], $v3_players)) { + $user = new App\Models\UserModel; + + $user->email = ''; + $user->nickname = $row['username']; + $user->score = $score; + $user->password = $row['password']; + $user->avatar = '0'; + $user->ip = $row['ip']; + $user->permission = '0'; + $user->last_sign_at = Utils::getTimeFormatted(time() - 86400); + $user->register_at = Utils::getTimeFormatted(); + + $user->save(); + + $models = ['steve', 'alex', 'cape']; + + $textures = []; + + foreach ($models as $model) { + if ($row["hash_$model"] != "") { + $name = str_replace('{model}', $model, $name); + + if (!$db->has('hash', $row["hash_$model"], $v3_textures)) { + $t = new App\Models\Texture; + + $t->name = $name; + $t->type = $model; + $t->likes = 1; + $t->hash = $row["hash_$model"]; + $t->size = Storage::size(BASE_DIR.'/textures/'.$row["hash_$model"]); + $t->uploader = $user->uid; + $t->public = $public; + $t->upload_at = $row['last_modified'] ? : Utils::getTimeFormatted(); + + $t->save(); + + $textures[$model] = $t->tid; + + $texture_imported++; + } else { + $texture_duplicated++; + } + } + } + + $p = new App\Models\PlayerModel; + + $p->uid = $user->uid; + $p->player_name = $row['username']; + $p->preference = $row['preference']; + $p->last_modified = $row['last_modified'] ? : Utils::getTimeFormatted(); + + $c = new App\Models\ClosetModel; + + $c->uid = $user->uid; + $c->textures = ''; + + $items = []; + + foreach ($textures as $model => $tid) { + $property = "tid_$model"; + $p->$property = $tid; + + $items[] = array( + 'tid' => $tid, + 'name' => $name, + 'add_at' => $row['last_modified'] ? : Utils::getTimeFormatted() + ); + } + + $c->textures = json_encode($items); + + $p->save(); + $c->save(); + + $user_imported++; + // echo $row['username']." saved.
"; + } else { + $user_duplicated++; + // echo $row['username']." duplicated.
"; + } + + + } +} + +return [ + 'user' => [ + 'imported' => $user_imported, + 'duplicated' => $user_duplicated + ], + 'texture' => [ + 'imported' => $texture_imported, + 'duplicated' => $texture_duplicated + ] +]; diff --git a/setup/migrations/import_v2_textures.php b/setup/migrations/import_v2_textures.php index 5cdf1853..603ff4ff 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-19 22:48:54 + * @Last Modified time: 2016-08-20 20:49:37 * * There are still some coupling relationships here but, * Just let it go :) @@ -22,9 +22,9 @@ $db = Database::table($v2_table_name, true); $steps = ceil($db->getRecordNum() / 250); -$public = isset($_POST['import_as_private']) ? '1' : '0'; +$public = isset($_POST['import_as_private']) ? '0' : '1'; -// chunked +// chunked (optionally) for ($i = 0; $i <= $steps; $i++) { $start = $i * 250; @@ -35,72 +35,30 @@ for ($i = 0; $i <= $steps; $i++) { // compile patterns $name = str_replace('{username}', $row['username'], $_POST['texture_name_pattern']); - if ($row['hash_steve'] != "") { - $name = str_replace('{model}', 'steve', $name); + $models = ['steve', 'alex', 'cape']; - if (!$db->has('hash', $row['hash_steve'], $v3_table_name)) { - $db->insert([ - 'name' => $name, - 'type' => 'steve', - 'likes' => 0, - 'hash' => $row['hash_steve'], - 'size' => 0, - 'uploader' => $_POST['uploader_uid'], - 'public' => $public, - 'upload_at' => Utils::getTimeFormatted() - ], $v3_table_name); + foreach ($models as $model) { + if ($row['hash_steve'] != "") { + $name = str_replace('{model}', $model, $name); - $imported++; - // echo $row['hash_steve']." saved.
"; - } else { - $duplicated++; - // echo $row['hash_steve']." duplicated.
"; - } - } + if (!$db->has('hash', $row["hash_$model"], $v3_table_name)) { + $db->insert([ + 'name' => $name, + 'type' => $model, + 'likes' => 0, + 'hash' => $row["hash_$model"], + 'size' => Storage::size(BASE_DIR.'/textures/'.$row["hash_$model"]), + 'uploader' => $_POST['uploader_uid'], + 'public' => $public, + 'upload_at' => Utils::getTimeFormatted() + ], $v3_table_name); - if ($row['hash_alex'] != "") { - $name = str_replace('{model}', 'alex', $name); - - if (!$db->has('hash', $row['hash_alex'], $v3_table_name)) { - $db->insert([ - 'name' => $name, - 'type' => 'alex', - 'likes' => 0, - 'hash' => $row['hash_alex'], - 'size' => 0, - 'uploader' => $_POST['uploader_uid'], - 'public' => $public, - 'upload_at' => Utils::getTimeFormatted() - ], $v3_table_name); - - $imported++; - // echo $row['hash_alex']." saved.
"; - } else { - $duplicated++; - // echo $row['hash_alex']." duplicated.
"; - } - } - - if ($row['hash_cape'] != "") { - $name = str_replace('{model}', 'cape', $name); - - if (!$db->has('hash', $row['hash_cape'], $v3_table_name)) { - $db->insert([ - 'name' => $name, - 'type' => 'cape', - 'likes' => 0, - 'hash' => $row['hash_cape'], - 'size' => 0, - 'uploader' => $_POST['uploader_uid'], - 'public' => $public, - 'upload_at' => Utils::getTimeFormatted() - ], $v3_table_name); - - $imported++; - // echo $row['hash_cape']." saved.
"; - } else { - $duplicated++; - // echo $row['hash_cape']." duplicated.
"; + $imported++; + // echo $row['hash_steve']." saved.
"; + } else { + $duplicated++; + // echo $row['hash_steve']." duplicated.
"; + } } } } diff --git a/setup/migrations/import_v2_users.php b/setup/migrations/import_v2_users.php index 371e2ece..c6515c48 100644 --- a/setup/migrations/import_v2_users.php +++ b/setup/migrations/import_v2_users.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-08-18 17:46:19 * @Last Modified by: printempw - * @Last Modified time: 2016-08-19 22:00:02 + * @Last Modified time: 2016-08-20 18:42:56 */ if (!defined('BASE_DIR')) exit('Permission denied.'); @@ -24,7 +24,7 @@ $steps = ceil($db->getRecordNum() / 250); $score = Option::get('user_initial_score'); -// chunked +// chunked (optionally) for ($i = 0; $i <= $steps; $i++) { $start = $i * 250; @@ -53,7 +53,7 @@ for ($i = 0; $i <= $steps; $i++) { $db->insert([ 'uid' => $uid, 'player_name' => $row['username'], - 'preference' => 'steve', + 'preference' => $row['preference'], 'last_modified' => Utils::getTimeFormatted() ], $v3_players); diff --git a/setup/migrations/index.php b/setup/migrations/index.php index 20f45c79..fc208d37 100644 --- a/setup/migrations/index.php +++ b/setup/migrations/index.php @@ -59,6 +59,10 @@ switch ($action) { View::show('setup.migrations.import-v2-users'); break; + case 'import-v2-both': + View::show('setup.migrations.import-v2-both'); + break; + default: throw new App\Exceptions\E('非法参数', 1, true); break;