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-03 03:51:13 +00:00
|
|
|
use Ramsey\Uuid\Uuid;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Models\Egg;
|
|
|
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
2017-10-03 03:51:13 +00:00
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
2017-10-07 21:16:51 +00:00
|
|
|
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
|
2017-08-09 04:24:55 +00:00
|
|
|
|
2018-05-13 14:50:56 +00:00
|
|
|
// When a mommy and a daddy pterodactyl really like each other...
|
2017-10-07 21:16:51 +00:00
|
|
|
class EggCreationService
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
2017-10-03 03:51:13 +00:00
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Config\Repository
|
|
|
|
*/
|
|
|
|
protected $config;
|
|
|
|
|
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
|
|
|
* EggCreationService constructor.
|
2017-08-09 04:24:55 +00:00
|
|
|
*
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Illuminate\Contracts\Config\Repository $config
|
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(ConfigRepository $config, EggRepositoryInterface $repository)
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
2017-10-03 03:51:13 +00:00
|
|
|
$this->config = $config;
|
2017-08-09 04:24:55 +00:00
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new service option and assign it to the given service.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param array $data
|
2017-10-07 04:57:53 +00:00
|
|
|
* @return \Pterodactyl\Models\Egg
|
2017-08-09 04:24:55 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-10-07 21:16:51 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function handle(array $data): Egg
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
2017-10-07 21:16:51 +00:00
|
|
|
$data['config_from'] = array_get($data, 'config_from');
|
|
|
|
if (! is_null($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', '=', array_get($data, 'nest_id')],
|
2017-08-09 04:24:55 +00:00
|
|
|
['id', '=', array_get($data, 'config_from')],
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($results !== 1) {
|
2017-10-08 20:29:46 +00:00
|
|
|
throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));
|
2017-08-09 04:24:55 +00:00
|
|
|
}
|
2017-10-03 03:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->repository->create(array_merge($data, [
|
|
|
|
'uuid' => Uuid::uuid4()->toString(),
|
2017-10-07 21:16:51 +00:00
|
|
|
'author' => $this->config->get('pterodactyl.service.author'),
|
2017-10-03 03:51:13 +00:00
|
|
|
]), true, true);
|
2017-08-09 04:24:55 +00:00
|
|
|
}
|
|
|
|
}
|