From 28ea2b2858a460b707f8fe444fcb5da971b13ed3 Mon Sep 17 00:00:00 2001 From: printempw Date: Fri, 25 Nov 2016 22:34:41 +0800 Subject: [PATCH] separate v2 data migrations as a plugin --- app/Services/Updater.php | 169 ------------------ config/menu.php | 1 - config/update.php | 27 --- resources/views/admin/download.tpl | 67 ------- .../views/setup/migrations/import-v2-both.tpl | 95 ---------- .../setup/migrations/import-v2-textures.tpl | 105 ----------- .../setup/migrations/import-v2-users.tpl | 72 -------- resources/views/setup/migrations/index.tpl | 18 -- resources/views/setup/migrations/master.tpl | 29 --- 9 files changed, 583 deletions(-) delete mode 100644 app/Services/Updater.php delete mode 100644 config/update.php delete mode 100644 resources/views/admin/download.tpl delete mode 100644 resources/views/setup/migrations/import-v2-both.tpl delete mode 100644 resources/views/setup/migrations/import-v2-textures.tpl delete mode 100644 resources/views/setup/migrations/import-v2-users.tpl delete mode 100644 resources/views/setup/migrations/index.tpl delete mode 100644 resources/views/setup/migrations/master.tpl diff --git a/app/Services/Updater.php b/app/Services/Updater.php deleted file mode 100644 index 1afad4ca..00000000 --- a/app/Services/Updater.php +++ /dev/null @@ -1,169 +0,0 @@ -current_version = $current_version; - $this->update_sources = config('update'); - - $source = Option::get('update_source'); - - if (!isset($this->update_sources[$source])) { - Option::set('update_source', config('options.update_source')); - } - - $this->current_source = $this->update_sources[Option::get('update_source')]; - } - - /** - * Get update info from selected json source - * - * @return array Decoded json - */ - public function getUpdateInfo() - { - $ch = curl_init(); - // add timestamp to control cdn cache - $url = $this->current_source['update_url']."?v=".substr(time(), 0, -3); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - // quick fix for accessing https resources - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - $result = curl_exec($ch); - curl_close($ch); - - $this->update_info = json_decode($result, true); - return $this->update_info; - } - - /** - * Check for updates - * - * @return void - */ - public function checkUpdate() - { - $info = $this->getUpdateInfo(); - - $this->latest_version = $info['latest_version']; - $this->update_time = date('Y-m-d H:i:s', $info['update_time']); - } - - /** - * Download update files - * - * @param bool $silent Don't print messages - * @return void - */ - public function downloadUpdate($silent = true) - { - $release_url = $this->update_info['releases'][$this->latest_version]['release_url']; - - if (!$silent) - echo "

正在下载更新包:$release_url

"; - - // I don't know why curl can't get full file content here.. - $file = file_get_contents($release_url); - - if (!$silent) - echo "

下载完成。

"; - - $update_cache = storage_path('update_cache'); - - if (!is_dir($update_cache)) { - if (false === mkdir($update_cache)) { - exit('

创建下载缓存文件夹失败,请检查目录权限。

'); - } - } - - $zip_path = $update_cache."update_".time().".zip"; - - if (Storage::put($zip_path, $file) === false) { - Storage::removeDir($update_cache); - return false; - } - - return $zip_path; - } - - /** - * Check if a new version is available - * - * @return bool - */ - public function newVersionAvailable() - { - $this->checkUpdate(); - return $this->compareVersion($this->latest_version, $this->current_version); - } - - public function getUpdateSources() - { - return $this->update_sources; - } - - /** - * Compare version string - * - * @param string $v1 - * @param string $v2 - * @return boolean - */ - private function compareVersion($v1, $v2) - { - if (version_compare($v1, $v2) > 0) { - // v1 > v2 - return true; - } else { - // v1 < v2 || v1 = v2 - return false; - } - } -} diff --git a/config/menu.php b/config/menu.php index 69622c7a..db36623f 100644 --- a/config/menu.php +++ b/config/menu.php @@ -23,7 +23,6 @@ $menu['admin'] = array( ['title' => 'general.customize', 'link' => 'admin/customize', 'icon' => 'fa-paint-brush'], ['title' => 'general.score-options', 'link' => 'admin/score', 'icon' => 'fa-credit-card'], ['title' => 'general.options', 'link' => 'admin/options', 'icon' => 'fa-cog'], - ['title' => 'general.import-v2', 'link' => 'setup/migrations', 'icon' => 'fa-undo'], ['title' => 'general.check-update', 'link' => 'admin/update', 'icon' => 'fa-arrow-up'] ); diff --git a/config/update.php b/config/update.php deleted file mode 100644 index 9a2c5856..00000000 --- a/config/update.php +++ /dev/null @@ -1,27 +0,0 @@ - [ - 'name' => 'LizCat', - 'update_url' => 'http://cdn.prinzeugen.net/update.json', - 'description' => '感谢 NyaVM 提供的 Anycast CDN,国内外主机都可获得不错的速度。' - ], - 'little_service' => [ - 'name' => 'LittleService-COS', - 'update_url' => 'http://cos.littleservice.cn/bs/update.json', - 'description' => '由 Little_Qiu 及其 团队 维护的非官方更新源,国内主机使用可能会获得一定的加速 Buff。不建议海外主机的用户使用。' - ], - 'local' => [ - 'name' => 'LocalHost', - 'update_url' => 'http://127.0.0.1/test/update.json', - 'description' => '本地调试用,请勿选择(炸了别怪我)' - ] -); diff --git a/resources/views/admin/download.tpl b/resources/views/admin/download.tpl deleted file mode 100644 index 02a7ef16..00000000 --- a/resources/views/admin/download.tpl +++ /dev/null @@ -1,67 +0,0 @@ -@extends('admin.master') - -@section('title', trans('general.download-update')) - -@section('content') - - -
- -
-

- {{ trans('general.download-update') }} - Download Updates -

-
- - -
-
-
-

{{ trans('general.download-update') }}

-
-
newVersionAvailable()) { - $zip_path = $updater->downloadUpdate(false); - - if ($zip_path === false) { - exit('

无法下载更新包。

'); - } - - $zip = new ZipArchive(); - $extract_dir = storage_path("update_cache/{$updater->latest_version}"); - $res = $zip->open($zip_path); - - if ($res === true) { - echo "

正在解压更新包

"; - $zip->extractTo($extract_dir); - } else { - exit('

更新包解压缩失败。错误代码:'.$res.'

'); - } - $zip->close(); - - if (Storage::copyDir($extract_dir, base_path()) !== true) { - Storage::removeDir(storage_path('update_cache')); - exit('无法覆盖文件。'); - } else { - echo "

正在覆盖文件

"; - Storage::removeDir(storage_path('update_cache')); - echo "

正在清理

"; - } - echo "

更新完成。

"; - } else { - echo "

无可用更新。

"; - } ?> -
- - -
- -
-
- -@endsection diff --git a/resources/views/setup/migrations/import-v2-both.tpl b/resources/views/setup/migrations/import-v2-both.tpl deleted file mode 100644 index 65e9b40b..00000000 --- a/resources/views/setup/migrations/import-v2-both.tpl +++ /dev/null @@ -1,95 +0,0 @@ -@extends('setup.migrations.master') - -@section('content') - - - -{{-- Step 1: --}} - -@if ($step == '1') -

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

- -

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

-

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

-

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

- -
- -
- - - - - - - - - - - - - - - -
- -

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

-
- -

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

-
私密材质 - -
- - @if (Session::has('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 deleted file mode 100644 index cfea8a73..00000000 --- a/resources/views/setup/migrations/import-v2-textures.tpl +++ /dev/null @@ -1,105 +0,0 @@ -@extends('setup.migrations.master') - -@section('content') - - - -{{-- Step 1: --}} - -@if ($step == '1') -

导入皮肤库

- -

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

-

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

- -
- - - - - - - - - - - - - - - - - - - - -
- -

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

-
- -

- - 导入后的材质在皮肤库中显示的上传者,填写 0 会显示为「不存在的用户」 - -

-
- -

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

-
私密材质 - -
- - @if (Session::has('msg')) - - @endif - -

- -

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

导入成功

- - - -

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

-

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

- -

-导入完成 -

- -@endif - -@endsection diff --git a/resources/views/setup/migrations/import-v2-users.tpl b/resources/views/setup/migrations/import-v2-users.tpl deleted file mode 100644 index 0da86a2e..00000000 --- a/resources/views/setup/migrations/import-v2-users.tpl +++ /dev/null @@ -1,72 +0,0 @@ -@extends('setup.migrations.master') - -@section('content') - - - -{{-- Step 1: --}} - -@if ($step == '1') -

导入用户数据

- -

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

-

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

-

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

- -
- -
- - - - - -
- -

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

-
- - @if (Session::has('msg')) - - @endif - -

- -

-
-@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 deleted file mode 100644 index 83837734..00000000 --- a/resources/views/setup/migrations/index.tpl +++ /dev/null @@ -1,18 +0,0 @@ -@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 deleted file mode 100644 index aa2f6716..00000000 --- a/resources/views/setup/migrations/master.tpl +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - Blessing Skin Server 数据迁移 - - - - - - - - - -@yield('content') - - - -