2017-08-09 04:24:55 +00:00
|
|
|
<?php
|
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
namespace Pterodactyl\Services\Eggs\Scripts;
|
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\InvalidCopyFromException;
|
2017-08-09 04:24:55 +00:00
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
class InstallScriptService
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
|
|
|
/**
|
2017-10-07 21:16:51 +00:00
|
|
|
* InstallScriptService 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-10-07 21:16:51 +00:00
|
|
|
* Modify the install script for a given Egg.
|
2017-08-09 04:24:55 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-08-12 21:30:27 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-10-07 21:16:51 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException
|
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, 'copy_script_from'))) {
|
|
|
|
if (!$this->repository->isCopyableScript(array_get($data, 'copy_script_from'), $egg->nest_id)) {
|
2017-10-07 21:16:51 +00:00
|
|
|
throw new InvalidCopyFromException(trans('exceptions.nest.egg.invalid_copy_id'));
|
2017-08-09 04:24:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-05 22:33:50 +00:00
|
|
|
$this->repository->withoutFreshModel()->update($egg->id, [
|
2017-08-12 20:29:01 +00:00
|
|
|
'script_install' => array_get($data, 'script_install'),
|
2017-10-07 21:16:51 +00:00
|
|
|
'script_is_privileged' => array_get($data, 'script_is_privileged', 1),
|
2017-08-12 20:29:01 +00:00
|
|
|
'script_entry' => array_get($data, 'script_entry'),
|
|
|
|
'script_container' => array_get($data, 'script_container'),
|
|
|
|
'copy_script_from' => array_get($data, 'copy_script_from'),
|
|
|
|
]);
|
2017-08-09 04:24:55 +00:00
|
|
|
}
|
|
|
|
}
|