transfers: fix allocation array merging logic (#3551)

This commit is contained in:
Matthew Penner 2021-08-18 11:58:41 -07:00 committed by GitHub
parent b94d69bbab
commit b4cae916ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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]);
});