2017-08-16 03:21:47 +00:00
|
|
|
<?php
|
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
namespace Pterodactyl\Services\Nests;
|
2017-08-16 03:21:47 +00:00
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
2017-08-19 03:19:06 +00:00
|
|
|
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
2017-08-16 03:21:47 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
class NestDeletionService
|
2017-08-16 03:21:47 +00:00
|
|
|
{
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* NestDeletionService constructor.
|
2017-08-16 03:21:47 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2022-10-14 16:59:20 +00:00
|
|
|
protected ServerRepositoryInterface $serverRepository,
|
|
|
|
protected NestRepositoryInterface $repository
|
2017-08-16 03:21:47 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Delete a nest from the system only if there are no servers attached to it.
|
2017-08-16 03:21:47 +00:00
|
|
|
*
|
2017-08-19 03:19:06 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
2017-08-16 03:21:47 +00:00
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function handle(int $nest): int
|
2017-08-16 03:21:47 +00:00
|
|
|
{
|
2017-10-07 04:57:53 +00:00
|
|
|
$count = $this->serverRepository->findCountWhere([['nest_id', '=', $nest]]);
|
2017-08-16 03:21:47 +00:00
|
|
|
if ($count > 0) {
|
2019-10-04 05:14:47 +00:00
|
|
|
throw new HasActiveServersException(trans('exceptions.nest.delete_has_servers'));
|
2017-08-16 03:21:47 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
return $this->repository->delete($nest);
|
2017-08-16 03:21:47 +00:00
|
|
|
}
|
|
|
|
}
|