Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Services/Eggs/EggDeletionService.php
10314 views
1
<?php
2
3
namespace Pterodactyl\Services\Eggs;
4
5
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
6
use Pterodactyl\Exceptions\Service\Egg\HasChildrenException;
7
use Pterodactyl\Exceptions\Service\HasActiveServersException;
8
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
9
10
class EggDeletionService
11
{
12
/**
13
* EggDeletionService constructor.
14
*/
15
public function __construct(
16
protected ServerRepositoryInterface $serverRepository,
17
protected EggRepositoryInterface $repository,
18
) {
19
}
20
21
/**
22
* Delete an Egg from the database if it has no active servers attached to it.
23
*
24
* @throws HasActiveServersException
25
* @throws HasChildrenException
26
*/
27
public function handle(int $egg): int
28
{
29
$servers = $this->serverRepository->findCountWhere([['egg_id', '=', $egg]]);
30
if ($servers > 0) {
31
throw new HasActiveServersException(trans('exceptions.nest.egg.delete_has_servers'));
32
}
33
34
$children = $this->repository->findCountWhere([['config_from', '=', $egg]]);
35
if ($children > 0) {
36
throw new HasChildrenException(trans('exceptions.nest.egg.has_children'));
37
}
38
39
return $this->repository->delete($egg);
40
}
41
}
42
43