blessing-skin-server/app/Console/Commands/BsInstallCommand.php

53 lines
1.7 KiB
PHP
Raw Normal View History

2019-03-23 16:36:54 +08:00
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
2019-09-06 23:53:47 +08:00
use Illuminate\Filesystem\Filesystem;
2019-03-23 16:36:54 +08:00
2019-08-09 10:13:55 +08:00
class BsInstallCommand extends Command
2019-03-23 16:36:54 +08:00
{
protected $signature = 'bs:install {email} {password} {nickname}';
protected $description = 'Execute installation and create a super administrator.';
2019-09-06 23:53:47 +08:00
public function handle(Filesystem $filesystem)
2019-03-23 16:36:54 +08:00
{
2019-09-06 23:53:47 +08:00
if ($filesystem->exists(storage_path('install.lock'))) {
$this->info('You have installed Blessing Skin Server. Nothing to do.');
2019-04-19 19:36:36 +08:00
return;
}
2019-03-23 16:36:54 +08:00
$this->call('migrate', ['--force' => true]);
2019-12-14 11:10:37 +08:00
if (!$this->getLaravel()->runningUnitTests()) {
2019-08-09 15:36:13 +08:00
// @codeCoverageIgnoreStart
$this->call('key:generate');
$this->call('jwt:secret', ['--no-interaction' => true]);
$this->call('passport:keys', ['--no-interaction' => true]);
// @codeCoverageIgnoreEnd
}
2019-03-23 16:36:54 +08:00
2019-08-09 10:13:55 +08:00
option(['site_url' => url('/')]);
2019-03-23 16:36:54 +08:00
2019-12-14 11:10:37 +08:00
$admin = new User();
2019-03-23 16:36:54 +08:00
$admin->email = $this->argument('email');
$admin->nickname = $this->argument('nickname');
$admin->score = option('user_initial_score');
$admin->avatar = 0;
$admin->password = app('cipher')->hash($this->argument('password'), config('secure.salt'));
$admin->ip = '127.0.0.1';
$admin->permission = User::SUPER_ADMIN;
$admin->register_at = get_datetime_string();
$admin->last_sign_at = get_datetime_string(time() - 86400);
$admin->verified = true;
$admin->save();
2019-09-06 23:53:47 +08:00
$filesystem->put(storage_path('install.lock'), '');
2019-03-23 16:36:54 +08:00
$this->info('Installation completed!');
$this->info('We recommend to modify your "Site URL" option if incorrect.');
}
}