mirror of
https://github.com/pterodactyl/panel.git
synced 2024-11-26 02:52:30 +01:00
cbcf62086f
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
33 lines
946 B
PHP
33 lines
946 B
PHP
<?php
|
|
|
|
namespace Pterodactyl\Services\Allocations;
|
|
|
|
use Pterodactyl\Models\Allocation;
|
|
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
|
use Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException;
|
|
|
|
class AllocationDeletionService
|
|
{
|
|
/**
|
|
* AllocationDeletionService constructor.
|
|
*/
|
|
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.
|
|
*
|
|
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
|
|
*/
|
|
public function handle(Allocation $allocation): int
|
|
{
|
|
if (!is_null($allocation->server_id)) {
|
|
throw new ServerUsingAllocationException(trans('exceptions.allocations.server_using'));
|
|
}
|
|
|
|
return $this->repository->delete($allocation->id);
|
|
}
|
|
}
|