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
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Models\Egg;
|
|
|
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
2017-10-07 21:16:51 +00:00
|
|
|
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
|
2017-08-09 04:24:55 +00:00
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
class EggUpdateService
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
|
|
|
/**
|
2017-10-07 21:16:51 +00:00
|
|
|
* EggUpdateService constructor.
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function __construct(protected EggRepositoryInterface $repository)
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-12 20:29:01 +00:00
|
|
|
* Update a service option.
|
2017-08-09 04:24:55 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-08-12 20:29:01 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-10-07 21:16:51 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function handle(Egg $egg, array $data): void
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!is_null(array_get($data, 'config_from'))) {
|
2017-08-09 04:24:55 +00:00
|
|
|
$results = $this->repository->findCountWhere([
|
2017-10-07 21:16:51 +00:00
|
|
|
['nest_id', '=', $egg->nest_id],
|
2017-08-09 04:24:55 +00:00
|
|
|
['id', '=', array_get($data, 'config_from')],
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($results !== 1) {
|
2017-10-07 21:16:51 +00:00
|
|
|
throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));
|
2017-08-09 04:24:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2017-08-09 04:24:55 +00:00
|
|
|
}
|
|
|
|
}
|