aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2023-05-09 17:28:47 +0200
committerGitHub <noreply@github.com>2023-05-09 17:28:47 +0200
commit31302c45286c2e01649575688995907217236b8b (patch)
tree22d63b7769156fe091c0dd410aff4fa978c18258 /lib
parent972b2097d03b1ce0a82b3035fd07a64d53f34a0c (diff)
parentb67e34f78f73cfa67c8e1df76f3608c9280d7b47 (diff)
downloadnextcloud-server-31302c45286c2e01649575688995907217236b8b.tar.gz
nextcloud-server-31302c45286c2e01649575688995907217236b8b.zip
Merge pull request #38095 from nextcloud/artonge/fix/file_metadata_scan
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Metadata/FileMetadataMapper.php30
-rw-r--r--lib/private/Metadata/Provider/ExifProvider.php8
2 files changed, 34 insertions, 4 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);
+ }
+ }
}
diff --git a/lib/private/Metadata/Provider/ExifProvider.php b/lib/private/Metadata/Provider/ExifProvider.php
index 4e211e7b6c4..b1598abbbc8 100644
--- a/lib/private/Metadata/Provider/ExifProvider.php
+++ b/lib/private/Metadata/Provider/ExifProvider.php
@@ -44,11 +44,15 @@ class ExifProvider implements IMetadataProvider {
return extension_loaded('exif');
}
- /** @return array{'gps': FileMetadata, 'size': FileMetadata} */
+ /** @return array{'gps'?: FileMetadata, 'size'?: FileMetadata} */
public function execute(File $file): array {
$exifData = [];
$fileDescriptor = $file->fopen('rb');
+ if ($fileDescriptor === false) {
+ return [];
+ }
+
$data = null;
try {
// Needed to make reading exif data reliable.
@@ -107,7 +111,7 @@ class ExifProvider implements IMetadataProvider {
}
public static function getMimetypesSupported(): string {
- return '/image\/.*/';
+ return '/image\/(png|jpeg|heif|webp|tiff)/';
}
/**