Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Services/Allocations/AllocationDeletionService.php
14042 views
1
<?php
2
3
namespace Pterodactyl\Services\Allocations;
4
5
use Pterodactyl\Models\Allocation;
6
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
7
use Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException;
8
9
class AllocationDeletionService
10
{
11
/**
12
* AllocationDeletionService constructor.
13
*/
14
public function __construct(private AllocationRepositoryInterface $repository)
15
{
16
}
17
18
/**
19
* Delete an allocation from the database only if it does not have a server
20
* that is actively attached to it.
21
*
22
* @throws ServerUsingAllocationException
23
*/
24
public function handle(Allocation $allocation): int
25
{
26
if (!is_null($allocation->server_id)) {
27
throw new ServerUsingAllocationException(trans('exceptions.allocations.server_using'));
28
}
29
30
return $this->repository->delete($allocation->id);
31
}
32
}
33
34