, settings?: array} $draft * * @throws ValidationException */ public function handle(Channel $channel, IntakeKind $intake, array $draft, ?string $by = null): Channel { $problems = $this->configuration->problems($channel, $intake, $draft); if ($problems !== []) { throw ValidationException::withMessages(['process' => $problems]); } return DB::transaction(function () use ($channel, $intake, $draft, $by): Channel { $channel = Channel::query()->lockForUpdate()->findOrFail($channel->id); $overrides = (array) ($channel->process_overrides ?? []); $current = (array) ($overrides[$intake->value] ?? []); $settings = []; foreach (ProcessSetting::cases() as $setting) { $value = array_key_exists($setting->value, (array) ($draft['settings'] ?? [])) ? $setting->normalize($draft['settings'][$setting->value]) : $setting->normalize($current[$setting->value] ?? null); if ($value !== null && in_array($intake, $setting->channelIntakes(), true)) { $settings[$setting->value] = $value; } } $steps = []; foreach ((array) ($draft['steps'] ?? []) as $module => $step) { if (array_key_exists('on', $step) && $step['on'] === false) { $steps[$module] = ['on' => false]; } } $overrides[$intake->value] = [ ...$settings, 'model' => $draft['model'], 'variant' => $draft['variant'] ?? 'standard', 'steps' => $steps, 'configured_at' => now()->toIso8601String(), 'configured_by' => $by ?? auth()->user()?->name, ]; $channel->update(['process_overrides' => $overrides]); return $channel; }); } }