From 724bae7ebb09b292a1124cb1807694ca16fa89a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jona=20L=C3=B6ffler?= <37999659+JonaLoeffler@users.noreply.github.com> Date: Wed, 2 Apr 2025 17:42:14 +0200 Subject: [PATCH 1/2] Add exif tags to systemtags table --- lib/Db/ExifFields.php | 1 + lib/Db/TimelineWrite.php | 5 ++++ lib/Db/TimelineWriteTags.php | 52 ++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 lib/Db/TimelineWriteTags.php diff --git a/lib/Db/ExifFields.php b/lib/Db/ExifFields.php index e5629f5dd..ec81ca2e2 100644 --- a/lib/Db/ExifFields.php +++ b/lib/Db/ExifFields.php @@ -73,6 +73,7 @@ class ExifFields 'CircleOfConfusion' => true, 'DOF' => true, 'FOV' => true, + 'TagsList' => true, // Currently unused fields 'ExifVersion' => true, diff --git a/lib/Db/TimelineWrite.php b/lib/Db/TimelineWrite.php index 0e38d50fa..8ba098633 100644 --- a/lib/Db/TimelineWrite.php +++ b/lib/Db/TimelineWrite.php @@ -22,6 +22,7 @@ class TimelineWrite use TimelineWriteMap; use TimelineWriteOrphans; use TimelineWritePlaces; + use TimelineWriteTags; public function __construct( protected IDBConnection $connection, @@ -104,6 +105,10 @@ public function processFile( return Util::transaction(fn () => $this->livePhoto->processVideoPart($file, $exif)); } + if (!empty($exif['TagsList'])){ + Util::transaction(fn () => $this->processTags($file, $exif)); + } + // If control reaches here, it's not a Live Photo video part // But if prevRow exists and dayid is not set, it *was* a live video part // In this case delete that entry (very rare edge case) diff --git a/lib/Db/TimelineWriteTags.php b/lib/Db/TimelineWriteTags.php new file mode 100644 index 000000000..35a66e510 --- /dev/null +++ b/lib/Db/TimelineWriteTags.php @@ -0,0 +1,52 @@ +connection->getQueryBuilder(); + $exists = $query->select('id') + ->from('systemtag') + ->where($query->expr()->eq('name', $query->createNamedParameter($tag, IQueryBuilder::PARAM_STR))) + ->executeQuery() + ->fetch(); + + $this->logger->error("fetched oc systemtag id", ["exists" => $exists]); + + if (!$exists) { + $query = $this->connection->getQueryBuilder(); + $query->insert('systemtag') + ->values([ + 'name' => $query->createNamedParameter($tag, IQueryBuilder::PARAM_STR) + ])->executeStatement(); + $exists = $query->getLastInsertId(); + } + + $this->logger->error("created oc systemtag id", ["exists" => $exists]); + $this->logger->error("params", ["systemtagid" => $exists, "objectid" => $file->getId(), "objecttype" => "files"]); + + $query = $this->connection->getQueryBuilder(); + $params = [ + 'systemtagid' => $query->createNamedParameter($exists, IQueryBuilder::PARAM_INT), + 'objectid' => $query->createNamedParameter($file->getId(), IQueryBuilder::PARAM_STR), + 'objecttype' => $query->createNamedParameter('files', IQueryBuilder::PARAM_STR), + ]; + $result = $query->insert('systemtag_object_mapping') + ->values($params)->executeStatement(); + + $this->logger->error("inserted", [$tag, $result]); + } + } +} \ No newline at end of file From e24008005ee2f4a344267aef7bb3d7df620ce114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jona=20L=C3=B6ffler?= <37999659+JonaLoeffler@users.noreply.github.com> Date: Wed, 2 Apr 2025 17:52:10 +0200 Subject: [PATCH 2/2] Clean up logging --- lib/Db/TimelineWriteTags.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/Db/TimelineWriteTags.php b/lib/Db/TimelineWriteTags.php index 35a66e510..061b03705 100644 --- a/lib/Db/TimelineWriteTags.php +++ b/lib/Db/TimelineWriteTags.php @@ -9,12 +9,13 @@ use Psr\Log\LoggerInterface; use OCP\IDBConnection; -trait TimelineWriteTags +trait TimelineWriteTags { protected IDBConnection $connection; protected LoggerInterface $logger; - public function processTags(File $file, array $exif): void{ + public function processTags(File $file, array $exif): void + { foreach ($exif["TagsList"] as $tag) { $query = $this->connection->getQueryBuilder(); $exists = $query->select('id') @@ -23,19 +24,14 @@ public function processTags(File $file, array $exif): void{ ->executeQuery() ->fetch(); - $this->logger->error("fetched oc systemtag id", ["exists" => $exists]); - if (!$exists) { $query = $this->connection->getQueryBuilder(); $query->insert('systemtag') ->values([ - 'name' => $query->createNamedParameter($tag, IQueryBuilder::PARAM_STR) + 'name' => $query->createNamedParameter($tag, IQueryBuilder::PARAM_STR) ])->executeStatement(); $exists = $query->getLastInsertId(); - } - - $this->logger->error("created oc systemtag id", ["exists" => $exists]); - $this->logger->error("params", ["systemtagid" => $exists, "objectid" => $file->getId(), "objecttype" => "files"]); + } $query = $this->connection->getQueryBuilder(); $params = [ @@ -43,10 +39,11 @@ public function processTags(File $file, array $exif): void{ 'objectid' => $query->createNamedParameter($file->getId(), IQueryBuilder::PARAM_STR), 'objecttype' => $query->createNamedParameter('files', IQueryBuilder::PARAM_STR), ]; - $result = $query->insert('systemtag_object_mapping') + $query->insert('systemtag_object_mapping') ->values($params)->executeStatement(); - $this->logger->error("inserted", [$tag, $result]); + $this->logger->info("Added $tag to file {$file->getId()}"); } } -} \ No newline at end of file +} +