From b4cae916ac1b62480d82e97dd421d8b7df9007d7 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Wed, 18 Aug 2021 11:58:41 -0700 Subject: [PATCH] transfers: fix allocation array merging logic (#3551) --- .../Remote/Servers/ServerTransferController.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php b/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php index 9259c32d..5962f307 100644 --- a/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php +++ b/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php @@ -146,17 +146,14 @@ class ServerTransferController extends Controller * * @throws \Throwable */ - public function success(string $uuid) + public function success(string $uuid): JsonResponse { $server = $this->repository->getByUuid($uuid); $transfer = $server->transfer; /** @var \Pterodactyl\Models\Server $server */ $server = $this->connection->transaction(function () use ($server, $transfer) { - $allocations = [$transfer->old_allocation]; - if (!empty($transfer->old_additional_allocations)) { - array_push($allocations, $transfer->old_additional_allocations); - } + $allocations = array_merge([$transfer->old_allocation], $transfer->old_additional_allocations); // Remove the old allocations for the server and re-assign the server to the new // primary allocation and node. @@ -173,7 +170,7 @@ class ServerTransferController extends Controller }); // Delete the server from the old node making sure to point it to the old node so - // that we do not delete it from the new node the server was transfered to. + // that we do not delete it from the new node the server was transferred to. try { $this->daemonServerRepository ->setServer($server) @@ -199,11 +196,7 @@ class ServerTransferController extends Controller $this->connection->transaction(function () use (&$transfer) { $transfer->forceFill(['successful' => false])->saveOrFail(); - $allocations = [$transfer->new_allocation]; - if (!empty($transfer->new_additional_allocations)) { - array_push($allocations, $transfer->new_additional_allocations); - } - + $allocations = array_merge([$transfer->new_allocation], $transfer->new_additional_allocations); Allocation::query()->whereIn('id', $allocations)->update(['server_id' => null]); });