aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryemkareems <yemkareems@gmail.com>2024-05-30 14:39:58 +0530
committerMarcel Klehr <mklehr@gmx.net>2024-06-19 12:52:46 +0200
commit8782b8724aa01ea7dbce91817b352613726cd133 (patch)
tree09e6ced3271703661b998356750aa8c053e086b0
parent441dfd6646ed5491610f4a7d02afda08e2748fc2 (diff)
downloadnextcloud-server-8782b8724aa01ea7dbce91817b352613726cd133.tar.gz
nextcloud-server-8782b8724aa01ea7dbce91817b352613726cd133.zip
fix: do a select in systemtag_object_mapping to see if tag exists already in db. if it does not exist alone insert the same or else do nothing
Signed-off-by: yemkareems <yemkareems@gmail.com>
-rw-r--r--lib/private/SystemTag/SystemTagObjectMapper.php26
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/private/SystemTag/SystemTagObjectMapper.php b/lib/private/SystemTag/SystemTagObjectMapper.php
index 58a9e6a23da..78e21d0cb27 100644
--- a/lib/private/SystemTag/SystemTagObjectMapper.php
+++ b/lib/private/SystemTag/SystemTagObjectMapper.php
@@ -117,6 +117,15 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
$this->assertTagsExist($tagIds);
$query = $this->connection->getQueryBuilder();
+ $query->select('systemtagid')
+ ->from(self::RELATION_TABLE)
+ ->where($query->expr()->in('systemtagid', $query->createNamedParameter($tagIds, IQueryBuilder::PARAM_INT_ARRAY)))
+ ->andWhere($query->expr()->eq('objecttype', $query->createNamedParameter($objectType)))
+ ->andWhere($query->expr()->eq('objectid', $query->createNamedParameter($objId)));
+ $result = $query->executeQuery();
+ $rows = $result->fetchAll();
+
+ $query = $this->connection->getQueryBuilder();
$query->insert(self::RELATION_TABLE)
->values([
'objectid' => $query->createNamedParameter($objId),
@@ -126,12 +135,17 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
$tagsAssigned = [];
foreach ($tagIds as $tagId) {
- try {
- $query->setParameter('tagid', $tagId);
- $query->execute();
- $tagsAssigned[] = $tagId;
- } catch (UniqueConstraintViolationException $e) {
- // ignore existing relations
+ if(!in_array($tagId, array_column($rows, 'systemtagid'))) {
+ // tag not in db so create new one
+ try {
+ $query->setParameter('tagid', $tagId);
+ $query->execute();
+ $tagsAssigned[] = $tagId;
+ } catch (UniqueConstraintViolationException $e) {
+ // ignore existing relations
+ }
+ } else {
+ //tag exists already don't insert
}
}