diff --git a/composer.json b/composer.json index baf14593d..27c36f034 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "require-dev": { "bamarni/composer-bin-plugin": "^1.8", "nextcloud/coding-standard": "1.0", - "nextcloud/ocp": "dev-master", + "nextcloud/ocp": "dev-stable26", "phpunit/phpunit": "^9", "sabre/dav": "^4.2.1", "vimeo/psalm": "^4.22" @@ -38,4 +38,4 @@ "require": { "hexogen/kdtree": "^0.2.5" } -} +} \ No newline at end of file diff --git a/composer.lock b/composer.lock index ccd3f39d1..7f64529db 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "bad8cd6db2697a29fb83af680ef4523e", + "content-hash": "d408820b3a7d04573219b1eb1ac7f48b", "packages": [ { "name": "hexogen/kdtree", @@ -1231,26 +1231,24 @@ }, { "name": "nextcloud/ocp", - "version": "dev-master", + "version": "dev-stable26", "source": { "type": "git", "url": "https://github.com/nextcloud-deps/ocp.git", - "reference": "c4a05e2e3b749899fb3dd5577ecb5763d3993da3" + "reference": "8ad3d190cc7fa4210e5121c36d40d0de9dcc343f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/c4a05e2e3b749899fb3dd5577ecb5763d3993da3", - "reference": "c4a05e2e3b749899fb3dd5577ecb5763d3993da3", + "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/8ad3d190cc7fa4210e5121c36d40d0de9dcc343f", + "reference": "8ad3d190cc7fa4210e5121c36d40d0de9dcc343f", "shasum": "" }, "require": { "php": "^7.4 || ~8.0 || ~8.1", - "psr/clock": "^1.0", "psr/container": "^1.1.1", "psr/event-dispatcher": "^1.0", "psr/log": "^1.1" }, - "default-branch": true, "type": "library", "extra": { "branch-alias": { @@ -1270,9 +1268,9 @@ "description": "Composer package containing Nextcloud's public API (classes, interfaces)", "support": { "issues": "https://github.com/nextcloud-deps/ocp/issues", - "source": "https://github.com/nextcloud-deps/ocp/tree/master" + "source": "https://github.com/nextcloud-deps/ocp/tree/stable26" }, - "time": "2023-02-22T00:36:09+00:00" + "time": "2023-04-04T00:35:10+00:00" }, { "name": "nikic/php-parser", @@ -2128,54 +2126,6 @@ }, "time": "2021-02-03T23:26:27+00:00" }, - { - "name": "psr/clock", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/clock.git", - "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/clock/zipball/e41a24703d4560fd0acb709162f73b8adfc3aa0d", - "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d", - "shasum": "" - }, - "require": { - "php": "^7.0 || ^8.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Psr\\Clock\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interface for reading the clock.", - "homepage": "https://github.com/php-fig/clock", - "keywords": [ - "clock", - "now", - "psr", - "psr-20", - "time" - ], - "support": { - "issues": "https://github.com/php-fig/clock/issues", - "source": "https://github.com/php-fig/clock/tree/1.0.0" - }, - "time": "2022-11-25T14:36:26+00:00" - }, { "name": "psr/container", "version": "1.1.2", diff --git a/lib/DB/Place/PlaceMapper.php b/lib/DB/Place/PlaceMapper.php index e5c3e9501..4f926a083 100644 --- a/lib/DB/Place/PlaceMapper.php +++ b/lib/DB/Place/PlaceMapper.php @@ -33,7 +33,7 @@ use OCP\IDBConnection; class PlaceMapper { - public const METADATA_TYPE = 'photos_place'; + public const METADATA_GROUP = 'photos_place'; public function __construct( private IDBConnection $connection, @@ -53,16 +53,16 @@ public function findPlacesForUser(string $userId): array { $qb = $this->connection->getQueryBuilder(); - $rows = $qb->selectDistinct('meta.metadata') + $rows = $qb->selectDistinct('meta.value') ->from('file_metadata', 'meta') ->join('meta', 'filecache', 'file', $qb->expr()->eq('file.fileid', 'meta.id', IQueryBuilder::PARAM_INT)) ->where($qb->expr()->eq('file.storage', $qb->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) ->andWhere($qb->expr()->eq('file.mimepart', $qb->createNamedParameter($mimepart, IQueryBuilder::PARAM_INT))) - ->andWhere($qb->expr()->eq('meta.group_name', $qb->createNamedParameter(self::METADATA_TYPE))) + ->andWhere($qb->expr()->eq('meta.group_name', $qb->createNamedParameter(self::METADATA_GROUP))) ->executeQuery() ->fetchAll(); - return array_map(fn ($row) => new PlaceInfo($userId, $row['metadata']), $rows); + return array_map(fn ($row) => new PlaceInfo($userId, $row['value']), $rows); } /** @return PlaceInfo */ @@ -76,13 +76,13 @@ public function findPlaceForUser(string $userId, string $place): PlaceInfo { $qb = $this->connection->getQueryBuilder(); - $rows = $qb->selectDistinct('meta.metadata') + $rows = $qb->selectDistinct('meta.value') ->from('file_metadata', 'meta') ->join('meta', 'filecache', 'file', $qb->expr()->eq('file.fileid', 'meta.id', IQueryBuilder::PARAM_INT)) ->where($qb->expr()->eq('file.storage', $qb->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) ->andWhere($qb->expr()->eq('file.mimepart', $qb->createNamedParameter($mimepart, IQueryBuilder::PARAM_INT))) - ->andWhere($qb->expr()->eq('meta.group_name', $qb->createNamedParameter(self::METADATA_TYPE))) - ->andWhere($qb->expr()->eq('meta.metadata', $qb->createNamedParameter($place))) + ->andWhere($qb->expr()->eq('meta.group_name', $qb->createNamedParameter(self::METADATA_GROUP))) + ->andWhere($qb->expr()->eq('meta.value', $qb->createNamedParameter($place))) ->executeQuery() ->fetchAll(); @@ -90,7 +90,7 @@ public function findPlaceForUser(string $userId, string $place): PlaceInfo { throw new NotFoundException(); } - return new PlaceInfo($userId, $rows[0]['metadata']); + return new PlaceInfo($userId, $rows[0]['value']); } /** @return PlaceFile[] */ @@ -104,13 +104,13 @@ public function findFilesForUserAndPlace(string $userId, string $place) { $qb = $this->connection->getQueryBuilder(); - $rows = $qb->select('file.fileid', 'file.name', 'file.mimetype', 'file.size', 'file.mtime', 'file.etag', 'meta.metadata') + $rows = $qb->select('file.fileid', 'file.name', 'file.mimetype', 'file.size', 'file.mtime', 'file.etag', 'meta.value') ->from('file_metadata', 'meta') ->join('meta', 'filecache', 'file', $qb->expr()->eq('file.fileid', 'meta.id', IQueryBuilder::PARAM_INT)) ->where($qb->expr()->eq('file.storage', $qb->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) ->andWhere($qb->expr()->eq('file.mimepart', $qb->createNamedParameter($mimepart, IQueryBuilder::PARAM_INT))) - ->andWhere($qb->expr()->eq('meta.group_name', $qb->createNamedParameter(self::METADATA_TYPE))) - ->andWhere($qb->expr()->eq('meta.metadata', $qb->createNamedParameter($place))) + ->andWhere($qb->expr()->eq('meta.group_name', $qb->createNamedParameter(self::METADATA_GROUP))) + ->andWhere($qb->expr()->eq('meta.value', $qb->createNamedParameter($place))) ->executeQuery() ->fetchAll(); @@ -122,7 +122,7 @@ public function findFilesForUserAndPlace(string $userId, string $place) { (int)$row['size'], (int)$row['mtime'], $row['etag'], - $row['metadata'] + $row['value'] ), $rows, ); @@ -138,15 +138,15 @@ public function findFileForUserAndPlace(string $userId, string $place, string $f $qb = $this->connection->getQueryBuilder(); - $rows = $qb->select('file.fileid', 'file.name', 'file.mimetype', 'file.size', 'file.mtime', 'file.etag', 'meta.metadata') + $rows = $qb->select('file.fileid', 'file.name', 'file.mimetype', 'file.size', 'file.mtime', 'file.etag', 'meta.value') ->from('file_metadata', 'meta') ->join('meta', 'filecache', 'file', $qb->expr()->eq('file.fileid', 'meta.id', IQueryBuilder::PARAM_INT)) ->where($qb->expr()->eq('file.storage', $qb->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) ->andWhere($qb->expr()->eq('file.mimepart', $qb->createNamedParameter($mimepart, IQueryBuilder::PARAM_INT))) ->andWhere($qb->expr()->eq('file.fileid', $qb->createNamedParameter($fileId))) ->andWhere($qb->expr()->eq('file.name', $qb->createNamedParameter($fileName))) - ->andWhere($qb->expr()->eq('meta.group_name', $qb->createNamedParameter(self::METADATA_TYPE))) - ->andWhere($qb->expr()->eq('meta.metadata', $qb->createNamedParameter($place))) + ->andWhere($qb->expr()->eq('meta.group_name', $qb->createNamedParameter(self::METADATA_GROUP))) + ->andWhere($qb->expr()->eq('meta.value', $qb->createNamedParameter($place))) ->executeQuery() ->fetchAll(); @@ -161,7 +161,7 @@ public function findFileForUserAndPlace(string $userId, string $place, string $f (int)$rows[0]['size'], (int)$rows[0]['mtime'], $rows[0]['etag'], - $rows[0]['metadata'] + $rows[0]['value'] ); } @@ -171,8 +171,8 @@ public function setPlaceForFile(string $place, int $fileId): void { $query->insert('file_metadata') ->values([ "id" => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT), - "group_name" => $query->createNamedParameter(self::METADATA_TYPE), - "metadata" => $query->createNamedParameter($place), + "group_name" => $query->createNamedParameter(self::METADATA_GROUP), + "value" => $query->createNamedParameter($place), ]) ->executeStatement(); } catch (\Exception $ex) { @@ -185,9 +185,9 @@ public function setPlaceForFile(string $place, int $fileId): void { public function updatePlaceForFile(string $place, int $fileId): void { $query = $this->connection->getQueryBuilder(); $query->update('file_metadata') - ->set("metadata", $query->createNamedParameter($place)) + ->set("value", $query->createNamedParameter($place)) ->where($query->expr()->eq('id', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))) - ->andWhere($query->expr()->eq('group_name', $query->createNamedParameter(self::METADATA_TYPE))) + ->andWhere($query->expr()->eq('group_name', $query->createNamedParameter(self::METADATA_GROUP))) ->executeStatement(); } } diff --git a/lib/Sabre/PropFindPlugin.php b/lib/Sabre/PropFindPlugin.php index 174b825e6..9abee8954 100644 --- a/lib/Sabre/PropFindPlugin.php +++ b/lib/Sabre/PropFindPlugin.php @@ -120,7 +120,7 @@ public function propFind(PropFind $propFind, INode $node): void { $sizeMetadata = $this->metadataManager->fetchMetadataFor('size', [$node->getFile()->getFileId()])[$node->getFile()->getFileId()]; } - return json_encode((object)$sizeMetadata->getMetadata()); + return $sizeMetadata->getValue(); }); } } diff --git a/lib/Service/MediaPlaceManager.php b/lib/Service/MediaPlaceManager.php index acd54be1f..c1e11f7b6 100644 --- a/lib/Service/MediaPlaceManager.php +++ b/lib/Service/MediaPlaceManager.php @@ -58,7 +58,7 @@ public function updatePlaceForFile(int $fileId): void { private function getPlaceForFile(int $fileId): ?string { $gpsMetadata = $this->metadataManager->fetchMetadataFor('gps', [$fileId])[$fileId]; - $metadata = $gpsMetadata->getMetadata(); + $metadata = $gpsMetadata->getDecodedValue(); if (count($metadata) === 0) { return null; diff --git a/tests/stub.phpstub b/tests/stub.phpstub index 1cf150a3b..edb8340e5 100644 --- a/tests/stub.phpstub +++ b/tests/stub.phpstub @@ -657,11 +657,18 @@ 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 { + 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)); + } } }