misc_pterodactyl-panel/app/Services/Allocations/AllocationDeletionService.php

41 lines
1.1 KiB
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
{
/**
* @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface
*/
private $repository;
/**
* AllocationDeletionService constructor.
*/
public function __construct(AllocationRepositoryInterface $repository)
{
$this->repository = $repository;
}
/**
* Delete an allocation from the database only if it does not have a server
* that is actively attached to it.
*
* @return int
*
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
*/
public function handle(Allocation $allocation)
{
2021-01-23 20:33:34 +00:00
if (!is_null($allocation->server_id)) {
throw new ServerUsingAllocationException(trans('exceptions.allocations.server_using'));
}
return $this->repository->delete($allocation->id);
}
}