api(remote): check if transfer is present before trying to update status

This commit is contained in:
Matthew Penner 2022-12-01 11:50:28 -07:00
parent 794248d4d7
commit 3c278a8c51
No known key found for this signature in database

View file

@ -11,6 +11,7 @@ use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\Eloquent\ServerRepository; use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Repositories\Wings\DaemonServerRepository; use Pterodactyl\Repositories\Wings\DaemonServerRepository;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException; use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class ServerTransferController extends Controller class ServerTransferController extends Controller
@ -33,6 +34,10 @@ class ServerTransferController extends Controller
public function failure(string $uuid): JsonResponse public function failure(string $uuid): JsonResponse
{ {
$server = $this->repository->getByUuid($uuid); $server = $this->repository->getByUuid($uuid);
$transfer = $server->transfer;
if (is_null($transfer)) {
throw new ConflictHttpException('Server is not being transferred.');
}
return $this->processFailedTransfer($server->transfer); return $this->processFailedTransfer($server->transfer);
} }
@ -46,6 +51,9 @@ class ServerTransferController extends Controller
{ {
$server = $this->repository->getByUuid($uuid); $server = $this->repository->getByUuid($uuid);
$transfer = $server->transfer; $transfer = $server->transfer;
if (is_null($transfer)) {
throw new ConflictHttpException('Server is not being transferred.');
}
/** @var \Pterodactyl\Models\Server $server */ /** @var \Pterodactyl\Models\Server $server */
$server = $this->connection->transaction(function () use ($server, $transfer) { $server = $this->connection->transaction(function () use ($server, $transfer) {