From 2e8139809b2cb0f4f580beffaf77f48c140ba967 Mon Sep 17 00:00:00 2001 From: printempw Date: Mon, 22 Aug 2016 21:45:04 +0800 Subject: [PATCH] fix bug of migrations --- setup/migrations/import_v2_both.php | 24 ++++++++++++++++-------- setup/migrations/import_v2_textures.php | 4 ++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/setup/migrations/import_v2_both.php b/setup/migrations/import_v2_both.php index 0e1a965d..12e074bb 100644 --- a/setup/migrations/import_v2_both.php +++ b/setup/migrations/import_v2_both.php @@ -3,9 +3,14 @@ * @Author: printempw * @Date: 2016-08-18 17:46:19 * @Last Modified by: printempw - * @Last Modified time: 2016-08-20 20:49:29 + * @Last Modified time: 2016-08-21 09:41:14 */ +use App\Models\UserModel; +use App\Models\PlayerModel; +use App\Models\ClosetModel; +use App\Models\Texture; + if (!defined('BASE_DIR')) exit('Permission denied.'); $v2_table_name = $_POST['v2_table_name']; @@ -40,8 +45,8 @@ for ($i = 0; $i <= $steps; $i++) { // 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; + if (PlayerModel::where('player_name', $row['username'])->get()->isEmpty()) { + $user = new UserModel; $user->email = ''; $user->nickname = $row['username']; @@ -63,14 +68,16 @@ for ($i = 0; $i <= $steps; $i++) { if ($row["hash_$model"] != "") { $name = str_replace('{model}', $model, $name); - if (!$db->has('hash', $row["hash_$model"], $v3_textures)) { - $t = new App\Models\Texture; + $res = Texture::where('hash', $row["hash_$model"])->first(); + + if ($res->isEmpty()) { + $t = new 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->size = ceil(Storage::size(BASE_DIR.'/textures/'.$row["hash_$model"]) / 1024); $t->uploader = $user->uid; $t->public = $public; $t->upload_at = $row['last_modified'] ? : Utils::getTimeFormatted(); @@ -81,19 +88,20 @@ for ($i = 0; $i <= $steps; $i++) { $texture_imported++; } else { + $textures[$model] = $res->tid; $texture_duplicated++; } } } - $p = new App\Models\PlayerModel; + $p = new 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 = new ClosetModel; $c->uid = $user->uid; $c->textures = ''; diff --git a/setup/migrations/import_v2_textures.php b/setup/migrations/import_v2_textures.php index 603ff4ff..b3328391 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-20 20:49:37 + * @Last Modified time: 2016-08-20 23:43:45 * * There are still some coupling relationships here but, * Just let it go :) @@ -47,7 +47,7 @@ for ($i = 0; $i <= $steps; $i++) { 'type' => $model, 'likes' => 0, 'hash' => $row["hash_$model"], - 'size' => Storage::size(BASE_DIR.'/textures/'.$row["hash_$model"]), + 'size' => ceil(Storage::size(BASE_DIR.'/textures/'.$row["hash_$model"]) / 1024), 'uploader' => $_POST['uploader_uid'], 'public' => $public, 'upload_at' => Utils::getTimeFormatted()