mirror of
https://github.com/pterodactyl/panel.git
synced 2024-11-26 02:52:30 +01:00
cbcf62086f
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?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 \Pterodactyl\Exceptions\Service\Location\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);
|
|
}
|
|
}
|