misc_pterodactyl-panel/app/Services/Eggs/EggUpdateService.php

45 lines
1.4 KiB
PHP
Raw Normal View History

<?php
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
*/
public function handle(Egg $egg, array $data): void
{
2021-01-23 20:33:34 +00:00
if (!is_null(array_get($data, 'config_from'))) {
$results = $this->repository->findCountWhere([
['nest_id', '=', $egg->nest_id],
['id', '=', array_get($data, 'config_from')],
]);
if ($results !== 1) {
throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));
}
}
2021-01-11 01:05:41 +00:00
// 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']);
2018-01-05 22:33:50 +00:00
$this->repository->withoutFreshModel()->update($egg->id, $data);
}
}