From d8f75fa0b7cde9ad94f4c25faed4dc499d6ba576 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Thu, 17 Dec 2020 11:14:58 -0700 Subject: [PATCH] Fix failed transfers locking a server into a unaccessible state --- .../Servers/ServerTransferController.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php b/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php index cc9d197a4..32c56e98a 100644 --- a/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php +++ b/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php @@ -12,7 +12,6 @@ use Illuminate\Http\JsonResponse; use Lcobucci\JWT\Signer\Hmac\Sha256; use Illuminate\Database\ConnectionInterface; use Pterodactyl\Http\Controllers\Controller; -use Pterodactyl\Services\Servers\SuspensionService; use Pterodactyl\Repositories\Eloquent\NodeRepository; use Pterodactyl\Repositories\Eloquent\ServerRepository; use Pterodactyl\Repositories\Wings\DaemonServerRepository; @@ -114,9 +113,8 @@ class ServerTransferController extends Controller if (! $request->input('successful')) { $transfer = $server->transfer; - $transfer->forceFill([ - 'successful' => false, - ])->saveOrFail(); + $transfer->successful = false; + $transfer->saveOrFail(); $allocationIds = json_decode($transfer->new_additional_allocations); array_push($allocationIds, $transfer->new_allocation); @@ -189,9 +187,19 @@ class ServerTransferController extends Controller $allocationIds = json_decode($transfer->new_additional_allocations); array_push($allocationIds, $transfer->new_allocation); + // Begin a transaction. + $this->connection->beginTransaction(); + + // Mark the transfer as unsuccessful. + $transfer->successful = false; + $transfer->saveOrFail(); + // Remove the new allocations. $this->allocationRepository->updateWhereIn('id', $allocationIds, ['server_id' => null]); + // Commit the transaction. + $this->connection->commit(); + return new JsonResponse([], Response::HTTP_NO_CONTENT); } @@ -236,9 +244,6 @@ class ServerTransferController extends Controller $this->writer->warning($exception); } - // Unsuspend the server - $server->load('node'); - return new JsonResponse([], Response::HTTP_NO_CONTENT); } }