Files

38 lines
1.0 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Pterodactyl\Services\Locations;
2018-01-03 21:14:53 -06:00
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(
2022-10-14 10:59:20 -06:00
protected LocationRepositoryInterface $repository,
2024-10-21 19:18:20 -06:00
protected NodeRepositoryInterface $nodeRepository,
) {
}
/**
* Delete an existing location.
*
2024-10-21 19:18:20 -06:00
* @throws HasActiveNodesException
*/
2022-10-14 10:59:20 -06:00
public function handle(Location|int $location): ?int
{
$location = $location instanceof Location ? $location->id : $location;
$count = $this->nodeRepository->findCountWhere([['location_id', '=', $location]]);
if ($count > 0) {
throw new HasActiveNodesException(trans('exceptions.locations.has_nodes'));
}
return $this->repository->delete($location);
}
}