2017-08-09 04:24:55 +00:00
|
|
|
<?php
|
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
namespace Pterodactyl\Services\Eggs;
|
2017-08-09 04:24:55 +00:00
|
|
|
|
2022-10-21 01:17:03 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
2017-10-07 21:16:51 +00:00
|
|
|
use Pterodactyl\Exceptions\Service\Egg\HasChildrenException;
|
2017-08-19 03:19:06 +00:00
|
|
|
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
2017-08-09 04:24:55 +00:00
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
class EggDeletionService
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
2017-08-12 20:29:01 +00:00
|
|
|
/**
|
2017-10-07 21:16:51 +00:00
|
|
|
* EggDeletionService constructor.
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
2017-08-12 20:29:01 +00:00
|
|
|
public function __construct(
|
2022-10-14 16:59:20 +00:00
|
|
|
protected EggRepositoryInterface $repository
|
2017-08-12 20:29:01 +00:00
|
|
|
) {
|
2017-08-09 04:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 21:16:51 +00:00
|
|
|
* Delete an Egg from the database if it has no active servers attached to it.
|
2017-08-09 04:24:55 +00:00
|
|
|
*
|
2017-08-19 03:19:06 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
2017-10-07 21:16:51 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\HasChildrenException
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
2017-10-07 21:16:51 +00:00
|
|
|
public function handle(int $egg): int
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
2022-10-21 01:17:03 +00:00
|
|
|
if (Server::query()->where('egg_id', $egg)->count()) {
|
2017-10-07 21:16:51 +00:00
|
|
|
throw new HasActiveServersException(trans('exceptions.nest.egg.delete_has_servers'));
|
2017-08-09 04:24:55 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
$children = $this->repository->findCountWhere([['config_from', '=', $egg]]);
|
2017-09-30 17:54:09 +00:00
|
|
|
if ($children > 0) {
|
2017-10-07 21:16:51 +00:00
|
|
|
throw new HasChildrenException(trans('exceptions.nest.egg.has_children'));
|
2017-09-30 17:54:09 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
return $this->repository->delete($egg);
|
2017-08-09 04:24:55 +00:00
|
|
|
}
|
|
|
|
}
|