$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
- ->where($qb->expr()->eq('id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT_ARRAY)))
+ ->where($qb->expr()->eq('id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('group_name', $qb->createNamedParameter($groupName, IQueryBuilder::PARAM_STR)));
return $this->findEntity($qb);
/**
* Updates an entry in the db from an entity
*
- * @param Entity $entity the entity that should be created
+ * @param FileMetadata $entity the entity that should be created
* @return FileMetadata the saved entity with the set id
* @throws Exception
* @throws \InvalidArgumentException if entity has no id
return $entity;
}
+
+ /**
+ * Override the insertOrUpdate as we could be in a transaction in which case we can not afford on error.
+ *
+ * @param FileMetadata $entity the entity that should be created/updated
+ * @return FileMetadata the saved entity with the (new) id
+ * @throws Exception
+ * @throws \InvalidArgumentException if entity has no id
+ */
+ public function insertOrUpdate(Entity $entity): FileMetadata {
+ try {
+ $existingEntity = $this->findForGroupForFile($entity->getId(), $entity->getGroupName());
+ } catch (\Throwable) {
+ $existingEntity = null;
+ }
+
+ if ($existingEntity !== null) {
+ if ($entity->getValue() !== $existingEntity->getValue()) {
+ return $this->update($entity);
+ } else {
+ return $existingEntity;
+ }
+ } else {
+ return parent::insertOrUpdate($entity);
+ }
+ }
}