Skip to content

Add exif tags to systemtags table #1431

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions lib/Db/ExifFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class ExifFields
'CircleOfConfusion' => true,
'DOF' => true,
'FOV' => true,
'TagsList' => true,

// Currently unused fields
'ExifVersion' => true,
Expand Down
5 changes: 5 additions & 0 deletions lib/Db/TimelineWrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TimelineWrite
use TimelineWriteMap;
use TimelineWriteOrphans;
use TimelineWritePlaces;
use TimelineWriteTags;

public function __construct(
protected IDBConnection $connection,
Expand Down Expand Up @@ -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)
Expand Down
49 changes: 49 additions & 0 deletions lib/Db/TimelineWriteTags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace OCA\Memories\Db;

use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\File;
use Psr\Log\LoggerInterface;
use OCP\IDBConnection;

trait TimelineWriteTags
{
protected IDBConnection $connection;
protected LoggerInterface $logger;

public function processTags(File $file, array $exif): void
{
foreach ($exif["TagsList"] as $tag) {
$query = $this->connection->getQueryBuilder();
$exists = $query->select('id')
->from('systemtag')
->where($query->expr()->eq('name', $query->createNamedParameter($tag, IQueryBuilder::PARAM_STR)))
->executeQuery()
->fetch();

if (!$exists) {
$query = $this->connection->getQueryBuilder();
$query->insert('systemtag')
->values([
'name' => $query->createNamedParameter($tag, IQueryBuilder::PARAM_STR)
])->executeStatement();
$exists = $query->getLastInsertId();
}

$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),
];
$query->insert('systemtag_object_mapping')
->values($params)->executeStatement();

$this->logger->info("Added $tag to file {$file->getId()}");
}
}
}