summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoranoy <anoymouserver+github@mailbox.org>2020-10-04 17:25:25 +0200
committerSean Molenaar <SMillerDev@users.noreply.github.com>2020-10-04 21:35:31 +0200
commitbfcf38a4806800d8d9b19161670369a30739c4a2 (patch)
tree0706b711eca45e49da863613084d895e77ff1645
parent0fe63840854c185b40b0f788e227ef44ca5bb157 (diff)
update only relevant item fields
Signed-off-by: anoy <anoymouserver+github@mailbox.org> Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
-rw-r--r--lib/Db/ItemMapperV2.php11
-rw-r--r--lib/Service/ItemServiceV2.php7
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/Db/ItemMapperV2.php b/lib/Db/ItemMapperV2.php
index 222340744..54d9ecbaf 100644
--- a/lib/Db/ItemMapperV2.php
+++ b/lib/Db/ItemMapperV2.php
@@ -16,6 +16,7 @@ use Doctrine\DBAL\FetchMode;
use OCA\News\Utility\Time;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
+use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
@@ -95,6 +96,16 @@ class ItemMapperV2 extends NewsMapperV2
return $this->findEntity($builder);
}
+ /**
+ * Find an item by a GUID hash.
+ *
+ * @param string $guidHash hash to find with
+ *
+ * @return Item|Entity
+ *
+ * @throws DoesNotExistException
+ * @throws MultipleObjectsReturnedException
+ */
public function findByGuidHash(string $guidHash): Item
{
$builder = $this->db->getQueryBuilder();
diff --git a/lib/Service/ItemServiceV2.php b/lib/Service/ItemServiceV2.php
index 1e4fe1eac..c88a7293a 100644
--- a/lib/Service/ItemServiceV2.php
+++ b/lib/Service/ItemServiceV2.php
@@ -76,7 +76,12 @@ class ItemServiceV2 extends Service
{
try {
$db_item = $this->mapper->findByGuidHash($item->getGuidHash());
- $item->setId($db_item->getId());
+
+ // Transfer user modifications
+ $item->setUnread($db_item->isUnread())
+ ->setStarred($db_item->isStarred())
+ ->setId($db_item->getId());
+
$this->mapper->update($item);
} catch (DoesNotExistException $exception) {
$this->mapper->insert($item);