misc_pterodactyl-panel/app/Services/Eggs/Scripts/InstallScriptService.php

42 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace Pterodactyl\Services\Eggs\Scripts;
use Pterodactyl\Models\Egg;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException;
class InstallScriptService
{
/**
* InstallScriptService constructor.
*/
public function __construct(protected EggRepositoryInterface $repository)
{
}
/**
* Modify the install script for a given Egg.
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
2017-08-12 21:30:27 +00:00
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException
*/
public function handle(Egg $egg, array $data): void
{
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)) {
throw new InvalidCopyFromException(trans('exceptions.nest.egg.invalid_copy_id'));
}
}
2018-01-05 22:33:50 +00:00
$this->repository->withoutFreshModel()->update($egg->id, [
'script_install' => array_get($data, 'script_install'),
'script_is_privileged' => array_get($data, 'script_is_privileged', 1),
'script_entry' => array_get($data, 'script_entry'),
'script_container' => array_get($data, 'script_container'),
'copy_script_from' => array_get($data, 'copy_script_from'),
]);
}
}