Replace egg repository
This commit is contained in:
parent
860b2d890b
commit
6e4f7f16c1
11 changed files with 54 additions and 206 deletions
|
@ -3,42 +3,33 @@
|
|||
namespace Pterodactyl\Services\Eggs;
|
||||
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
|
||||
|
||||
class EggUpdateService
|
||||
{
|
||||
/**
|
||||
* EggUpdateService constructor.
|
||||
*/
|
||||
public function __construct(protected EggRepositoryInterface $repository)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a service option.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
|
||||
* @throws NoParentConfigurationFoundException
|
||||
*/
|
||||
public function handle(Egg $egg, array $data): void
|
||||
{
|
||||
if (!is_null(array_get($data, 'config_from'))) {
|
||||
$results = $this->repository->findCountWhere([
|
||||
['nest_id', '=', $egg->nest_id],
|
||||
['id', '=', array_get($data, 'config_from')],
|
||||
]);
|
||||
$eggId = array_get($data, 'config_from');
|
||||
if (!is_null($eggId)) {
|
||||
$results = Egg::query()
|
||||
->where('nest_id', $egg->nest_id)
|
||||
->where('id', $eggId)
|
||||
->count();
|
||||
|
||||
if ($results !== 1) {
|
||||
throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(dane): Once the admin UI is done being reworked and this is exposed
|
||||
// TODO: (Dane) Once the admin UI is done being reworked and this is exposed
|
||||
// in said UI, remove this so that you can actually update the denylist.
|
||||
unset($data['file_denylist']);
|
||||
|
||||
$this->repository->withoutFreshModel()->update($egg->id, $data);
|
||||
$egg->update($data);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue