Files

33 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2026-10-05 18:10:18 -04:00
<?php
declare(strict_types=1);
namespace Pterodactyl\Actions\Allocations;
use Pterodactyl\Contracts\Allocations\UnassignsAllocations;
use Pterodactyl\Exceptions\DisplayException;
2026-10-11 14:10:47 -04:00
use Pterodactyl\Facades\Activity;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\Allocation;
use Pterodactyl\Models\Server;
final class UnassignAllocation implements UnassignsAllocations
{
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,
]);
2026-10-11 14:10:47 -04:00
Activity::event('server:allocation.delete')
->subject($server, $allocation)
->property('allocation', $allocation->toString())
->log();
2026-10-05 18:10:18 -04:00
return $allocation->refresh();
}
}