Replace egg repository
This commit is contained in:
parent
860b2d890b
commit
6e4f7f16c1
11 changed files with 54 additions and 206 deletions
|
@ -2,27 +2,25 @@
|
|||
|
||||
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;
|
||||
use Pterodactyl\Models\Egg;
|
||||
|
||||
class EggDeletionService
|
||||
{
|
||||
/**
|
||||
* EggDeletionService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
protected ServerRepositoryInterface $serverRepository,
|
||||
protected EggRepositoryInterface $repository
|
||||
) {
|
||||
public function __construct(protected ServerRepositoryInterface $serverRepository)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @throws HasActiveServersException
|
||||
* @throws HasChildrenException
|
||||
*/
|
||||
public function handle(int $egg): int
|
||||
{
|
||||
|
@ -31,11 +29,13 @@ class EggDeletionService
|
|||
throw new HasActiveServersException(trans('exceptions.nest.egg.delete_has_servers'));
|
||||
}
|
||||
|
||||
$children = $this->repository->findCountWhere([['config_from', '=', $egg]]);
|
||||
$children = Egg::query()->where('config_from', $egg)->count();
|
||||
if ($children > 0) {
|
||||
throw new HasChildrenException(trans('exceptions.nest.egg.has_children'));
|
||||
}
|
||||
|
||||
return $this->repository->delete($egg);
|
||||
$egg = Egg::query()->findOrFail($egg);
|
||||
|
||||
return $egg->delete();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue