V2.1: Kanalfähigkeiten, Ausführungsvarianten, Dokumentenentkopplung, Portalbestätigung

Modellwahl über Kanalfähigkeiten mit erklärten Einschränkungen, Abgleich alter Werte,
Ausführungsvarianten je Modul, getrennte Vertrags-/Buchungsinformation, Warten auf
die Portalbestätigung mit Eskalation und Wiederaufnahme (Fälle C und D getestet).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-05 07:54:11 +01:00
1 parent ef1635e59a
commit 8442d0a3d8
62 files changed
+1818 -69

No files matched your search

+43 -11
View File
@@ -5,40 +5,59 @@
use App\Enums\IntakeKind;
use App\Enums\ProcessSetting;
use App\Models\Channel;
use App\Process\ChannelCapabilities;
use App\Process\ChannelProcessConfiguration;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException;
/**
* Saves the process of a channel for one intake kind (Kanal › Ablauf, docs/Prozessarchitektur/Architektur/03): the
* chosen model and variant, the step switches and the step settings – in channels.process_overrides[intake], next to
* the existing settings, so their inheritance stays as it is. Refuses everything the configuration does not admit
* (mandatory steps off, responsibilities the model does not allow, tester-only variants). Changes apply to new cases
* only (decision E3): running cases keep their frozen plan.
* Saves the process of a channel for one intake kind (Kanal › Ablauf, docs/Prozessarchitektur/Architektur/03 and V2.1/02):
* the confirmed capabilities of the portal, the chosen model and variant, the step switches and the step settings – in
* channels.settings and channels.process_overrides[intake], next to the existing settings, so their inheritance stays
* as it is. Refuses everything the configuration does not admit (mandatory steps off, responsibilities the model does not
* allow, a model the capabilities do not fit, tester-only variants). Stored settings that the chosen model overrides are
* removed only after the landlord confirmed that, and the change is kept in the channel's history. Changes apply to new
* cases only (decision E3): running cases keep their frozen plan.
*/
class ConfigureChannelProcess
{
public function __construct(private ChannelProcessConfiguration $configuration) {}
public const HISTORY_LIMIT = 20;
public function __construct(private ChannelProcessConfiguration $configuration, private ChannelCapabilities $capabilities) {}
/**
* @param array{model: string, variant?: string, steps?: array<string, array{on?: bool}>, settings?: array<string, mixed>} $draft
* @param array{model: string, variant?: string, steps?: array<string, array{on?: bool}>, settings?: array<string, mixed>, capabilities?: array<string, bool|string|null>} $draft
* @param bool $acknowledgeConflicts the landlord confirmed that stored settings the model overrides are removed
*
* @throws ValidationException
*/
public function handle(Channel $channel, IntakeKind $intake, array $draft, ?string $by = null): Channel
public function handle(Channel $channel, IntakeKind $intake, array $draft, ?string $by = null, bool $acknowledgeConflicts = false): 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 {
$conflicts = $this->configuration->conflicts($channel, $intake, (string) $draft['model']);
if ($conflicts !== [] && ! $acknowledgeConflicts) {
throw ValidationException::withMessages(['process' => [
'Bisherige Einstellungen widersprechen dem gewählten Modell und würden still überstimmt. Bitte ausdrücklich bestätigen, dass sie entfernt werden:',
...array_column($conflicts, 'text'),
]]);
}
return DB::transaction(function () use ($channel, $intake, $draft, $by, $conflicts): Channel {
$channel = Channel::query()->lockForUpdate()->findOrFail($channel->id);
$by ??= auth()->user()?->name;
$overrides = (array) ($channel->process_overrides ?? []);
$current = (array) ($overrides[$intake->value] ?? []);
$removed = array_map(fn (array $conflict): string => $conflict['setting']->value, $conflicts);
$settings = [];
foreach (ProcessSetting::cases() as $setting) {
if (in_array($setting->value, $removed, true)) {
continue;
}
$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;
@@ -58,9 +77,22 @@ public function handle(Channel $channel, IntakeKind $intake, array $draft, ?stri
'variant' => $draft['variant'] ?? 'standard',
'steps' => $steps,
'configured_at' => now()->toIso8601String(),
'configured_by' => $by ?? auth()->user()?->name,
'configured_by' => $by,
];
$channel->update(['process_overrides' => $overrides]);
$channelSettings = (array) ($channel->settings ?? []);
$changes = [];
if (! $channel->isWebsite() && filled($draft['capabilities'] ?? null)) {
$confirmed = $this->capabilities->confirm($channel, (array) $draft['capabilities'], $by);
$channelSettings['capabilities'] = $confirmed['capabilities'];
$changes = $confirmed['changes'];
}
$channelSettings['process_history'] = array_slice([...(array) ($channelSettings['process_history'] ?? []), [
'at' => now()->toIso8601String(), 'by' => $by, 'intake' => $intake->value, 'model' => $draft['model'], 'variant' => $draft['variant'] ?? 'standard',
'capabilities' => $changes, 'removed_settings' => array_map(fn (array $conflict): string => $conflict['text'], $conflicts),
]], -self::HISTORY_LIMIT);
$channel->update(['process_overrides' => $overrides, 'settings' => $channelSettings]);
return $channel;
});