From 8d297a09183ed727414cbd8ed57ffb415aa282b9 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Wed, 16 Dec 2020 19:24:39 -0700 Subject: [PATCH] Release reserved allocations upon archive failure --- .../Api/Remote/Servers/ServerTransferController.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php b/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php index 8ee2c242f..cc9d197a4 100644 --- a/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php +++ b/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php @@ -112,10 +112,18 @@ class ServerTransferController extends Controller // Unsuspend the server and don't continue the transfer. if (! $request->input('successful')) { - $server->transfer->forceFill([ + $transfer = $server->transfer; + + $transfer->forceFill([ 'successful' => false, ])->saveOrFail(); + $allocationIds = json_decode($transfer->new_additional_allocations); + array_push($allocationIds, $transfer->new_allocation); + + // Release the reserved allocations. + $this->allocationRepository->updateWhereIn('id', $allocationIds, ['server_id' => null]); + return new JsonResponse([], Response::HTTP_NO_CONTENT); }