Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce exif provider errors during file scan #38095

Merged
merged 2 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions lib/private/Metadata/FileMetadataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function findForGroupForFile(int $fileId, string $groupName): FileMetadat
$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);
Expand Down Expand Up @@ -111,7 +111,7 @@ public function clear(int $fileId): void {
/**
* 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
Expand Down Expand Up @@ -148,4 +148,30 @@ public function update(Entity $entity): FileMetadata {

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());
artonge marked this conversation as resolved.
Show resolved Hide resolved
} catch (\Throwable) {
$existingEntity = null;
}

if ($existingEntity !== null) {
if ($entity->getValue() !== $existingEntity->getValue()) {
return $this->update($entity);
} else {
return $existingEntity;
}
} else {
return parent::insertOrUpdate($entity);
}
}
}
8 changes: 6 additions & 2 deletions lib/private/Metadata/Provider/ExifProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ public static function isAvailable(): bool {
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.
Expand Down Expand Up @@ -107,7 +111,7 @@ public function execute(File $file): array {
}

public static function getMimetypesSupported(): string {
return '/image\/.*/';
return '/image\/(png|jpeg|heif|webp|tiff)/';
}

/**
Expand Down