mirror of
https://github.com/pterodactyl/panel.git
synced 2024-11-23 09:32:29 +01:00
59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Pterodactyl - Panel
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
*
|
|
* This software is licensed under the terms of the MIT license.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
namespace Pterodactyl\Services\Eggs;
|
|
|
|
use Pterodactyl\Models\Egg;
|
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
|
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
|
|
|
|
class EggUpdateService
|
|
{
|
|
/**
|
|
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
|
*/
|
|
protected $repository;
|
|
|
|
/**
|
|
* EggUpdateService constructor.
|
|
*
|
|
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
|
|
*/
|
|
public function __construct(EggRepositoryInterface $repository)
|
|
{
|
|
$this->repository = $repository;
|
|
}
|
|
|
|
/**
|
|
* Update a service option.
|
|
*
|
|
* @param \Pterodactyl\Models\Egg $egg
|
|
* @param array $data
|
|
*
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
|
|
*/
|
|
public function handle(Egg $egg, array $data)
|
|
{
|
|
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'));
|
|
}
|
|
}
|
|
|
|
$this->repository->withoutFreshModel()->update($egg->id, $data);
|
|
}
|
|
}
|