Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Services/Locations/LocationDeletionService.php
10284 views
1
<?php
2
3
namespace Pterodactyl\Services\Locations;
4
5
use Pterodactyl\Models\Location;
6
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
7
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
8
use Pterodactyl\Exceptions\Service\Location\HasActiveNodesException;
9
10
class LocationDeletionService
11
{
12
/**
13
* LocationDeletionService constructor.
14
*/
15
public function __construct(
16
protected LocationRepositoryInterface $repository,
17
protected NodeRepositoryInterface $nodeRepository,
18
) {
19
}
20
21
/**
22
* Delete an existing location.
23
*
24
* @throws HasActiveNodesException
25
*/
26
public function handle(Location|int $location): ?int
27
{
28
$location = $location instanceof Location ? $location->id : $location;
29
30
$count = $this->nodeRepository->findCountWhere([['location_id', '=', $location]]);
31
if ($count > 0) {
32
throw new HasActiveNodesException(trans('exceptions.locations.has_nodes'));
33
}
34
35
return $this->repository->delete($location);
36
}
37
}
38
39