2018-01-11 05:19:03 +00:00
|
|
|
<?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 16:59:20 +00:00
|
|
|
public function __construct(private AllocationRepositoryInterface $repository)
|
2018-01-11 05:19:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete an allocation from the database only if it does not have a server
|
|
|
|
* that is actively attached to it.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function handle(Allocation $allocation): int
|
2018-01-11 05:19:03 +00:00
|
|
|
{
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!is_null($allocation->server_id)) {
|
2018-01-11 05:19:03 +00:00
|
|
|
throw new ServerUsingAllocationException(trans('exceptions.allocations.server_using'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->repository->delete($allocation->id);
|
|
|
|
}
|
|
|
|
}
|