diff --git a/app/Services/Migration.php b/app/Services/Migration.php
index ffcf5bca..3d9f75b6 100644
--- a/app/Services/Migration.php
+++ b/app/Services/Migration.php
@@ -14,4 +14,9 @@ class Migration
require BASE_DIR."/setup/tables.php";
}
+ public static function importV2Textures()
+ {
+ return require BASE_DIR."/setup/migrations/import_v2_textures.php";
+ }
+
}
diff --git a/resources/views/setup/migrations/import-v2-textures.tpl b/resources/views/setup/migrations/import-v2-textures.tpl
new file mode 100644
index 00000000..4ee01fa1
--- /dev/null
+++ b/resources/views/setup/migrations/import-v2-textures.tpl
@@ -0,0 +1,93 @@
+@extends('setup.migrations.master')
+
+@section('content')
+
+
+
+{{-- Step 1: --}}
+
+@if ($step == '1')
+
导入皮肤库
+
+本功能用于导入 v2 用户皮肤至 v3 的皮肤库
+请先将 v2 的 users 表改名导入到当前 v3 的同一数据库中
+
+
+@endif
+
+{{-- Step 2: --}}
+
+@if ($step == '2')
+
+
+
+导入成功
+
+
+
+已导入 {{ $result['imported'] }} 个材质到皮肤库,{{ $result['duplicated'] }} 个材质因重复而未导入。
+
+
+导入完成
+
+
+@endif
+
+@endsection
diff --git a/resources/views/setup/migrations/index.tpl b/resources/views/setup/migrations/index.tpl
new file mode 100644
index 00000000..e1d815b3
--- /dev/null
+++ b/resources/views/setup/migrations/index.tpl
@@ -0,0 +1,18 @@
+@extends('setup.migrations.master')
+
+@section('content')
+欢迎
+
+欢迎使用 Blessing Skin Server 数据迁移工具,此工具用于迁移 v2 的数据至 v3。
+目前仅支持从 v2 导入用户皮肤至 v3 的皮肤库中。
+更多功能等我有时间再些吧(学业为重
+
+
+
+选择一个操作以继续:
+
+
+ 导入 v2 皮肤库
+ 导入 v2 用户数据
+
+@endsection
diff --git a/resources/views/setup/migrations/master.tpl b/resources/views/setup/migrations/master.tpl
new file mode 100644
index 00000000..76e84f93
--- /dev/null
+++ b/resources/views/setup/migrations/master.tpl
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+ Blessing Skin Server 数据迁移
+
+
+
+
+
+
+
+Blessing Skin Server
+
+@yield('content')
+
+
+
+
diff --git a/setup/migrations/import_v2_textures.php b/setup/migrations/import_v2_textures.php
new file mode 100644
index 00000000..13b834c0
--- /dev/null
+++ b/setup/migrations/import_v2_textures.php
@@ -0,0 +1,108 @@
+getRecordNum() / 250);
+
+// chunked
+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 ($row['hash_steve'] != "") {
+ $name = str_replace('{model}', 'steve', $name);
+
+ 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' => '1',
+ 'upload_at' => Utils::getTimeFormatted()
+ ], $v3_table_name);
+
+ $imported += 1;
+ // echo $row['hash_steve']." saved.
";
+ } else {
+ $duplicated += 1;
+ // echo $row['hash_steve']." duplicated.
";
+ }
+ }
+
+ 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_steve'],
+ 'size' => 0,
+ 'uploader' => $_POST['uploader_uid'],
+ 'public' => '1',
+ 'upload_at' => Utils::getTimeFormatted()
+ ], $v3_table_name);
+
+ $imported += 1;
+ // echo $row['hash_alex']." saved.
";
+ } else {
+ $duplicated += 1;
+ // 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_steve'],
+ 'size' => 0,
+ 'uploader' => $_POST['uploader_uid'],
+ 'public' => '1',
+ 'upload_at' => Utils::getTimeFormatted()
+ ], $v3_table_name);
+
+ $imported += 1;
+ // echo $row['hash_cape']." saved.
";
+ } else {
+ $duplicated += 1;
+ // echo $row['hash_cape']." duplicated.
";
+ }
+ }
+ }
+}
+
+return [
+ 'imported' => $imported,
+ 'duplicated' => $duplicated
+];
diff --git a/setup/migrations/index.php b/setup/migrations/index.php
new file mode 100644
index 00000000..0dd23127
--- /dev/null
+++ b/setup/migrations/index.php
@@ -0,0 +1,61 @@
+getToken())
+ Http::redirect('../../auth/login', '无效的 token,请重新登录~');
+
+ if ($user->getPermission() != "2")
+ Http::abort(403, '此页面仅超级管理员可访问');
+
+} else {
+ Http::redirect('../../auth/login', '非法访问,请先登录');
+}
+
+$action = isset($_GET['action']) ? $_GET['action'] : 'index';
+
+switch ($action) {
+ case 'index':
+ View::show('setup.migrations.index');
+ break;
+
+ case 'import-v2-textures':
+ View::show('setup.migrations.import-v2-textures');
+ break;
+
+ default:
+ throw new App\Exceptions\E('非法参数', 1, true);
+ break;
+}
+
+