From d3503d5e47c0c58e5a438f39c152ca3c9b2782af Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sun, 22 Oct 2023 12:14:02 -0700 Subject: [PATCH] lp: renew query Signed-off-by: Varun Patil --- lib/Db/LivePhoto.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/Db/LivePhoto.php b/lib/Db/LivePhoto.php index 74c1f93e..278a1858 100644 --- a/lib/Db/LivePhoto.php +++ b/lib/Db/LivePhoto.php @@ -112,18 +112,22 @@ class LivePhoto { $fileId = $file->getId(); $mtime = $file->getMTime(); - $liveid = $exif['ContentIdentifier']; + $liveid = $exif['ContentIdentifier'] ?? null; if (empty($liveid)) { return false; } + // Check if entry already exists $query = $this->connection->getQueryBuilder(); - $query->select('fileid') + $exists = $query->select('fileid') ->from('memories_livephoto') ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))) + ->executeQuery() + ->fetch() ; - $prevRow = $query->executeQuery()->fetch(); + // Construct query parameters + $query = $this->connection->getQueryBuilder(); $params = [ 'liveid' => $query->createNamedParameter($liveid, IQueryBuilder::PARAM_STR), 'mtime' => $query->createNamedParameter($mtime, IQueryBuilder::PARAM_INT), @@ -131,7 +135,8 @@ class LivePhoto 'orphan' => $query->createNamedParameter(false, IQueryBuilder::PARAM_BOOL), ]; - if ($prevRow) { + // Insert or update + if ($exists) { $query->update('memories_livephoto') ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))) ;