2018-12-03 07:39:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Console\Commands\Server;
|
|
|
|
|
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use GuzzleHttp\Exception\RequestException;
|
2020-04-11 22:35:32 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
2019-09-06 03:33:27 +00:00
|
|
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
2018-12-03 07:39:40 +00:00
|
|
|
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
|
|
|
|
|
|
|
class BulkReinstallActionCommand extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
|
|
|
|
*/
|
2020-04-11 22:35:32 +00:00
|
|
|
private $configurationStructureService;
|
2018-12-03 07:39:40 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-11 22:35:32 +00:00
|
|
|
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
2018-12-03 07:39:40 +00:00
|
|
|
*/
|
2020-04-11 22:35:32 +00:00
|
|
|
private $daemonRepository;
|
2018-12-03 07:39:40 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-11 22:35:32 +00:00
|
|
|
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
2018-12-03 07:39:40 +00:00
|
|
|
*/
|
2020-04-11 22:35:32 +00:00
|
|
|
private $repository;
|
2018-12-03 07:39:40 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-11 22:35:32 +00:00
|
|
|
* @var string
|
2018-12-03 07:39:40 +00:00
|
|
|
*/
|
2020-04-11 22:35:32 +00:00
|
|
|
protected $description = 'Reinstall a single server, all servers on a node, or all servers on the panel.';
|
2018-12-03 07:39:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'p:server:reinstall
|
|
|
|
{server? : The ID of the server to reinstall.}
|
|
|
|
{--node= : ID of the node to reinstall all servers on. Ignored if server is passed.}';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BulkReinstallActionCommand constructor.
|
|
|
|
*
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonRepository
|
2019-09-05 03:19:01 +00:00
|
|
|
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
|
2020-04-11 22:35:32 +00:00
|
|
|
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
|
2018-12-03 07:39:40 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2019-09-06 03:33:27 +00:00
|
|
|
DaemonServerRepository $daemonRepository,
|
2018-12-03 07:39:40 +00:00
|
|
|
ServerConfigurationStructureService $configurationStructureService,
|
2020-04-11 22:35:32 +00:00
|
|
|
ServerRepository $repository
|
2018-12-03 07:39:40 +00:00
|
|
|
) {
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->configurationStructureService = $configurationStructureService;
|
|
|
|
$this->daemonRepository = $daemonRepository;
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle command execution.
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2018-12-03 07:42:35 +00:00
|
|
|
$servers = $this->getServersToProcess();
|
2018-12-03 07:39:40 +00:00
|
|
|
|
2020-02-08 21:30:49 +00:00
|
|
|
if (! $this->confirm(trans('command/messages.server.reinstall.confirm')) && $this->input->isInteractive()) {
|
2018-12-03 07:39:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$bar = $this->output->createProgressBar(count($servers));
|
|
|
|
|
|
|
|
$servers->each(function ($server) use ($bar) {
|
|
|
|
$bar->clear();
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->daemonRepository->setServer($server)->reinstall();
|
|
|
|
} catch (RequestException $exception) {
|
|
|
|
$this->output->error(trans('command/messages.server.reinstall.failed', [
|
|
|
|
'name' => $server->name,
|
|
|
|
'id' => $server->id,
|
|
|
|
'node' => $server->node->name,
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
|
|
|
$bar->advance();
|
|
|
|
$bar->display();
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->line('');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the servers to be reinstalled.
|
|
|
|
*
|
2020-04-11 22:35:32 +00:00
|
|
|
* @return \Illuminate\Support\Collection
|
2018-12-03 07:39:40 +00:00
|
|
|
*/
|
|
|
|
private function getServersToProcess()
|
|
|
|
{
|
|
|
|
Assert::nullOrIntegerish($this->argument('server'), 'Value passed in server argument must be null or an integer, received %s.');
|
|
|
|
Assert::nullOrIntegerish($this->option('node'), 'Value passed in node option must be null or integer, received %s.');
|
|
|
|
|
|
|
|
return $this->repository->getDataForReinstall($this->argument('server'), $this->option('node'));
|
|
|
|
}
|
|
|
|
}
|