summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Metadata/FileMetadata.php16
-rw-r--r--lib/private/Metadata/FileMetadataMapper.php8
-rw-r--r--lib/private/Metadata/MetadataManager.php3
-rw-r--r--lib/private/Metadata/Provider/ExifProvider.php8
4 files changed, 23 insertions, 12 deletions
diff --git a/lib/private/Metadata/FileMetadata.php b/lib/private/Metadata/FileMetadata.php
index 9ad0f9d35c6..a9808a86998 100644
--- a/lib/private/Metadata/FileMetadata.php
+++ b/lib/private/Metadata/FileMetadata.php
@@ -28,16 +28,24 @@ use OCP\DB\Types;
/**
* @method string getGroupName()
* @method void setGroupName(string $groupName)
- * @method array getMetadata()
- * @method void setMetadata(array $metadata)
+ * @method string getValue()
+ * @method void setValue(string $value)
* @see \OC\Core\Migrations\Version240000Date20220404230027
*/
class FileMetadata extends Entity {
protected ?string $groupName = null;
- protected ?array $metadata = null;
+ protected ?string $value = null;
public function __construct() {
$this->addType('groupName', 'string');
- $this->addType('metadata', Types::JSON);
+ $this->addType('value', Types::STRING);
+ }
+
+ public function getDecodedValue(): array {
+ return json_decode($this->getValue(), true) ?? [];
+ }
+
+ public function setArrayAsValue(array $value): void {
+ $this->setValue(json_encode($value, JSON_THROW_ON_ERROR));
}
}
diff --git a/lib/private/Metadata/FileMetadataMapper.php b/lib/private/Metadata/FileMetadataMapper.php
index f8f8df4bf3b..f3120e5e515 100644
--- a/lib/private/Metadata/FileMetadataMapper.php
+++ b/lib/private/Metadata/FileMetadataMapper.php
@@ -89,7 +89,7 @@ class FileMetadataMapper extends QBMapper {
continue;
}
$empty = new FileMetadata();
- $empty->setMetadata([]);
+ $empty->setValue('');
$empty->setGroupName($groupName);
$empty->setId($id);
$metadata[$id] = $empty;
@@ -132,13 +132,13 @@ class FileMetadataMapper extends QBMapper {
$idType = $this->getParameterTypeForProperty($entity, 'id');
$groupNameType = $this->getParameterTypeForProperty($entity, 'groupName');
- $metadataValue = $entity->getMetadata();
- $metadataType = $this->getParameterTypeForProperty($entity, 'metadata');
+ $value = $entity->getValue();
+ $valueType = $this->getParameterTypeForProperty($entity, 'value');
$qb = $this->db->getQueryBuilder();
$qb->update($this->tableName)
- ->set('metadata', $qb->createNamedParameter($metadataValue, $metadataType))
+ ->set('value', $qb->createNamedParameter($value, $valueType))
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, $idType)))
->andWhere($qb->expr()->eq('group_name', $qb->createNamedParameter($groupName, $groupNameType)))
->executeStatement();
diff --git a/lib/private/Metadata/MetadataManager.php b/lib/private/Metadata/MetadataManager.php
index 77407a2f529..6d96ff1ab68 100644
--- a/lib/private/Metadata/MetadataManager.php
+++ b/lib/private/Metadata/MetadataManager.php
@@ -78,6 +78,9 @@ class MetadataManager implements IMetadataManager {
$this->fileMetadataMapper->clear($fileId);
}
+ /**
+ * @return array<int, FileMetadata>
+ */
public function fetchMetadataFor(string $group, array $fileIds): array {
return $this->fileMetadataMapper->findForGroupForFiles($fileIds, $group);
}
diff --git a/lib/private/Metadata/Provider/ExifProvider.php b/lib/private/Metadata/Provider/ExifProvider.php
index ae2c57ba7e5..4e211e7b6c4 100644
--- a/lib/private/Metadata/Provider/ExifProvider.php
+++ b/lib/private/Metadata/Provider/ExifProvider.php
@@ -65,12 +65,12 @@ class ExifProvider implements IMetadataProvider {
$size = new FileMetadata();
$size->setGroupName('size');
$size->setId($file->getId());
- $size->setMetadata([]);
+ $size->setArrayAsValue([]);
if (!$data) {
$sizeResult = getimagesizefromstring($file->getContent());
if ($sizeResult !== false) {
- $size->setMetadata([
+ $size->setArrayAsValue([
'width' => $sizeResult[0],
'height' => $sizeResult[1],
]);
@@ -79,7 +79,7 @@ class ExifProvider implements IMetadataProvider {
}
} elseif (array_key_exists('COMPUTED', $data)) {
if (array_key_exists('Width', $data['COMPUTED']) && array_key_exists('Height', $data['COMPUTED'])) {
- $size->setMetadata([
+ $size->setArrayAsValue([
'width' => $data['COMPUTED']['Width'],
'height' => $data['COMPUTED']['Height'],
]);
@@ -95,7 +95,7 @@ class ExifProvider implements IMetadataProvider {
$gps = new FileMetadata();
$gps->setGroupName('gps');
$gps->setId($file->getId());
- $gps->setMetadata([
+ $gps->setArrayAsValue([
'latitude' => $this->gpsDegreesToDecimal($data['GPS']['GPSLatitude'], $data['GPS']['GPSLatitudeRef']),
'longitude' => $this->gpsDegreesToDecimal($data['GPS']['GPSLongitude'], $data['GPS']['GPSLongitudeRef']),
]);