forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEggDeletionService.php
More file actions
41 lines (35 loc) · 1.23 KB
/
EggDeletionService.php
File metadata and controls
41 lines (35 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace Pterodactyl\Services\Eggs;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Exceptions\Service\Egg\HasChildrenException;
use Pterodactyl\Exceptions\Service\HasActiveServersException;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class EggDeletionService
{
/**
* EggDeletionService constructor.
*/
public function __construct(
protected ServerRepositoryInterface $serverRepository,
protected EggRepositoryInterface $repository,
) {
}
/**
* Delete an Egg from the database if it has no active servers attached to it.
*
* @throws HasActiveServersException
* @throws HasChildrenException
*/
public function handle(int $egg): int
{
$servers = $this->serverRepository->findCountWhere([['egg_id', '=', $egg]]);
if ($servers > 0) {
throw new HasActiveServersException(trans('exceptions.nest.egg.delete_has_servers'));
}
$children = $this->repository->findCountWhere([['config_from', '=', $egg]]);
if ($children > 0) {
throw new HasChildrenException(trans('exceptions.nest.egg.has_children'));
}
return $this->repository->delete($egg);
}
}