Refactor subject conversion handling and enhance audit logging

- Replaced `Subject|array` return types with `SubjectBag` in `SubjectConverterInterface` for more robust handling.
- Updated `getSubjectsForEntity` to include an optional `$includeAssociated` parameter for finer control over associated subject resolution.
- Refactored `AuditEvent` to differentiate `mainSubject` from associated subjects, improving clarity in audit logging.
- Introduced database schema changes to add `main_subject` and `subjects` columns in the `chill_main_audit_trail` table.
- Added `SubjectBag` class for grouped subject management and implemented deduplication logic.
- Updated all converters and test cases to use the new `SubjectBag` approach, ensuring compatibility.
- Improved event dispatching in controllers to utilize the updated `AuditEvent` structure and refined metadata handling.
This commit is contained in:
2026-02-13 16:56:04 +01:00
parent 443ee4cb1a
commit 32c5f21438
20 changed files with 332 additions and 84 deletions

View File

@@ -34,13 +34,10 @@ final readonly class AuditEvent2Trail implements AuditEvent2TrailInterface
$event->description->trans($this->translator)
: $event->description;
$subjects = array_reduce(
$event->subjects,
function (array $carry, mixed $item): array {
return array_merge($carry, $this->subjectConverterManager->getSubjectsForEntity($item));
},
[]
);
$subjectBag = $this->subjectConverterManager->getSubjectsForEntity($event->mainSubject, true);
foreach ($event->subjects as $target) {
$subjectBag->append($this->subjectConverterManager->getSubjectsForEntity($target, false));
}
$user = $this->security->getUser();
@@ -50,7 +47,8 @@ final readonly class AuditEvent2Trail implements AuditEvent2TrailInterface
$this->clock->now(),
$user instanceof User ? $user : null,
$description,
array_map(fn (Subject $subject) => $subject->asArray(), $subjects),
$subjectBag->subject->asArray(),
array_map(fn (Subject $subject) => $subject->asArray(), $subjectBag->associatedSubjects),
$event->metadata,
);
}