diff --git a/app/Console/Commands/Server/RebuildServerCommand.php b/app/Console/Commands/Server/RebuildServerCommand.php deleted file mode 100644 index cf20f9df3..000000000 --- a/app/Console/Commands/Server/RebuildServerCommand.php +++ /dev/null @@ -1,109 +0,0 @@ -. - * - * 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; -use Pterodactyl\Repositories\Wings\DaemonServerRepository; -use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; -use Pterodactyl\Services\Servers\ServerConfigurationStructureService; - -class RebuildServerCommand extends Command -{ - /** - * @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService - */ - protected $configurationStructureService; - - /** - * @var \Pterodactyl\Repositories\Wings\DaemonServerRepository - */ - 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. - * - * @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonRepository - * @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService - * @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository - */ - public function __construct( - DaemonServerRepository $daemonRepository, - ServerConfigurationStructureService $configurationStructureService, - ServerRepositoryInterface $repository - ) { - parent::__construct(); - - $this->configurationStructureService = $configurationStructureService; - $this->daemonRepository = $daemonRepository; - $this->repository = $repository; - } - - /** - * Handle command execution. - */ - public function handle() - { - $servers = $this->getServersToProcess(); - $bar = $this->output->createProgressBar(count($servers)); - - $servers->each(function ($server) use ($bar) { - $bar->clear(); - $json = array_merge($this->configurationStructureService->handle($server), ['rebuild' => true]); - - try { - $this->daemonRepository->setServer($server)->update($json); - } 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')); - } -} diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index 70c3af092..8bcb10390 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -18,7 +18,6 @@ use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Services\Servers\SuspensionService; use Pterodactyl\Services\Servers\ServerDeletionService; use Pterodactyl\Services\Servers\ReinstallServerService; -use Pterodactyl\Services\Servers\ContainerRebuildService; use Pterodactyl\Services\Servers\BuildModificationService; use Pterodactyl\Services\Databases\DatabasePasswordService; use Pterodactyl\Services\Servers\DetailsModificationService; @@ -54,11 +53,6 @@ class ServersController extends Controller */ protected $config; - /** - * @var \Pterodactyl\Services\Servers\ContainerRebuildService - */ - protected $containerRebuildService; - /** * @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface */ @@ -121,7 +115,6 @@ class ServersController extends Controller * @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository * @param \Pterodactyl\Services\Servers\BuildModificationService $buildModificationService * @param \Illuminate\Contracts\Config\Repository $config - * @param \Pterodactyl\Services\Servers\ContainerRebuildService $containerRebuildService * @param \Pterodactyl\Services\Databases\DatabaseManagementService $databaseManagementService * @param \Pterodactyl\Services\Databases\DatabasePasswordService $databasePasswordService * @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $databaseRepository @@ -139,7 +132,6 @@ class ServersController extends Controller AllocationRepositoryInterface $allocationRepository, BuildModificationService $buildModificationService, ConfigRepository $config, - ContainerRebuildService $containerRebuildService, DatabaseManagementService $databaseManagementService, DatabasePasswordService $databasePasswordService, DatabaseRepositoryInterface $databaseRepository, @@ -156,7 +148,6 @@ class ServersController extends Controller $this->allocationRepository = $allocationRepository; $this->buildModificationService = $buildModificationService; $this->config = $config; - $this->containerRebuildService = $containerRebuildService; $this->databaseHostRepository = $databaseHostRepository; $this->databaseManagementService = $databaseManagementService; $this->databasePasswordService = $databasePasswordService; @@ -235,21 +226,6 @@ class ServersController extends Controller return redirect()->route('admin.servers.view.manage', $server->id); } - /** - * Setup a server to have a container rebuild. - * - * @param \Pterodactyl\Models\Server $server - * @return \Illuminate\Http\RedirectResponse - * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException - */ - public function rebuildContainer(Server $server) - { - $this->containerRebuildService->handle($server); - $this->alert->success(trans('admin/server.alerts.rebuild_on_boot'))->flash(); - - return redirect()->route('admin.servers.view.manage', $server->id); - } - /** * Manage the suspension status for a server. * @@ -302,7 +278,7 @@ class ServersController extends Controller * @return \Illuminate\Http\RedirectResponse * * @throws \Pterodactyl\Exceptions\DisplayException - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Throwable */ public function delete(Request $request, Server $server) { @@ -320,7 +296,6 @@ class ServersController extends Controller * @return \Illuminate\Http\RedirectResponse * * @throws \Illuminate\Validation\ValidationException - * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ diff --git a/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php b/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php index d4d0cc14d..c2c3fa1cf 100644 --- a/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php +++ b/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php @@ -63,15 +63,16 @@ class ServerDetailsController extends ApplicationApiController * Update the build details for a specific server. * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigurationRequest $request + * @param \Pterodactyl\Models\Server $server * @return array * * @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ - public function build(UpdateServerBuildConfigurationRequest $request): array + public function build(UpdateServerBuildConfigurationRequest $request, Server $server): array { - $server = $this->buildModificationService->handle($request->getModel(Server::class), $request->validated()); + $server = $this->buildModificationService->handle($server, $request->validated()); return $this->fractal->item($server) ->transformWith($this->getTransformer(ServerTransformer::class)) diff --git a/app/Http/Controllers/Api/Application/Servers/ServerManagementController.php b/app/Http/Controllers/Api/Application/Servers/ServerManagementController.php index 7a48f4bfd..90372f220 100644 --- a/app/Http/Controllers/Api/Application/Servers/ServerManagementController.php +++ b/app/Http/Controllers/Api/Application/Servers/ServerManagementController.php @@ -6,17 +6,11 @@ use Illuminate\Http\Response; use Pterodactyl\Models\Server; use Pterodactyl\Services\Servers\SuspensionService; use Pterodactyl\Services\Servers\ReinstallServerService; -use Pterodactyl\Services\Servers\ContainerRebuildService; use Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest; use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController; class ServerManagementController extends ApplicationApiController { - /** - * @var \Pterodactyl\Services\Servers\ContainerRebuildService - */ - private $rebuildService; - /** * @var \Pterodactyl\Services\Servers\ReinstallServerService */ @@ -30,18 +24,15 @@ class ServerManagementController extends ApplicationApiController /** * SuspensionController constructor. * - * @param \Pterodactyl\Services\Servers\ContainerRebuildService $rebuildService * @param \Pterodactyl\Services\Servers\ReinstallServerService $reinstallServerService * @param \Pterodactyl\Services\Servers\SuspensionService $suspensionService */ public function __construct( - ContainerRebuildService $rebuildService, ReinstallServerService $reinstallServerService, SuspensionService $suspensionService ) { parent::__construct(); - $this->rebuildService = $rebuildService; $this->reinstallServerService = $reinstallServerService; $this->suspensionService = $suspensionService; } @@ -53,9 +44,7 @@ class ServerManagementController extends ApplicationApiController * @param \Pterodactyl\Models\Server $server * @return \Illuminate\Http\Response * - * @throws \Pterodactyl\Exceptions\DisplayException - * @throws \Pterodactyl\Exceptions\Model\DataValidationException - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Throwable */ public function suspend(ServerWriteRequest $request, Server $server): Response { @@ -71,9 +60,7 @@ class ServerManagementController extends ApplicationApiController * @param \Pterodactyl\Models\Server $server * @return \Illuminate\Http\Response * - * @throws \Pterodactyl\Exceptions\DisplayException - * @throws \Pterodactyl\Exceptions\Model\DataValidationException - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Throwable */ public function unsuspend(ServerWriteRequest $request, Server $server): Response { @@ -99,20 +86,4 @@ class ServerManagementController extends ApplicationApiController return $this->returnNoContent(); } - - /** - * Mark a server as needing its container rebuilt the next time it is started. - * - * @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request - * @param \Pterodactyl\Models\Server $server - * @return \Illuminate\Http\Response - * - * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException - */ - public function rebuild(ServerWriteRequest $request, Server $server): Response - { - $this->rebuildService->handle($server); - - return $this->returnNoContent(); - } } diff --git a/app/Services/Servers/BuildModificationService.php b/app/Services/Servers/BuildModificationService.php index 13400ee9a..0e3085dc5 100644 --- a/app/Services/Servers/BuildModificationService.php +++ b/app/Services/Servers/BuildModificationService.php @@ -107,9 +107,10 @@ class BuildModificationService $updateData = $this->structureService->handle($server); try { - $this->daemonServerRepository->setServer($server)->update( - Arr::only($updateData, ['allocations', 'build', 'container']) - ); + $this->daemonServerRepository + ->setServer($server) + ->update(Arr::only($updateData, ['build'])); + $this->connection->commit(); } catch (RequestException $exception) { throw new DaemonConnectionException($exception); diff --git a/app/Services/Servers/ContainerRebuildService.php b/app/Services/Servers/ContainerRebuildService.php deleted file mode 100644 index a5e21c1dc..000000000 --- a/app/Services/Servers/ContainerRebuildService.php +++ /dev/null @@ -1,44 +0,0 @@ -repository = $repository; - } - - /** - * Mark a server for rebuild on next boot cycle. This just makes an empty patch - * request to Wings which will automatically mark the container as requiring a rebuild - * on the next boot as a result. - * - * @param \Pterodactyl\Models\Server $server - * - * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException - */ - public function handle(Server $server) - { - try { - $this->repository->setServer($server)->update([]); - } catch (RequestException $exception) { - throw new DaemonConnectionException($exception); - } - } -} diff --git a/app/Services/Servers/StartupModificationService.php b/app/Services/Servers/StartupModificationService.php index ebcd58923..405fee47b 100644 --- a/app/Services/Servers/StartupModificationService.php +++ b/app/Services/Servers/StartupModificationService.php @@ -2,16 +2,12 @@ namespace Pterodactyl\Services\Servers; -use Illuminate\Support\Arr; use Pterodactyl\Models\User; use Pterodactyl\Models\Server; -use GuzzleHttp\Exception\RequestException; use Illuminate\Database\ConnectionInterface; use Pterodactyl\Traits\Services\HasUserLevels; -use Pterodactyl\Repositories\Wings\DaemonServerRepository; use Pterodactyl\Contracts\Repository\EggRepositoryInterface; use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; -use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException; use Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface; class StartupModificationService @@ -48,11 +44,6 @@ class StartupModificationService */ private $validatorService; - /** - * @var \Pterodactyl\Repositories\Wings\DaemonServerRepository - */ - private $daemonServerRepository; - /** * @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService */ @@ -62,7 +53,6 @@ class StartupModificationService * StartupModificationService constructor. * * @param \Illuminate\Database\ConnectionInterface $connection - * @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $eggRepository * @param \Pterodactyl\Services\Servers\EnvironmentService $environmentService * @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository @@ -72,7 +62,6 @@ class StartupModificationService */ public function __construct( ConnectionInterface $connection, - DaemonServerRepository $daemonServerRepository, EggRepositoryInterface $eggRepository, EnvironmentService $environmentService, ServerRepositoryInterface $repository, @@ -86,7 +75,6 @@ class StartupModificationService $this->repository = $repository; $this->serverVariableRepository = $serverVariableRepository; $this->validatorService = $validatorService; - $this->daemonServerRepository = $daemonServerRepository; $this->structureService = $structureService; } @@ -98,7 +86,6 @@ class StartupModificationService * @return \Pterodactyl\Models\Server * * @throws \Illuminate\Validation\ValidationException - * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ @@ -123,17 +110,6 @@ class StartupModificationService $this->updateAdministrativeSettings($data, $server); } - $updateData = $this->structureService->handle($server); - - try { - $this->daemonServerRepository->setServer($server)->update( - Arr::only($updateData, ['environment', 'invocation', 'service']) - ); - } catch (RequestException $exception) { - $this->connection->rollBack(); - throw new DaemonConnectionException($exception); - } - $this->connection->commit(); return $server; diff --git a/routes/admin.php b/routes/admin.php index 598f46bbb..63aa580d9 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -123,7 +123,6 @@ Route::group(['prefix' => 'servers'], function () { Route::post('/view/{server}/startup', 'ServersController@saveStartup'); Route::post('/view/{server}/database', 'ServersController@newDatabase'); Route::post('/view/{server}/manage/toggle', 'ServersController@toggleInstall')->name('admin.servers.view.manage.toggle'); - Route::post('/view/{server}/manage/rebuild', 'ServersController@rebuildContainer')->name('admin.servers.view.manage.rebuild'); Route::post('/view/{server}/manage/suspension', 'ServersController@manageSuspension')->name('admin.servers.view.manage.suspension'); Route::post('/view/{server}/manage/reinstall', 'ServersController@reinstallServer')->name('admin.servers.view.manage.reinstall'); Route::post('/view/{server}/delete', 'ServersController@delete'); diff --git a/routes/api-application.php b/routes/api-application.php index 9b3b4f073..fe7181667 100644 --- a/routes/api-application.php +++ b/routes/api-application.php @@ -84,7 +84,6 @@ Route::group(['prefix' => '/servers'], function () { Route::post('/{server}/suspend', 'Servers\ServerManagementController@suspend')->name('api.application.servers.suspend'); Route::post('/{server}/unsuspend', 'Servers\ServerManagementController@unsuspend')->name('api.application.servers.unsuspend'); Route::post('/{server}/reinstall', 'Servers\ServerManagementController@reinstall')->name('api.application.servers.reinstall'); - Route::post('/{server}/rebuild', 'Servers\ServerManagementController@rebuild')->name('api.application.servers.rebuild'); Route::delete('/{server}', 'Servers\ServerController@delete'); Route::delete('/{server}/{force?}', 'Servers\ServerController@delete'); diff --git a/tests/Unit/Services/Servers/ContainerRebuildServiceTest.php b/tests/Unit/Services/Servers/ContainerRebuildServiceTest.php deleted file mode 100644 index 5f97fcbde..000000000 --- a/tests/Unit/Services/Servers/ContainerRebuildServiceTest.php +++ /dev/null @@ -1,71 +0,0 @@ -exception = m::mock(RequestException::class)->makePartial(); - $this->repository = m::mock(ServerRepositoryInterface::class); - - $this->server = factory(Server::class)->make(['node_id' => 1]); - $this->service = new ContainerRebuildService($this->repository); - } - - /** - * Test that a server is marked for rebuild. - */ - public function testServerIsMarkedForRebuild() - { - $this->repository->shouldReceive('setServer')->with($this->server)->once()->andReturnSelf() - ->shouldReceive('rebuild')->withNoArgs()->once()->andReturn(new Response); - - $this->service->handle($this->server); - } - - /** - * Test that an exception thrown by guzzle is rendered as a displayable exception. - * - * @expectedException \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException - */ - public function testExceptionThrownByGuzzle() - { - $this->repository->shouldReceive('setServer')->with($this->server)->once()->andThrow($this->exception); - - $this->service->handle($this->server); - } -}