@@ -284,6 +284,9 @@ function (ISystemTag $tag) {
284284 * {@inheritdoc}
285285 */
286286 public function setObjectIdsForTag (string $ tagId , string $ objectType , array $ objectIds ): void {
287+ $ currentObjectIds = $ this ->getObjectIdsForTags ($ tagId , $ objectType );
288+ $ removedObjectIds = array_diff ($ currentObjectIds , $ objectIds );
289+ $ addedObjectIds = array_diff ($ objectIds , $ currentObjectIds );
287290 $ this ->connection ->beginTransaction ();
288291 $ query = $ this ->connection ->getQueryBuilder ();
289292 $ query ->delete (self ::RELATION_TABLE )
@@ -292,6 +295,15 @@ public function setObjectIdsForTag(string $tagId, string $objectType, array $obj
292295 ->executeStatement ();
293296 $ this ->connection ->commit ();
294297
298+ foreach ($ removedObjectIds as $ objectId ) {
299+ $ this ->dispatcher ->dispatch (MapperEvent::EVENT_UNASSIGN , new MapperEvent (
300+ MapperEvent::EVENT_UNASSIGN ,
301+ $ objectType ,
302+ (string ) $ objectId ,
303+ [$ tagId ]
304+ ));
305+ }
306+
295307 if (empty ($ objectIds )) {
296308 return ;
297309 }
@@ -312,6 +324,14 @@ public function setObjectIdsForTag(string $tagId, string $objectType, array $obj
312324
313325 $ this ->updateEtagForTags ([$ tagId ]);
314326 $ this ->connection ->commit ();
327+ foreach ($ addedObjectIds as $ objectId ) {
328+ $ this ->dispatcher ->dispatch (MapperEvent::EVENT_ASSIGN , new MapperEvent (
329+ MapperEvent::EVENT_ASSIGN ,
330+ $ objectType ,
331+ (string ) $ objectId ,
332+ [$ tagId ]
333+ ));
334+ }
315335 }
316336
317337 /**
0 commit comments