Files

33 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2026-10-05 18:10:18 -04:00
<?php
declare(strict_types=1);
namespace Pterodactyl\Actions\Eggs\Variables;
2026-10-11 23:29:38 -04:00
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Validator;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Contracts\Eggs\UpdatesEggVariables;
2026-10-11 08:19:22 -04:00
use Pterodactyl\Models\Egg;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\EggVariable;
final class UpdateEggVariable implements UpdatesEggVariables
{
2026-10-11 08:19:22 -04:00
public function update(EggVariable $variable, array $input): EggVariable
2026-10-05 18:10:18 -04:00
{
2026-10-11 08:19:22 -04:00
$egg = Egg::query()->findOrFail($variable->egg_id);
2026-10-11 23:29:38 -04:00
$validated = Validator::validate($input, CreateEggVariable::rules($egg, $variable));
$options = Arr::array($validated, 'options', []);
2026-10-11 08:19:22 -04:00
2026-10-11 23:29:38 -04:00
// A variable given no description gets a blank one, and the options set whether users
// can see and edit it; any other option is ignored.
$variable->update([
...Arr::except($validated, 'options'),
'description' => $validated['description'] ?? '',
'user_viewable' => in_array('user_viewable', $options, true),
'user_editable' => in_array('user_editable', $options, true),
]);
2026-10-08 19:17:30 -04:00
return $variable;
2026-10-05 18:10:18 -04:00
}
}