Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Services/Nests/NestDeletionService.php
10287 views
1
<?php
2
3
namespace Pterodactyl\Services\Nests;
4
5
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
6
use Pterodactyl\Exceptions\Service\HasActiveServersException;
7
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
8
9
class NestDeletionService
10
{
11
/**
12
* NestDeletionService constructor.
13
*/
14
public function __construct(
15
protected ServerRepositoryInterface $serverRepository,
16
protected NestRepositoryInterface $repository,
17
) {
18
}
19
20
/**
21
* Delete a nest from the system only if there are no servers attached to it.
22
*
23
* @throws HasActiveServersException
24
*/
25
public function handle(int $nest): int
26
{
27
$count = $this->serverRepository->findCountWhere([['nest_id', '=', $nest]]);
28
if ($count > 0) {
29
throw new HasActiveServersException(trans('exceptions.nest.delete_has_servers'));
30
}
31
32
return $this->repository->delete($nest);
33
}
34
}
35
36