forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocationDeletionService.php
More file actions
40 lines (33 loc) · 1.21 KB
/
LocationDeletionService.php
File metadata and controls
40 lines (33 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace Pterodactyl\Services\Locations;
use Webmozart\Assert\Assert;
use Pterodactyl\Models\Location;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
use Pterodactyl\Exceptions\Service\Location\HasActiveNodesException;
class LocationDeletionService
{
/**
* LocationDeletionService constructor.
*/
public function __construct(
protected LocationRepositoryInterface $repository,
protected NodeRepositoryInterface $nodeRepository,
) {
}
/**
* Delete an existing location.
*
* @throws HasActiveNodesException
*/
public function handle(Location|int $location): ?int
{
$location = ($location instanceof Location) ? $location->id : $location;
Assert::integerish($location, 'First argument passed to handle must be numeric or an instance of ' . Location::class . ', received %s.');
$count = $this->nodeRepository->findCountWhere([['location_id', '=', $location]]);
if ($count > 0) {
throw new HasActiveNodesException(trans('exceptions.locations.has_nodes'));
}
return $this->repository->delete($location);
}
}