Skip to content

Commit d8f75fa

Browse files
committed
Fix failed transfers locking a server into a unaccessible state
1 parent 37cfa15 commit d8f75fa

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Lcobucci\JWT\Signer\Hmac\Sha256;
1313
use Illuminate\Database\ConnectionInterface;
1414
use Pterodactyl\Http\Controllers\Controller;
15-
use Pterodactyl\Services\Servers\SuspensionService;
1615
use Pterodactyl\Repositories\Eloquent\NodeRepository;
1716
use Pterodactyl\Repositories\Eloquent\ServerRepository;
1817
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
@@ -114,9 +113,8 @@ public function archive(Request $request, string $uuid)
114113
if (! $request->input('successful')) {
115114
$transfer = $server->transfer;
116115

117-
$transfer->forceFill([
118-
'successful' => false,
119-
])->saveOrFail();
116+
$transfer->successful = false;
117+
$transfer->saveOrFail();
120118

121119
$allocationIds = json_decode($transfer->new_additional_allocations);
122120
array_push($allocationIds, $transfer->new_allocation);
@@ -189,9 +187,19 @@ public function failure(string $uuid)
189187
$allocationIds = json_decode($transfer->new_additional_allocations);
190188
array_push($allocationIds, $transfer->new_allocation);
191189

190+
// Begin a transaction.
191+
$this->connection->beginTransaction();
192+
193+
// Mark the transfer as unsuccessful.
194+
$transfer->successful = false;
195+
$transfer->saveOrFail();
196+
192197
// Remove the new allocations.
193198
$this->allocationRepository->updateWhereIn('id', $allocationIds, ['server_id' => null]);
194199

200+
// Commit the transaction.
201+
$this->connection->commit();
202+
195203
return new JsonResponse([], Response::HTTP_NO_CONTENT);
196204
}
197205

@@ -236,9 +244,6 @@ public function success(string $uuid)
236244
$this->writer->warning($exception);
237245
}
238246

239-
// Unsuspend the server
240-
$server->load('node');
241-
242247
return new JsonResponse([], Response::HTTP_NO_CONTENT);
243248
}
244249
}

0 commit comments

Comments
 (0)