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 (PlayerModel::where('player_name', $row['username'])->get()->isEmpty()) { $user = new 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); $res = Texture::where('hash', $row["hash_$model"])->first(); if (!$res) { $t = new Texture; // file size in bytes $size = Storage::disk('textures')->has($row["hash_$model"]) ? Storage::disk('textures')->size($row["hash_$model"]) : 0; $t->name = $name; $t->type = $model; $t->likes = 1; $t->hash = $row["hash_$model"]; $t->size = ceil($size / 1024); $t->uploader = $user->uid; $t->public = $public; $t->upload_at = $row['last_modified'] ? : Utils::getTimeFormatted(); $t->save(); $textures[$model] = $t->tid; $texture_imported++; } else { $textures[$model] = $res->tid; $texture_duplicated++; } } } $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 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 ] ];