From bfcf38a4806800d8d9b19161670369a30739c4a2 Mon Sep 17 00:00:00 2001 From: anoy Date: Sun, 4 Oct 2020 17:25:25 +0200 Subject: update only relevant item fields Signed-off-by: anoy Signed-off-by: Sean Molenaar --- lib/Db/ItemMapperV2.php | 11 +++++++++++ lib/Service/ItemServiceV2.php | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) 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); -- cgit v1.2.3