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>
35 lines
984 B
PHP
35 lines
984 B
PHP
<?php
|
|
|
|
namespace Pterodactyl\Services\Nests;
|
|
|
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
|
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|
|
|
class NestDeletionService
|
|
{
|
|
/**
|
|
* NestDeletionService constructor.
|
|
*/
|
|
public function __construct(
|
|
protected ServerRepositoryInterface $serverRepository,
|
|
protected NestRepositoryInterface $repository
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Delete a nest from the system only if there are no servers attached to it.
|
|
*
|
|
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
|
*/
|
|
public function handle(int $nest): int
|
|
{
|
|
$count = $this->serverRepository->findCountWhere([['nest_id', '=', $nest]]);
|
|
if ($count > 0) {
|
|
throw new HasActiveServersException(trans('exceptions.nest.delete_has_servers'));
|
|
}
|
|
|
|
return $this->repository->delete($nest);
|
|
}
|
|
}
|