@@ -42,11 +42,98 @@ public function format($subject, array $change_set): ?string
4242
4343 case IAuditStrategy::EVENT_ENTITY_DELETION :
4444 return sprintf ("Attendee (%s) '%s' deleted by user %s " , $ id , $ name , $ this ->getUserInfo ());
45+
46+ case IAuditStrategy::EVENT_COLLECTION_MANYTOMANY_UPDATE :
47+ return $ this ->handleManyToManyCollection ($ subject , $ change_set , $ id , $ name , false );
48+
49+ case IAuditStrategy::EVENT_COLLECTION_MANYTOMANY_DELETE :
50+ return $ this ->handleManyToManyCollection ($ subject , $ change_set , $ id , $ name , true );
4551 }
4652 } catch (\Exception $ ex ) {
4753 Log::warning ("SummitAttendeeAuditLogFormatter error: " . $ ex ->getMessage ());
4854 }
4955
5056 return null ;
5157 }
58+
59+ private function handleManyToManyCollection (SummitAttendee $ subject , array $ change_set , $ id , $ name , bool $ isDeletion ): ?string
60+ {
61+ if (!isset ($ change_set ['collection ' ]) || !isset ($ change_set ['uow ' ])) {
62+ return null ;
63+ }
64+
65+ $ col = $ change_set ['collection ' ];
66+ $ uow = $ change_set ['uow ' ];
67+
68+ $ collectionData = $ this ->processCollection ($ subject , $ col , $ uow , $ isDeletion );
69+ if (!$ collectionData ) {
70+ return null ;
71+ }
72+
73+ return $ isDeletion
74+ ? $ this ->formatManyToManyDelete ($ subject , $ collectionData , $ id , $ name )
75+ : $ this ->formatManyToManyUpdate ($ subject , $ collectionData , $ id , $ name );
76+ }
77+
78+ private function formatManyToManyUpdate (SummitAttendee $ subject , array $ collectionData , $ id , $ name ): ?string
79+ {
80+ try {
81+ $ field = $ collectionData ['field ' ] ?? 'unknown ' ;
82+ $ targetEntity = $ collectionData ['target_entity ' ] ?? 'unknown ' ;
83+ $ added_ids = $ collectionData ['added_ids ' ] ?? [];
84+ $ removed_ids = $ collectionData ['removed_ids ' ] ?? [];
85+
86+ $ idsPart = '' ;
87+ if (!empty ($ added_ids )) {
88+ $ idsPart .= 'Added IDs: ' . json_encode ($ added_ids );
89+ }
90+ if (!empty ($ removed_ids )) {
91+ $ idsPart .= (!empty ($ added_ids ) ? ', ' : '' ) . 'Removed IDs: ' . json_encode ($ removed_ids );
92+ }
93+ if (empty ($ idsPart )) {
94+ $ idsPart = 'No changes ' ;
95+ }
96+
97+ $ description = sprintf (
98+ "Attendee (%s) '%s', Field: %s, Target: %s, %s, by user %s " ,
99+ $ id ,
100+ $ name ,
101+ $ field ,
102+ class_basename ($ targetEntity ),
103+ $ idsPart ,
104+ $ this ->getUserInfo ()
105+ );
106+
107+ return $ description ;
108+
109+ } catch (\Exception $ ex ) {
110+ Log::warning ("SummitAttendeeAuditLogFormatter::formatManyToManyUpdate error: " . $ ex ->getMessage ());
111+ return sprintf ("Attendee (%s) '%s' association updated by user %s " , $ id , $ name , $ this ->getUserInfo ());
112+ }
113+ }
114+
115+ private function formatManyToManyDelete (SummitAttendee $ subject , array $ collectionData , $ id , $ name ): ?string
116+ {
117+ try {
118+ $ field = $ collectionData ['field ' ] ?? 'unknown ' ;
119+ $ targetEntity = $ collectionData ['target_entity ' ] ?? 'unknown ' ;
120+ $ removed_ids = $ collectionData ['removed_ids ' ] ?? [];
121+
122+ $ description = sprintf (
123+ "Attendee (%s) '%s' association deleted: Field: %s, Target: %s, Cleared IDs: %s, by user %s " ,
124+ $ id ,
125+ $ name ,
126+ $ field ,
127+ class_basename ($ targetEntity ),
128+ json_encode ($ removed_ids ),
129+ $ this ->getUserInfo ()
130+ );
131+
132+ return $ description ;
133+
134+ } catch (\Exception $ ex ) {
135+ Log::warning ("SummitAttendeeAuditLogFormatter::formatManyToManyDelete error: " . $ ex ->getMessage ());
136+ return sprintf ("Attendee (%s) '%s' association deleted by user %s " , $ id , $ name , $ this ->getUserInfo ());
137+ }
138+ }
52139}
0 commit comments