1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-23 01:22:30 +01:00
Pterodactyl-Panel/app/Services/Eggs/EggDeletionService.php
Matthew Penner cbcf62086f
Upgrade to Laravel 9 (#4413)
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
2022-10-14 10:59:20 -06:00

42 lines
1.3 KiB
PHP

<?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 \Pterodactyl\Exceptions\Service\HasActiveServersException
* @throws \Pterodactyl\Exceptions\Service\Egg\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);
}
}