2019-03-23 16:36:54 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
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.';
|
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
2019-03-23 18:57:56 +08:00
|
|
|
if (\App\Http\Controllers\SetupController::checkTablesExist()) {
|
|
|
|
$this->info('You have installed Blessing Skin Server. Nothing to do.');
|
2019-04-19 19:36:36 +08:00
|
|
|
|
2019-03-23 18:57:56 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-23 16:36:54 +08:00
|
|
|
$this->call('migrate', ['--force' => true]);
|
2019-08-09 15:36:13 +08:00
|
|
|
if (! $this->getLaravel()->runningUnitTests()) {
|
|
|
|
// @codeCoverageIgnoreStart
|
|
|
|
$this->call('key:generate');
|
|
|
|
$this->call('salt:random');
|
|
|
|
$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
|
|
|
|
|
|
|
$admin = new User;
|
|
|
|
$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();
|
|
|
|
|
|
|
|
$this->info('Installation completed!');
|
|
|
|
$this->info('We recommend to modify your "Site URL" option if incorrect.');
|
|
|
|
}
|
|
|
|
}
|