2026-10-05 18:10:18 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Pterodactyl\Actions\Eggs\Scripts;
|
|
|
|
|
|
2026-10-11 08:19:22 -04:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Contracts\Eggs\UpdatesEggInstallScripts;
|
|
|
|
|
use Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException;
|
|
|
|
|
use Pterodactyl\Models\Egg;
|
|
|
|
|
|
|
|
|
|
final class UpdateInstallScript implements UpdatesEggInstallScripts
|
|
|
|
|
{
|
2026-10-11 23:50:53 -04:00
|
|
|
/** @return NormalizedValidationRules */
|
2026-10-11 08:19:22 -04:00
|
|
|
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
|
2026-10-05 18:10:18 -04:00
|
|
|
{
|
2026-10-11 23:29:38 -04:00
|
|
|
$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);
|
2026-10-11 08:19:22 -04:00
|
|
|
|
|
|
|
|
$copyFrom = $attributes['copy_script_from'] ?? null;
|
2026-10-05 18:10:18 -04:00
|
|
|
if ($copyFrom !== null && ! Egg::query()->scriptSources()->whereKey($copyFrom)->exists()) {
|
|
|
|
|
throw new InvalidCopyFromException(trans('exceptions.egg.invalid_copy_id'));
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-11 08:19:22 -04:00
|
|
|
$egg->update($attributes);
|
2026-10-08 19:17:30 -04:00
|
|
|
|
|
|
|
|
return $egg;
|
2026-10-05 18:10:18 -04:00
|
|
|
}
|
|
|
|
|
}
|