2017-09-20 03:10:14 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-09-20 03:10:14 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-09-20 03:10:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Console\Commands\Server;
|
|
|
|
|
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use GuzzleHttp\Exception\RequestException;
|
2019-09-05 03:19:01 +00:00
|
|
|
use Pterodactyl\Repositories\Wings\WingsServerRepository;
|
2017-09-20 03:10:14 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
2017-10-06 04:09:43 +00:00
|
|
|
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
2017-09-20 03:10:14 +00:00
|
|
|
|
|
|
|
class RebuildServerCommand extends Command
|
|
|
|
{
|
2017-10-06 04:09:43 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
|
|
|
|
*/
|
|
|
|
protected $configurationStructureService;
|
|
|
|
|
2017-09-20 03:10:14 +00:00
|
|
|
/**
|
2019-09-05 03:19:01 +00:00
|
|
|
* @var \Pterodactyl\Repositories\Wings\WingsServerRepository
|
2017-09-20 03:10:14 +00:00
|
|
|
*/
|
|
|
|
protected $daemonRepository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Rebuild a single server, all servers on a node, or all servers on the panel.';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'p:server:rebuild
|
|
|
|
{server? : The ID of the server to rebuild.}
|
|
|
|
{--node= : ID of the node to rebuild all servers on. Ignored if server is passed.}';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RebuildServerCommand constructor.
|
|
|
|
*
|
2019-09-05 03:19:01 +00:00
|
|
|
* @param \Pterodactyl\Repositories\Wings\WingsServerRepository $daemonRepository
|
|
|
|
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
2017-09-20 03:10:14 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2019-09-05 03:19:01 +00:00
|
|
|
WingsServerRepository $daemonRepository,
|
2017-10-06 04:09:43 +00:00
|
|
|
ServerConfigurationStructureService $configurationStructureService,
|
2017-09-20 03:10:14 +00:00
|
|
|
ServerRepositoryInterface $repository
|
|
|
|
) {
|
|
|
|
parent::__construct();
|
|
|
|
|
2017-10-06 04:09:43 +00:00
|
|
|
$this->configurationStructureService = $configurationStructureService;
|
2017-09-20 03:10:14 +00:00
|
|
|
$this->daemonRepository = $daemonRepository;
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle command execution.
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$servers = $this->getServersToProcess();
|
|
|
|
$bar = $this->output->createProgressBar(count($servers));
|
|
|
|
|
2017-09-20 03:15:52 +00:00
|
|
|
$servers->each(function ($server) use ($bar) {
|
2017-09-20 03:10:14 +00:00
|
|
|
$bar->clear();
|
2017-10-06 04:09:43 +00:00
|
|
|
$json = array_merge($this->configurationStructureService->handle($server), ['rebuild' => true]);
|
2017-09-20 03:10:14 +00:00
|
|
|
|
|
|
|
try {
|
2018-01-06 00:27:47 +00:00
|
|
|
$this->daemonRepository->setServer($server)->update($json);
|
2017-09-20 03:10:14 +00:00
|
|
|
} catch (RequestException $exception) {
|
|
|
|
$this->output->error(trans('command/messages.server.rebuild_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 rebuilt.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Collection
|
|
|
|
*/
|
|
|
|
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->getDataForRebuild($this->argument('server'), $this->option('node'));
|
|
|
|
}
|
|
|
|
}
|