misc_pterodactyl-panel/app/Http/Controllers/Api/Application/Servers/ServerManagementController.php

75 lines
2.1 KiB
PHP
Raw Normal View History

2018-01-20 19:48:02 +00:00
<?php
namespace Pterodactyl\Http\Controllers\Api\Application\Servers;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server;
use Pterodactyl\Services\Servers\SuspensionService;
use Pterodactyl\Services\Servers\ReinstallServerService;
use Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class ServerManagementController extends ApplicationApiController
{
/**
* @var \Pterodactyl\Services\Servers\ReinstallServerService
*/
private $reinstallServerService;
/**
* @var \Pterodactyl\Services\Servers\SuspensionService
*/
private $suspensionService;
/**
* SuspensionController constructor.
*/
public function __construct(
ReinstallServerService $reinstallServerService,
SuspensionService $suspensionService
) {
2018-01-20 19:48:02 +00:00
parent::__construct();
$this->reinstallServerService = $reinstallServerService;
$this->suspensionService = $suspensionService;
}
/**
* Suspend a server on the Panel.
*
2019-12-22 21:45:40 +00:00
* @throws \Throwable
2018-01-20 19:48:02 +00:00
*/
public function suspend(ServerWriteRequest $request, Server $server): Response
2018-01-20 19:48:02 +00:00
{
$this->suspensionService->toggle($server, SuspensionService::ACTION_SUSPEND);
2018-01-20 19:48:02 +00:00
return $this->returnNoContent();
}
/**
* Unsuspend a server on the Panel.
*
2019-12-22 21:45:40 +00:00
* @throws \Throwable
2018-01-20 19:48:02 +00:00
*/
public function unsuspend(ServerWriteRequest $request, Server $server): Response
2018-01-20 19:48:02 +00:00
{
$this->suspensionService->toggle($server, SuspensionService::ACTION_UNSUSPEND);
2018-01-20 19:48:02 +00:00
return $this->returnNoContent();
}
/**
* Mark a server as needing to be reinstalled.
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function reinstall(ServerWriteRequest $request, Server $server): Response
2018-01-20 19:48:02 +00:00
{
2020-10-06 04:54:29 +00:00
$this->reinstallServerService->handle($server);
2018-01-20 19:48:02 +00:00
return $this->returnNoContent();
}
}