2017-06-15 04:53:24 +00:00
|
|
|
<?php
|
|
|
|
|
2017-09-15 05:16:03 +00:00
|
|
|
namespace Pterodactyl\Services\Locations;
|
2017-06-15 04:53:24 +00:00
|
|
|
|
2018-01-04 03:14:53 +00:00
|
|
|
use Pterodactyl\Models\Location;
|
2017-09-15 05:16:03 +00:00
|
|
|
use Pterodactyl\Exceptions\Service\Location\HasActiveNodesException;
|
2017-06-15 04:53:24 +00:00
|
|
|
|
2017-09-15 05:16:03 +00:00
|
|
|
class LocationDeletionService
|
2017-06-15 04:53:24 +00:00
|
|
|
{
|
|
|
|
/**
|
2017-09-15 05:16:03 +00:00
|
|
|
* Delete an existing location.
|
2017-06-15 04:53:24 +00:00
|
|
|
*
|
2022-10-24 02:17:24 +00:00
|
|
|
* @throws HasActiveNodesException
|
2017-06-15 04:53:24 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function handle(Location|int $location): ?int
|
2017-06-15 04:53:24 +00:00
|
|
|
{
|
2022-10-24 02:17:24 +00:00
|
|
|
/** @var Location $location */
|
|
|
|
$location = ($location instanceof Location) ? $location : Location::query()->findOrFail($location);
|
2017-06-15 04:53:24 +00:00
|
|
|
|
2022-10-24 02:17:24 +00:00
|
|
|
$count = $location->nodes()->count();
|
2017-09-15 05:16:03 +00:00
|
|
|
if ($count > 0) {
|
|
|
|
throw new HasActiveNodesException(trans('exceptions.locations.has_nodes'));
|
|
|
|
}
|
2017-06-15 04:53:24 +00:00
|
|
|
|
2022-10-24 02:17:24 +00:00
|
|
|
return $location->delete();
|
2017-06-15 04:53:24 +00:00
|
|
|
}
|
|
|
|
}
|