Files
pterodactyl-panel/app/Actions/Allocations/UnassignAllocation.php
T
6c0413e39b Start 2.0 development
Co-authored-by: Anthony <anthony@infraly.co>
Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
2026-10-05 18:10:18 -04:00

30 lines
943 B
PHP

<?php
declare(strict_types=1);
namespace Pterodactyl\Actions\Allocations;
use Pterodactyl\Contracts\Allocations\UnassignsAllocations;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Models\Server;
final class UnassignAllocation implements UnassignsAllocations
{
/**
* @throws DisplayException
*/
public function unassign(Server $server, Allocation $allocation): Allocation
{
throw_if(empty($server->allocation_limit), DisplayException::class, 'You cannot delete allocations for this server: no allocation limit is set.');
throw_if($allocation->id === $server->allocation_id, DisplayException::class, 'You cannot delete the primary allocation for this server.');
Allocation::query()->where('id', $allocation->id)->update([
'notes' => null,
'server_id' => null,
]);
return $allocation->refresh();
}
}