Files

33 lines
903 B
PHP
Raw Permalink Normal View History

<?php
namespace Pterodactyl\Services\Allocations;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
use Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException;
class AllocationDeletionService
{
/**
* AllocationDeletionService constructor.
*/
2022-10-14 10:59:20 -06:00
public function __construct(private AllocationRepositoryInterface $repository)
{
}
/**
* Delete an allocation from the database only if it does not have a server
* that is actively attached to it.
*
2024-10-21 19:18:20 -06:00
* @throws ServerUsingAllocationException
*/
2022-10-14 10:59:20 -06:00
public function handle(Allocation $allocation): int
{
2021-01-23 12:33:34 -08:00
if (!is_null($allocation->server_id)) {
throw new ServerUsingAllocationException(trans('exceptions.allocations.server_using'));
}
return $this->repository->delete($allocation->id);
}
}