mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-04 04:59:41 +00:00
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:
@@ -42,7 +42,8 @@ class AuditTrailRepository extends ServiceEntityRepository
|
||||
'occurredat' => ':occured_at',
|
||||
'user_id' => ':user_id',
|
||||
'description' => ':description',
|
||||
'targets' => ':targets',
|
||||
'main_subject' => ':main_subject',
|
||||
'subjects' => ':subjects',
|
||||
'metadata' => ':metadata',
|
||||
])
|
||||
->setParameter('id', $auditTrail->getId())
|
||||
@@ -50,9 +51,24 @@ class AuditTrailRepository extends ServiceEntityRepository
|
||||
->setParameter('occured_at', $auditTrail->getOccurredAt(), Types::DATETIMETZ_IMMUTABLE)
|
||||
->setParameter('user_id', $auditTrail->getUser()?->getId(), Types::INTEGER)
|
||||
->setParameter('description', $auditTrail->getDescription())
|
||||
->setParameter('targets', $auditTrail->getTargets(), Types::JSON)
|
||||
->setParameter('main_subject', $auditTrail->getMainSubject(), Types::JSON)
|
||||
->setParameter('subjects', $auditTrail->getSubjects(), Types::JSON)
|
||||
->setParameter('metadata', $auditTrail->getMetadata(), Types::JSON);
|
||||
|
||||
$sql->executeQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{} $criteria
|
||||
*
|
||||
* @return array<AuditTrail>
|
||||
*/
|
||||
public function findByCriteria(array $criteria, int $offset = 0, int $limit = 100): array
|
||||
{
|
||||
return $this->createQueryBuilder('audit')
|
||||
->orderBy('audit.occurredAt', 'DESC')
|
||||
->setMaxResults($limit)
|
||||
->setFirstResult($offset)
|
||||
->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user