mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-02 20:35:50 -05:00
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
30 lines
943 B
PHP
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();
|
|
}
|
|
}
|