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