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\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 04:57:53 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
2017-10-07 21:16:51 +00:00
|
|
|
* EggUpdateService constructor.
|
2017-08-09 04:24:55 +00:00
|
|
|
*
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function __construct(EggRepositoryInterface $repository)
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-12 20:29:01 +00:00
|
|
|
* Update a service option.
|
2017-08-09 04:24:55 +00:00
|
|
|
*
|
2020-11-03 04:20:36 +00:00
|
|
|
* @param \Pterodactyl\Models\Egg $egg
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param array $data
|
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
|
|
|
*/
|
2020-11-03 04:20:36 +00:00
|
|
|
public function handle(Egg $egg, array $data)
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
|
|
|
if (! is_null(array_get($data, 'config_from'))) {
|
|
|
|
$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
|
|
|
}
|
|
|
|
}
|