mirror of
https://github.com/nextcloud/server.git
synced 2026-04-28 01:28:08 -04:00
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>
This commit is contained in:
parent
441dfd6646
commit
8782b8724a
1 changed files with 20 additions and 6 deletions
|
|
@ -116,6 +116,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([
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue