From 540c329f588b410df61bcf53bff603d1837c8854 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Mon, 13 Feb 2023 16:04:45 +0100 Subject: [PATCH] fixup! Use generic table to store location data --- lib/DB/Location/LocationMapper.php | 14 +++++++------- lib/Migration/Version20002Date20221012131022.php | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/DB/Location/LocationMapper.php b/lib/DB/Location/LocationMapper.php index 99ad012e6..eb7e628bf 100644 --- a/lib/DB/Location/LocationMapper.php +++ b/lib/DB/Location/LocationMapper.php @@ -32,7 +32,7 @@ class LocationMapper { public const TABLE_NAME = 'photos_metadata'; - public const METADATA_NAME = 'location'; + public const METADATA_TYPE = 'location'; public function __construct( private IDBConnection $connection, @@ -47,7 +47,7 @@ public function findLocationsForUser(string $userId): array { $rows = $qb->selectDistinct('value') ->from(self::TABLE_NAME) ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId))) - ->andWhere($qb->expr()->eq('name', $qb->createNamedParameter(self::METADATA_NAME))) + ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(self::METADATA_TYPE))) ->executeQuery() ->fetchAll(); @@ -62,7 +62,7 @@ public function findFilesForUserAndLocation(string $userId, int $locationId) { ->from(self::TABLE_NAME, 'm') ->leftJoin("m", "filecache", "f", $qb->expr()->eq("m.file_id", "f.fileid")) ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId))) - ->andWhere($qb->expr()->eq('m.name', $qb->createNamedParameter(self::METADATA_NAME))) + ->andWhere($qb->expr()->eq('m.type', $qb->createNamedParameter(self::METADATA_TYPE))) ->andWhere($qb->expr()->eq('m.value', $qb->createNamedParameter($locationId))) ->executeQuery(); @@ -86,7 +86,7 @@ public function addLocationForFileAndUser(int $locationId, int $fileId, string $ $query->insert(self::TABLE_NAME) ->values([ "user_id" => $query->createNamedParameter($userId), - "name" => $query->createNamedParameter(self::METADATA_NAME), + "type" => $query->createNamedParameter(self::METADATA_TYPE), "value" => $query->createNamedParameter($locationId), "file_id" => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT), ]) @@ -103,7 +103,7 @@ public function updateLocationForFile(int $locationId, int $fileId): void { $query->update(self::TABLE_NAME) ->set("value", $query->createNamedParameter($locationId)) ->where($query->expr()->eq('file_id', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))) - ->andWhere($query->expr()->eq('name', $query->createNamedParameter(self::METADATA_NAME))) + ->andWhere($query->expr()->eq('type', $query->createNamedParameter(self::METADATA_TYPE))) ->executeStatement(); } @@ -111,7 +111,7 @@ public function removeLocationForFile(int $fileId, ?string $userId = null): void $query = $this->connection->getQueryBuilder(); $query->delete(self::TABLE_NAME) ->where($query->expr()->eq('file_id', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))) - ->andWhere($query->expr()->eq('name', $query->createNamedParameter(self::METADATA_NAME))); + ->andWhere($query->expr()->eq('type', $query->createNamedParameter(self::METADATA_TYPE))); if ($userId !== null) { $query->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId))); @@ -124,7 +124,7 @@ public function removeLocationForUser(string $userId): void { $query = $this->connection->getQueryBuilder(); $query->delete(self::TABLE_NAME) ->where($query->expr()->eq('user_id', $query->createNamedParameter($userId))) - ->andWhere($query->expr()->eq('name', $query->createNamedParameter(self::METADATA_NAME))) + ->andWhere($query->expr()->eq('type', $query->createNamedParameter(self::METADATA_TYPE))) ->executeStatement(); } } diff --git a/lib/Migration/Version20002Date20221012131022.php b/lib/Migration/Version20002Date20221012131022.php index 14b9657d1..83352e6ad 100644 --- a/lib/Migration/Version20002Date20221012131022.php +++ b/lib/Migration/Version20002Date20221012131022.php @@ -62,7 +62,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table->addColumn('file_id', Types::BIGINT, [ 'notnull' => true, ]); - $table->addColumn('name', Types::STRING, [ + $table->addColumn('type', Types::STRING, [ 'notnull' => true, 'length' => 64, ]); @@ -72,7 +72,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt ]); $table->setPrimaryKey(['id']); - $table->addUniqueConstraint(['user_id', 'file_id', 'name'], 'photos_metadata_unique_idx'); + $table->addUniqueConstraint(['user_id', 'file_id', 'type'], 'photos_metadata_unique_idx'); } if ($modified) {