Skip to content

Commit 31302c4

Browse files
authored
Merge pull request #38095 from nextcloud/artonge/fix/file_metadata_scan
2 parents 972b209 + b67e34f commit 31302c4

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

lib/private/Metadata/FileMetadataMapper.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function findForGroupForFile(int $fileId, string $groupName): FileMetadat
6060
$qb = $this->db->getQueryBuilder();
6161
$qb->select('*')
6262
->from($this->getTableName())
63-
->where($qb->expr()->eq('id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT_ARRAY)))
63+
->where($qb->expr()->eq('id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)))
6464
->andWhere($qb->expr()->eq('group_name', $qb->createNamedParameter($groupName, IQueryBuilder::PARAM_STR)));
6565

6666
return $this->findEntity($qb);
@@ -111,7 +111,7 @@ public function clear(int $fileId): void {
111111
/**
112112
* Updates an entry in the db from an entity
113113
*
114-
* @param Entity $entity the entity that should be created
114+
* @param FileMetadata $entity the entity that should be created
115115
* @return FileMetadata the saved entity with the set id
116116
* @throws Exception
117117
* @throws \InvalidArgumentException if entity has no id
@@ -148,4 +148,30 @@ public function update(Entity $entity): FileMetadata {
148148

149149
return $entity;
150150
}
151+
152+
/**
153+
* Override the insertOrUpdate as we could be in a transaction in which case we can not afford on error.
154+
*
155+
* @param FileMetadata $entity the entity that should be created/updated
156+
* @return FileMetadata the saved entity with the (new) id
157+
* @throws Exception
158+
* @throws \InvalidArgumentException if entity has no id
159+
*/
160+
public function insertOrUpdate(Entity $entity): FileMetadata {
161+
try {
162+
$existingEntity = $this->findForGroupForFile($entity->getId(), $entity->getGroupName());
163+
} catch (\Throwable) {
164+
$existingEntity = null;
165+
}
166+
167+
if ($existingEntity !== null) {
168+
if ($entity->getValue() !== $existingEntity->getValue()) {
169+
return $this->update($entity);
170+
} else {
171+
return $existingEntity;
172+
}
173+
} else {
174+
return parent::insertOrUpdate($entity);
175+
}
176+
}
151177
}

lib/private/Metadata/Provider/ExifProvider.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ public static function isAvailable(): bool {
4444
return extension_loaded('exif');
4545
}
4646

47-
/** @return array{'gps': FileMetadata, 'size': FileMetadata} */
47+
/** @return array{'gps'?: FileMetadata, 'size'?: FileMetadata} */
4848
public function execute(File $file): array {
4949
$exifData = [];
5050
$fileDescriptor = $file->fopen('rb');
5151

52+
if ($fileDescriptor === false) {
53+
return [];
54+
}
55+
5256
$data = null;
5357
try {
5458
// Needed to make reading exif data reliable.
@@ -107,7 +111,7 @@ public function execute(File $file): array {
107111
}
108112

109113
public static function getMimetypesSupported(): string {
110-
return '/image\/.*/';
114+
return '/image\/(png|jpeg|heif|webp|tiff)/';
111115
}
112116

113117
/**

0 commit comments

Comments
 (0)