Path: blob/1.0-develop/app/Services/Locations/LocationDeletionService.php
10284 views
<?php12namespace Pterodactyl\Services\Locations;34use Pterodactyl\Models\Location;5use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;6use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;7use Pterodactyl\Exceptions\Service\Location\HasActiveNodesException;89class LocationDeletionService10{11/**12* LocationDeletionService constructor.13*/14public function __construct(15protected LocationRepositoryInterface $repository,16protected NodeRepositoryInterface $nodeRepository,17) {18}1920/**21* Delete an existing location.22*23* @throws HasActiveNodesException24*/25public function handle(Location|int $location): ?int26{27$location = $location instanceof Location ? $location->id : $location;2829$count = $this->nodeRepository->findCountWhere([['location_id', '=', $location]]);30if ($count > 0) {31throw new HasActiveNodesException(trans('exceptions.locations.has_nodes'));32}3334return $this->repository->delete($location);35}36}373839