2017-08-09 04:24:55 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-08-09 04:24:55 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
namespace Pterodactyl\Services\Eggs;
|
2017-08-09 04:24:55 +00:00
|
|
|
|
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-12 20:29:01 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
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-10-07 04:57:53 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
2017-08-12 20:29:01 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $serverRepository;
|
|
|
|
|
|
|
|
/**
|
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(
|
|
|
|
ServerRepositoryInterface $serverRepository,
|
2017-10-07 04:57:53 +00:00
|
|
|
EggRepositoryInterface $repository
|
2017-08-12 20:29:01 +00:00
|
|
|
) {
|
2017-08-09 04:24:55 +00:00
|
|
|
$this->repository = $repository;
|
2017-08-12 20:29:01 +00:00
|
|
|
$this->serverRepository = $serverRepository;
|
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
|
|
|
{
|
2017-10-07 21:16:51 +00:00
|
|
|
$servers = $this->serverRepository->findCountWhere([['egg_id', '=', $egg]]);
|
2017-08-12 20:29:01 +00:00
|
|
|
if ($servers > 0) {
|
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
|
|
|
}
|
|
|
|
}
|