aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2023-05-05 12:57:55 +0200
committerLouis Chemineau <louis@chmn.me>2023-05-09 11:43:56 +0200
commit157be42a83e7c43464462b7e8cbf0b2bb9a251ab (patch)
tree3ff753570506852b0cdb5a63b1074597a9ea0fa5 /lib/private
parenta1ed1db01b1e6cb798277baddfa41458631595c6 (diff)
downloadnextcloud-server-157be42a83e7c43464462b7e8cbf0b2bb9a251ab.tar.gz
nextcloud-server-157be42a83e7c43464462b7e8cbf0b2bb9a251ab.zip
Prevent error on files scan if metadata exists
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Metadata/FileMetadataMapper.php30
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/private/Metadata/FileMetadataMapper.php b/lib/private/Metadata/FileMetadataMapper.php
index 594ac5eafba..003ab13126e 100644
--- a/lib/private/Metadata/FileMetadataMapper.php
+++ b/lib/private/Metadata/FileMetadataMapper.php
@@ -60,7 +60,7 @@ class FileMetadataMapper extends QBMapper {
$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);
@@ -111,7 +111,7 @@ class FileMetadataMapper extends QBMapper {
/**
* 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
@@ -148,4 +148,30 @@ class FileMetadataMapper extends QBMapper {
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);
+ }
+ }
}