2017-08-09 05:24:55 +01:00
|
|
|
<?php
|
|
|
|
|
2017-10-07 22:16:51 +01:00
|
|
|
namespace Pterodactyl\Services\Eggs;
|
2017-08-09 05:24:55 +01:00
|
|
|
|
2017-10-03 04:51:13 +01:00
|
|
|
use Ramsey\Uuid\Uuid;
|
2017-10-07 05:57:53 +01:00
|
|
|
use Pterodactyl\Models\Egg;
|
2017-10-03 04:51:13 +01:00
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
2017-10-07 22:16:51 +01:00
|
|
|
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
|
2017-08-09 05:24:55 +01:00
|
|
|
|
2018-05-13 15:50:56 +01:00
|
|
|
// When a mommy and a daddy pterodactyl really like each other...
|
2017-10-07 22:16:51 +01:00
|
|
|
class EggCreationService
|
2017-08-09 05:24:55 +01:00
|
|
|
{
|
|
|
|
/**
|
2017-10-07 22:16:51 +01:00
|
|
|
* EggCreationService constructor.
|
2017-08-09 05:24:55 +01:00
|
|
|
*/
|
2022-10-23 22:27:18 +01:00
|
|
|
public function __construct(private ConfigRepository $config)
|
2017-08-09 05:24:55 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new service option and assign it to the given service.
|
|
|
|
*
|
2022-10-23 22:27:18 +01:00
|
|
|
* @throws NoParentConfigurationFoundException
|
2017-08-09 05:24:55 +01:00
|
|
|
*/
|
2017-10-07 05:57:53 +01:00
|
|
|
public function handle(array $data): Egg
|
2017-08-09 05:24:55 +01:00
|
|
|
{
|
2017-10-07 22:16:51 +01:00
|
|
|
$data['config_from'] = array_get($data, 'config_from');
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!is_null($data['config_from'])) {
|
2022-10-23 22:27:18 +01:00
|
|
|
$results = Egg::query()
|
|
|
|
->where('nest_id', array_get($data, 'nest_id'))
|
|
|
|
->where('id', array_get($data, 'config_from'))
|
|
|
|
->count();
|
2017-08-09 05:24:55 +01:00
|
|
|
|
|
|
|
if ($results !== 1) {
|
2017-10-08 21:29:46 +01:00
|
|
|
throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));
|
2017-08-09 05:24:55 +01:00
|
|
|
}
|
2017-10-03 04:51:13 +01:00
|
|
|
}
|
|
|
|
|
2022-10-23 22:27:18 +01:00
|
|
|
/** @var Egg $egg */
|
|
|
|
$egg = Egg::query()->create(array_merge($data, [
|
2017-10-03 04:51:13 +01:00
|
|
|
'uuid' => Uuid::uuid4()->toString(),
|
2017-10-07 22:16:51 +01:00
|
|
|
'author' => $this->config->get('pterodactyl.service.author'),
|
2022-10-23 22:27:18 +01:00
|
|
|
]));
|
|
|
|
|
|
|
|
return $egg;
|
2017-08-09 05:24:55 +01:00
|
|
|
}
|
|
|
|
}
|