diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 7653c410..027b7769 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -10,6 +10,7 @@ use Illuminate\Foundation\Validation\ValidationException; use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; class Handler extends ExceptionHandler { @@ -22,7 +23,8 @@ class Handler extends ExceptionHandler HttpException::class, ModelNotFoundException::class, ValidationException::class, - PrettyPageException::class + PrettyPageException::class, + MethodNotAllowedHttpException::class, ]; /** @@ -47,23 +49,30 @@ class Handler extends ExceptionHandler */ public function render($request, Exception $e) { + if ($e instanceof HttpException) { + // call i18n middleware manually since http exceptions won't be sent through it + (new Internationalization)->handle($request, function(){}); + } + if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } + if ($e instanceof MethodNotAllowedHttpException) { + abort(403, 'Method not allowed.'); + } + if ($e instanceof PrettyPageException && PHP_SAPI != "cli") { return $e->showErrorPage(); } - if ($e instanceof HttpException) { - // call i18n middleware manually since http exceptions won't be sent through it - (new Internationalization)->handle($request, function(){}); - } - if ($e instanceof ValidationException) { + // quick fix for returning 422 + // @see https://prinzeugen.net/custom-responses-of-laravel-validations/ return $e->getResponse()->setStatusCode(200); } + // render exceptions with whoops if (config('app.debug')) { foreach ($this->dontReport as $type) { if ($e instanceof $type) { diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php new file mode 100644 index 00000000..bef82a8b --- /dev/null +++ b/app/Http/Controllers/SetupController.php @@ -0,0 +1,152 @@ +checkTablesExist()) { + return view('setup.locked'); + } else { + $config = config('database.connections.mysql'); + + return view('setup.wizard.welcome')->with('server', "{$config['username']}@{$config['host']}"); + } + } + + public function update() + { + if (version_compare(config('app.version'), option('version', ''), '<=')) { + // no updates available + return view('setup.locked'); + } + + return view('setup.updates.welcome'); + } + + public function doUpdate() + { + $resource = opendir(database_path('update_scripts')); + $update_script_exist = false; + + $tips = []; + + while($filename = @readdir($resource)) { + if ($filename != "." && $filename != "..") { + preg_match('/update-(.*)-to-(.*).php/', $filename, $matches); + + // skip if the file is not valid or expired + if (!isset($matches[2]) || + version_compare($matches[2], option('version'), '<')) { + continue; + } + + $result = require database_path('update_scripts')."/$filename"; + + if (is_array($result)) { + // push tip to array + foreach ($result as $tip) { + $tips[] = $tip; + } + } + + $update_script_exist = true; + } + } + closedir($resource); + + foreach (config('options') as $key => $value) { + if (!Option::has($key)) + Option::set($key, $value); + } + + if (!$update_script_exist) { + // if update script is not given + Option::set('version', config('app.version')); + } + + return view('setup.updates.success', ['tips' => $tips]); + } + + public function info() + { + return view('setup.wizard.info'); + } + + public function finish(Request $request) + { + $this->validate($request, [ + 'email' => 'required|email', + 'password' => 'required|min:6|max:16|confirmed', + 'site_name' => 'required' + ]); + + // create tables + Artisan::call('migrate'); + + Option::set('site_name', $request->input('site_name')); + Option::set('site_url', url('/')); + + // register super admin + $user = User::register( + $request->input('email'), + $request->input('password'), + function ($user) + { + $user->ip = get_real_ip(); + $user->score = option('user_initial_score'); + $user->register_at = Utils::getTimeFormatted(); + $user->last_sign_at = Utils::getTimeFormatted(time() - 86400); + $user->permission = User::SUPER_ADMIN; + }); + + $this->createDirectories(); + + return view('setup.wizard.finish')->with([ + 'email' => $request->input('email'), + 'password' => $request->input('password') + ]); + } + + protected function createDirectories() + { + if (!is_dir(BASE_DIR.'/storage/textures/')) { + if (!mkdir(BASE_DIR.'/storage/textures/')) + throw new App\Exceptions\PrettyPageException('/storage/textures 文件夹创建失败,请检查目录权限是否正确,或者手动放置一个。', -1); + } + } + + protected function checkTablesExist() + { + $tables = ['users', 'closets', 'players', 'textures', 'options']; + + foreach ($tables as $table_name) { + // prefix will be added automatically + if (!Schema::hasTable($table_name)) { + return false; + } + } + + return true; + } + + /** + * {@inheritdoc} + */ + protected function formatValidationErrors(Validator $validator) + { + return $validator->errors()->all(); + } + +} diff --git a/app/Http/Routes/web.php b/app/Http/Routes/web.php index fa94df8c..31f487a2 100644 --- a/app/Http/Routes/web.php +++ b/app/Http/Routes/web.php @@ -16,12 +16,25 @@ Route::get('/index.php', 'HomeController@index'); Route::get('/locale/{lang}', 'HomeController@locale'); +/** + * Setup Wizard + */ +Route::group(['prefix' => 'setup'], function () +{ + Route::get ('/', 'SetupController@welcome'); + Route::get ('/info', 'SetupController@info'); + Route::post('/finish', 'SetupController@finish'); + + Route::get ('/update', 'SetupController@update'); + Route::post('/update', 'SetupController@doUpdate'); +}); + /** * Auth */ -Route::group(['prefix' => 'auth'], function() +Route::group(['prefix' => 'auth'], function () { - Route::group(['middleware' => 'guest'], function() + Route::group(['middleware' => 'guest'], function () { Route::get ('/login', 'AuthController@login'); Route::get ('/register', 'AuthController@register'); @@ -42,7 +55,7 @@ Route::group(['prefix' => 'auth'], function() /** * User Center */ -Route::group(['middleware' => 'auth', 'prefix' => 'user'], function() +Route::group(['middleware' => 'auth', 'prefix' => 'user'], function () { Route::any ('', 'UserController@index'); Route::any ('/checkin', 'UserController@checkIn'); @@ -73,14 +86,14 @@ Route::group(['middleware' => 'auth', 'prefix' => 'user'], function() /** * Skin Library */ -Route::group(['prefix' => 'skinlib'], function() +Route::group(['prefix' => 'skinlib'], function () { Route::get ('', 'SkinlibController@index'); Route::any ('/info/{tid}', 'SkinlibController@info'); Route::any ('/show', 'SkinlibController@show'); Route::any ('/search', 'SkinlibController@search'); - Route::group(['middleware' => 'auth'], function() + Route::group(['middleware' => 'auth'], function () { Route::get ('/upload', 'SkinlibController@upload'); Route::post('/upload', 'SkinlibController@handleUpload'); @@ -94,7 +107,7 @@ Route::group(['prefix' => 'skinlib'], function() /** * Admin Panel */ -Route::group(['middleware' => 'admin', 'prefix' => 'admin'], function() +Route::group(['middleware' => 'admin', 'prefix' => 'admin'], function () { Route::get('/', 'AdminController@index'); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index e559f1e8..3b7e711d 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -33,11 +33,8 @@ class AppServiceProvider extends ServiceProvider */ public function register() { - $this->app->singleton('database', \App\Services\Database\Database::class); - $this->app->singleton('option', \App\Services\Repositories\OptionRepository::class); // register default cipher $this->app->singleton('cipher', "App\Services\Cipher\\".config('secure.cipher')); - $this->app->singleton('users', \App\Services\Repositories\UserRepository::class); } } diff --git a/app/Providers/BootServiceProvider.php b/app/Providers/BootServiceProvider.php index 0afba6d4..e21ce9b7 100644 --- a/app/Providers/BootServiceProvider.php +++ b/app/Providers/BootServiceProvider.php @@ -3,6 +3,8 @@ namespace App\Providers; use View; +use Schema; +use Illuminate\Http\Request; use Illuminate\Support\ServiceProvider; use App\Exceptions\PrettyPageException; @@ -13,64 +15,73 @@ class BootServiceProvider extends ServiceProvider * * @return void */ - public function boot() + public function boot(Request $request) { View::addExtension('tpl', 'blade'); $this->checkFileExists(); $this->checkDbConfig(); - $this->checkInstallation(); + + if (!$request->is('setup') && !$request->is('setup/*') && PHP_SAPI != "cli") { + $this->checkInstallation(); + } } protected function checkFileExists() { if (!file_exists(BASE_DIR."/.env")) { - throw new PrettyPageException('.env 文件不存在', -1); + throw new PrettyPageException(trans('setup.file.no-dot-env'), -1); } } protected function checkDbConfig() { + $config = config('database.connections.mysql'); + // use error control to hide shitty connect warnings @$conn = new \mysqli( - config('database.connections.mysql.host'), - config('database.connections.mysql.username'), - config('database.connections.mysql.password'), - config('database.connections.mysql.database'), - config('database.connections.mysql.port') + $config['host'], + $config['username'], + $config['password'], + $config['database'], + $config['port'] ); if ($conn->connect_error) - throw new PrettyPageException("无法连接至 MySQL 服务器,请检查你的配置:".$conn->connect_error, $conn->connect_errno); + throw new PrettyPageException( + trans('setup.database.connection-error', ['msg' => $conn->connect_error]), + $conn->connect_errno + ); return true; } protected function checkInstallation() { - if (!$this->checkTableExist()) { - return redirect('/setup/index.php')->send(); + // redirect to setup wizard + if (!$this->checkTablesExist()) { + return redirect('/setup')->send(); } if (!is_dir(BASE_DIR.'/storage/textures/')) { if (!mkdir(BASE_DIR.'/storage/textures/')) - throw new PrettyPageException('textures 文件夹创建失败,请确认目录权限是否正确,或者手动放置一个。', -1); + throw new PrettyPageException(trans('setup.file.permission-error'), -1); } - if (config('app.version') != \Option::get('version', '')) { - return redirect('/setup/update.php')->send(); + if (version_compare(config('app.version'), option('version', ''), '>')) { + return redirect('/setup/update')->send(); } return true; } - public static function checkTableExist() + public static function checkTablesExist() { $tables = ['users', 'closets', 'players', 'textures', 'options']; foreach ($tables as $table_name) { // prefix will be added automatically - if (!\Schema::hasTable($table_name)) { + if (!Schema::hasTable($table_name)) { return false; } } @@ -85,6 +96,7 @@ class BootServiceProvider extends ServiceProvider */ public function register() { - // + $this->app->singleton('database', \App\Services\Database\Database::class); + $this->app->singleton('options', \App\Services\Repositories\OptionRepository::class); } } diff --git a/app/Services/Database/Database.php b/app/Services/Database/Database.php index 086b94e5..e84b0298 100644 --- a/app/Services/Database/Database.php +++ b/app/Services/Database/Database.php @@ -49,7 +49,7 @@ class Database ); if ($this->connection->connect_error) - throw new \InvalidArgumentException("Could not connect to MySQL database. Check your configuration:". + throw new \InvalidArgumentException("Could not connect to MySQL database. ". $this->connection->connect_error, $this->connection->connect_errno); $this->connection->query("SET names 'utf8'"); diff --git a/app/Services/Facades/Option.php b/app/Services/Facades/Option.php index 51d7267c..43f9a8e7 100644 --- a/app/Services/Facades/Option.php +++ b/app/Services/Facades/Option.php @@ -14,7 +14,7 @@ class Option extends Facade */ protected static function getFacadeAccessor() { - return 'option'; + return 'options'; } public static function form($id, $title, $callback) diff --git a/app/Services/Repositories/OptionRepository.php b/app/Services/Repositories/OptionRepository.php index 1a006d4d..190dd954 100644 --- a/app/Services/Repositories/OptionRepository.php +++ b/app/Services/Repositories/OptionRepository.php @@ -8,13 +8,6 @@ use Illuminate\Database\QueryException; class OptionRepository extends Repository { - /** - * All of the option items that is modified. - * - * @var array - */ - protected $items_modified = []; - /** * Create a new option repository. * @@ -76,7 +69,7 @@ class OptionRepository extends Repository * * @return void */ - protected function save() + public function save() { $this->items_modified = array_unique($this->items_modified); diff --git a/app/Services/Repositories/Repository.php b/app/Services/Repositories/Repository.php index 46d41b15..b1bd7f1a 100644 --- a/app/Services/Repositories/Repository.php +++ b/app/Services/Repositories/Repository.php @@ -14,6 +14,13 @@ class Repository implements ArrayAccess // Illuminate\Contracts\Cache\Repository */ protected $items; + /** + * All of the option items that is modified. + * + * @var array + */ + protected $items_modified = []; + /** * Determine if an item exists in the repository. * diff --git a/app/helpers.php b/app/helpers.php index 9733ec2b..5a00f2ce 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -179,9 +179,22 @@ if (! function_exists('bs_nickname')) { if (! function_exists('option')) { - function option($key) + function option($key = null, $default = null) { - return Option::get($key); + $options = app('options'); + + if (is_null($key)) { + return $options; + } + + if (is_array($key)) { + foreach ($key as $innerKey => $innerValue) { + $options->set($innerKey, $innerValue); + } + return $options->save(); + } + + return $options->get($key); } } diff --git a/composer.json b/composer.json index 5023d3ea..78ded422 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ }, "autoload": { "classmap": [ - "app/Models" + "app/Models", + "database" ], "psr-4": { "App\\": "app/" diff --git a/setup/update_scripts/update-3.0.1-to-3.0.2.php b/database/update_scripts/update-3.0.1-to-3.0.2.php similarity index 100% rename from setup/update_scripts/update-3.0.1-to-3.0.2.php rename to database/update_scripts/update-3.0.1-to-3.0.2.php diff --git a/setup/update_scripts/update-3.0.3-to-3.0.4.php b/database/update_scripts/update-3.0.3-to-3.0.4.php similarity index 100% rename from setup/update_scripts/update-3.0.3-to-3.0.4.php rename to database/update_scripts/update-3.0.3-to-3.0.4.php diff --git a/setup/update_scripts/update-3.1-to-3.1.1.php b/database/update_scripts/update-3.1-to-3.1.1.php similarity index 100% rename from setup/update_scripts/update-3.1-to-3.1.1.php rename to database/update_scripts/update-3.1-to-3.1.1.php diff --git a/database/update_scripts/update-3.1.1-to-3.2.php b/database/update_scripts/update-3.1.1-to-3.2.php new file mode 100644 index 00000000..8c476d99 --- /dev/null +++ b/database/update_scripts/update-3.1.1-to-3.2.php @@ -0,0 +1,13 @@ +已安装过
Blessing Skin Server 看起来已经安装妥当。如果想重新安装,请删除数据库中的旧数据表,或者换一个数据表前缀。
@endsection diff --git a/resources/views/setup/updates/success.tpl b/resources/views/setup/updates/success.tpl index f2544754..d290ca65 100644 --- a/resources/views/setup/updates/success.tpl +++ b/resources/views/setup/updates/success.tpl @@ -16,6 +16,6 @@ @endif @endsection diff --git a/resources/views/setup/updates/welcome.tpl b/resources/views/setup/updates/welcome.tpl index ad98a266..58645331 100644 --- a/resources/views/setup/updates/welcome.tpl +++ b/resources/views/setup/updates/welcome.tpl @@ -6,7 +6,9 @@欢迎升级至 Blessing Skin Server {{ config('app.version') }}!
我们需要升级您的数据库,点击下一步以继续。
-- 下一步 -
+ @endsection diff --git a/resources/views/setup/steps/3.tpl b/resources/views/setup/wizard/finish.tpl similarity index 93% rename from resources/views/setup/steps/3.tpl rename to resources/views/setup/wizard/finish.tpl index e019325d..920e2279 100644 --- a/resources/views/setup/steps/3.tpl +++ b/resources/views/setup/wizard/finish.tpl @@ -1,4 +1,4 @@ -@extends('setup.master') +@extends('setup.wizard.master') @section('content')您需要填写一些基本信息。无需担心填错,这些信息以后可以再次修改。
- @endsection diff --git a/resources/views/setup/master.tpl b/resources/views/setup/wizard/master.tpl similarity index 100% rename from resources/views/setup/master.tpl rename to resources/views/setup/wizard/master.tpl diff --git a/resources/views/setup/steps/1.tpl b/resources/views/setup/wizard/welcome.tpl similarity index 67% rename from resources/views/setup/steps/1.tpl rename to resources/views/setup/wizard/welcome.tpl index 65cefb6d..1ef07f33 100644 --- a/resources/views/setup/steps/1.tpl +++ b/resources/views/setup/wizard/welcome.tpl @@ -1,4 +1,4 @@ -@extends('setup.master') +@extends('setup.wizard.master') @section('content')成功连接至 MySQL 服务器 {{ $server }},点击下一步以开始安装。
@endsection diff --git a/setup/includes/bootstrap.php b/setup/includes/bootstrap.php deleted file mode 100644 index caa28c7b..00000000 --- a/setup/includes/bootstrap.php +++ /dev/null @@ -1,113 +0,0 @@ -load(); -} else { - exit('错误:.env 配置文件不存在'); -} - -if (false === menv('APP_KEY', false)) { - exit('错误:.env 已过期,请重新复制一份 .env.example 并修改配置'); -} - -// Register Error Hanlders -$whoops = new \Whoops\Run; -$handler = new \Whoops\Handler\PrettyPageHandler; -$whoops->pushHandler($handler); -$whoops->register(); - -// Instantiate Application -$app = new Illuminate\Foundation\Application(BASE_DIR); - -// Set Container for Facades -Illuminate\Support\Facades\Facade::setFacadeApplication($app); - -// Load Aliases -$config = require BASE_DIR.'/config/app.php'; - -foreach ($config['aliases'] as $facade => $class) { - class_alias($class, $facade); -} - -// Register Basic Service Providers manually -(new Illuminate\View\ViewServiceProvider($app))->register(); -(new Illuminate\Foundation\Bootstrap\LoadConfiguration)->bootstrap($app); -(new Illuminate\Database\DatabaseServiceProvider($app))->register(); -(new Illuminate\Filesystem\FilesystemServiceProvider($app))->register(); -(new Illuminate\Session\SessionServiceProvider($app))->register(); -(new Illuminate\Encryption\EncryptionServiceProvider($app))->register(); -(new Devitek\Core\Translation\TranslationServiceProvider($app))->register(); - -$request = Symfony\Component\HttpFoundation\Request::createFromGlobals(); - -$request = (new Illuminate\Http\Request)->duplicate( - $request->query->all(), $request->request->all(), $request->attributes->all(), - // quick fix: replace request URI with empty string - $request->cookies->all(), $request->files->all(), array_replace($request->server->all(), ['REQUEST_URI' => '']) -); - -// Enable URL generator -$app->bind('url', function ($app) { - $routes = $app['router']->getRoutes(); - $app->instance('routes', $routes); - - $url = new Illuminate\Routing\UrlGenerator( - $routes, $app['request'] - ); - - return $url; -}); - -$app->instance('request', $request); - -$app->singleton('database', App\Services\Database\Database::class); -$app->singleton('option', App\Services\Repositories\OptionRepository::class); -$app->singleton('cipher', "App\Services\Cipher\\".config('secure.cipher')); -$app->singleton('users', App\Services\Repositories\UserRepository::class); - -View::addExtension('tpl', 'blade'); - -$db_config = get_db_config(); - -// Check Database Config -check_db_config($db_config); - -// Boot Eloquent ORM -$capsule = new Illuminate\Database\Capsule\Manager; -$capsule->addConnection($db_config); -$capsule->setAsGlobal(); -$capsule->bootEloquent(); - -// Start Session -session_start(); -// start laravel session -$encrypter = $app->make('Illuminate\Contracts\Encryption\Encrypter'); -$session = $app->make('session')->driver(); - -if (isset($_COOKIE['BS_SESSION'])) { - $session->setId($encrypter->decrypt($_COOKIE['BS_SESSION'])); -} - -$session->start(); diff --git a/setup/includes/helpers.php b/setup/includes/helpers.php deleted file mode 100644 index 469a84df..00000000 --- a/setup/includes/helpers.php +++ /dev/null @@ -1,88 +0,0 @@ -bound('session')) { - // Session::put('msg', $msg); - // Session::save(); - // } else { - $_SESSION['msg'] = $msg; - // } - // } - - if (!headers_sent()) { - header('Location: '.$url); - } else { - echo ""; - } - exit; -} - -/** - * Check POST values in a simple way - * - * @param array $keys - * @return void - */ -function check_post(Array $keys) { - foreach ($keys as $key) { - if (!isset($_POST[$key])) { - return false; - } - } - return true; -} - -function check_password($password) -{ - if (strlen($password) > 16 || strlen($password) < 8) { - return false; - } - return true; -} - -function get_db_config() -{ - $config = require BASE_DIR.'/config/database.php'; - - return $config['connections']['mysql']; -} - -function check_db_config($config) -{ - @$conn = new mysqli($config['host'], $config['username'], $config['password'], $config['database'], $config['port']); - - if ($conn->connect_error) { - throw new App\Exceptions\PrettyPageException("无法连接至 MySQL 服务器,请检查你的配置:".$conn->connect_error, $conn->connect_errno, true); - } -} - -function migrate($migration) -{ - if (strpos($migration, 'import') !== false) { - $filename = BASE_DIR."/setup/migrations/".str_replace('-', '_', $migration).".php"; - if (file_exists($filename)) { - return require $filename; - } - } - throw new InvalidArgumentException('Non-existent migration'); -} diff --git a/setup/includes/tables.php b/setup/includes/tables.php deleted file mode 100644 index df4e920f..00000000 --- a/setup/includes/tables.php +++ /dev/null @@ -1,54 +0,0 @@ -increments('uid'); - $table->string('email', 100); - $table->string('nickname', 50)->default(''); - $table->integer('score'); - $table->integer('avatar')->default('0'); - $table->string('password', 255); - $table->string('ip', 32); - $table->integer('permission')->default('0'); - $table->dateTime('last_sign_at'); - $table->dateTime('register_at'); -}); - -Schema::create('closets', function($table) { - $table->increments('uid'); - $table->longText('textures'); -}); - -Schema::create('players', function($table) { - $table->increments('pid'); - $table->integer('uid'); - $table->string('player_name', 50); - $table->string('preference', 10); - $table->integer('tid_steve')->default('0'); - $table->integer('tid_alex')->default('0'); - $table->integer('tid_cape')->default('0'); - $table->dateTime('last_modified'); -}); - -Schema::create('textures', function($table) { - $table->increments('tid'); - $table->string('name', 50); - $table->string('type', 10); - $table->integer('likes'); - $table->string('hash', 64); - $table->integer('size'); - $table->integer('uploader'); - $table->integer('public'); - $table->dateTime('upload_at'); -}); - -Schema::create('options', function($table) { - $table->increments('id'); - $table->string('option_name', 50); - $table->longText('option_value'); -}); diff --git a/setup/index.php b/setup/index.php deleted file mode 100644 index 243557f9..00000000 --- a/setup/index.php +++ /dev/null @@ -1,90 +0,0 @@ -with('server', $server); - break; - - case 2: - echo View::make('setup.steps.2'); - break; - - case 3: - // check post - if (check_post(['email', 'password', 'confirm-pwd'], true)) - { - if ($_POST['password'] != $_POST['confirm-pwd']) - redirect_to('index.php?step=2', '确认密码不一致'); - - $email = $_POST['email']; - $password = $_POST['password']; - $sitename = isset($_POST['sitename']) ? $_POST['sitename'] : "Blessing Skin Server"; - - if (validate($email, 'email')) { - if (!check_password($password)) { - redirect_to('index.php?step=2', '无效的密码。密码长度应该大于 8 并小于 16。'); - - } else if (e($password) != $password) { - redirect_to('index.php?step=2', '无效的密码。密码中包含了奇怪的字符。'); - } - } else { - redirect_to('index.php?step=2', '邮箱格式不正确。'); - } - } - else { - redirect_to('index.php?step=2', '表单信息不完整。'); - } - - // create tables - require BASE_DIR."/setup/includes/tables.php"; - - // import options - $options = require BASE_DIR."/config/options.php"; - $options['site_name'] = $_POST['sitename']; - $options['site_url'] = url('/'); - $options['version'] = config('app.version'); - $options['announcement'] = str_replace('{version}', $options['version'], $options['announcement']); - - foreach ($options as $key => $value) { - Option::set($key, $value); - } - - // register super admin - $user = App\Models\User::register($_POST['email'], $_POST['password'], function($user) { - $user->ip = get_real_ip(); - $user->score = option('user_initial_score'); - $user->register_at = Utils::getTimeFormatted(); - $user->last_sign_at = Utils::getTimeFormatted(time() - 86400); - $user->permission = App\Models\User::SUPER_ADMIN; - }); - - if (!is_dir(BASE_DIR.'/storage/textures/')) { - if (!mkdir(BASE_DIR.'/storage/textures/')) - throw new App\Exceptions\PrettyPageException('/storage/textures 文件夹创建失败,请检查目录权限是否正确,或者手动放置一个。', -1); - } - - echo View::make('setup.steps.3')->with('email', $_POST['email'])->with('password', $_POST['password']); - - break; - - default: - throw new App\Exceptions\PrettyPageException('非法参数', 1, true); - break; -} diff --git a/setup/migrations/import_v2_both.php b/setup/migrations/import_v2_both.php deleted file mode 100644 index b06cde8b..00000000 --- a/setup/migrations/import_v2_both.php +++ /dev/null @@ -1,143 +0,0 @@ -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 (Player::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 Player; - - $p->uid = $user->uid; - $p->player_name = $row['username']; - $p->preference = $row['preference']; - $p->last_modified = $row['last_modified'] ? : Utils::getTimeFormatted(); - - $c = new Closet($user->uid); - - $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->setTextures(json_encode($items)); - - $user_imported++; - // echo $row['username']." saved.