mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-01 11:55:51 -05:00
27 lines
927 B
PHP
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);
|
|
});
|
|
}
|
|
}
|