Merge pull request #51690 from nextcloud/backport/51649/stable31

[stable31] fix(systemtags): Dispatch events when bulk assigning system tags
pull/51699/head
Kate 2025-03-25 13:59:14 +07:00 committed by GitHub
commit e8f010571e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 0 deletions

@ -284,6 +284,9 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
* {@inheritdoc}
*/
public function setObjectIdsForTag(string $tagId, string $objectType, array $objectIds): void {
$currentObjectIds = $this->getObjectIdsForTags($tagId, $objectType);
$removedObjectIds = array_diff($currentObjectIds, $objectIds);
$addedObjectIds = array_diff($objectIds, $currentObjectIds);
$this->connection->beginTransaction();
$query = $this->connection->getQueryBuilder();
$query->delete(self::RELATION_TABLE)
@ -292,6 +295,15 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
->executeStatement();
$this->connection->commit();
foreach ($removedObjectIds as $objectId) {
$this->dispatcher->dispatch(MapperEvent::EVENT_UNASSIGN, new MapperEvent(
MapperEvent::EVENT_UNASSIGN,
$objectType,
(string)$objectId,
[(int)$tagId]
));
}
if (empty($objectIds)) {
return;
}
@ -312,6 +324,14 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
$this->updateEtagForTags([$tagId]);
$this->connection->commit();
foreach ($addedObjectIds as $objectId) {
$this->dispatcher->dispatch(MapperEvent::EVENT_ASSIGN, new MapperEvent(
MapperEvent::EVENT_ASSIGN,
$objectType,
(string)$objectId,
[(int)$tagId]
));
}
}
/**