mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-02 04:15:52 -05:00
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
38 lines
1.4 KiB
PHP
38 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Pterodactyl\Actions\Eggs\Scripts;
|
|
|
|
use Illuminate\Support\Arr;
|
|
use Pterodactyl\Contracts\Eggs\UpdatesEggInstallScripts;
|
|
use Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException;
|
|
use Pterodactyl\Models\Egg;
|
|
use Pterodactyl\Support\JsonValueGuard;
|
|
|
|
final class UpdateInstallScript implements UpdatesEggInstallScripts
|
|
{
|
|
/**
|
|
* Modify the install script for a given Egg.
|
|
*
|
|
* @param ModelAttributes $data validated install script attributes
|
|
*
|
|
* @throws InvalidCopyFromException
|
|
*/
|
|
public function update(Egg $egg, array $data): void
|
|
{
|
|
$copyFrom = JsonValueGuard::nullableInteger(Arr::get($data, 'copy_script_from'));
|
|
if ($copyFrom !== null && ! Egg::query()->scriptSources()->whereKey($copyFrom)->exists()) {
|
|
throw new InvalidCopyFromException(trans('exceptions.egg.invalid_copy_id'));
|
|
}
|
|
|
|
$egg->update([
|
|
'script_install' => JsonValueGuard::nullableString(Arr::get($data, 'script_install')),
|
|
'script_is_privileged' => JsonValueGuard::boolean(Arr::get($data, 'script_is_privileged', true)),
|
|
'script_entry' => JsonValueGuard::string(Arr::get($data, 'script_entry')),
|
|
'script_container' => JsonValueGuard::string(Arr::get($data, 'script_container')),
|
|
'copy_script_from' => $copyFrom,
|
|
]);
|
|
}
|
|
}
|