Files
pterodactyl-panel/app/Actions/Eggs/Scripts/UpdateInstallScript.php
2026-10-12 05:18:58 -04:00

42 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Pterodactyl\Actions\Eggs\Scripts;
use Illuminate\Support\Facades\Validator;
use Pterodactyl\Contracts\Eggs\UpdatesEggInstallScripts;
use Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException;
use Pterodactyl\Models\Egg;
final class UpdateInstallScript implements UpdatesEggInstallScripts
{
/** @return NormalizedValidationRules */
public static function rules(): array
{
return [
'script_install' => ['sometimes', 'nullable', 'string'],
'script_is_privileged' => ['sometimes', 'required', 'boolean'],
'script_entry' => ['sometimes', 'required', 'string'],
'script_container' => ['sometimes', 'required', 'string'],
'copy_script_from' => ['sometimes', 'nullable', 'integer'],
];
}
public function update(Egg $egg, array $input): Egg
{
$attributes = Validator::validate($input, self::rules());
// Blank strings are null, as they are in a request, so a blank script or copy source is cleared.
$attributes = array_map(fn (mixed $value): mixed => is_string($value) && blank($value) ? null : $value, $attributes);
$copyFrom = $attributes['copy_script_from'] ?? null;
if ($copyFrom !== null && ! Egg::query()->scriptSources()->whereKey($copyFrom)->exists()) {
throw new InvalidCopyFromException(trans('exceptions.egg.invalid_copy_id'));
}
$egg->update($attributes);
return $egg;
}
}