Files
2026-10-12 05:18:58 -04:00

27 lines
927 B
PHP

<?php
declare(strict_types=1);
namespace Pterodactyl\Actions\Allocations;
use Illuminate\Support\Facades\DB;
use Pterodactyl\Contracts\Allocations\AssignsAllocations;
use Pterodactyl\Contracts\Allocations\AssignsAvailableAllocations;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Models\Server;
final readonly class AssignAllocation implements AssignsAllocations
{
public function __construct(private AssignsAvailableAllocations $assignable) {}
public function assign(Server $server): Allocation
{
return DB::transaction(function () use ($server): Allocation {
throw_if($server->allocations()->lockForUpdate()->count() >= $server->allocation_limit, DisplayException::class, 'Cannot assign additional allocations to this server: limit has been reached.');
return $this->assignable->assignAvailable($server);
});
}
}