Path: blob/1.0-develop/app/Services/Eggs/EggDeletionService.php
10314 views
<?php12namespace Pterodactyl\Services\Eggs;34use Pterodactyl\Contracts\Repository\EggRepositoryInterface;5use Pterodactyl\Exceptions\Service\Egg\HasChildrenException;6use Pterodactyl\Exceptions\Service\HasActiveServersException;7use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;89class EggDeletionService10{11/**12* EggDeletionService constructor.13*/14public function __construct(15protected ServerRepositoryInterface $serverRepository,16protected EggRepositoryInterface $repository,17) {18}1920/**21* Delete an Egg from the database if it has no active servers attached to it.22*23* @throws HasActiveServersException24* @throws HasChildrenException25*/26public function handle(int $egg): int27{28$servers = $this->serverRepository->findCountWhere([['egg_id', '=', $egg]]);29if ($servers > 0) {30throw new HasActiveServersException(trans('exceptions.nest.egg.delete_has_servers'));31}3233$children = $this->repository->findCountWhere([['config_from', '=', $egg]]);34if ($children > 0) {35throw new HasChildrenException(trans('exceptions.nest.egg.has_children'));36}3738return $this->repository->delete($egg);39}40}414243