summaryrefslogtreecommitdiffstats
path: root/bl
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-27 12:26:04 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-27 12:26:04 +0100
commit02ae36eba33a5e0957defd4619d337bfdd0c178f (patch)
treed80f58cdf9eb774d00fc5fc322bf0750b644dab2 /bl
parent89a1713f062cc78b727c6240a91408d91611dbab (diff)
fixed mark all unread serverside (was missing highestitemid, dont use lastmodified to compare for new versions but use the highest item id. if items are updated and the guidHash and feedId are the same then it will be deleted and newly inserted to make the lastmodified feasable
Diffstat (limited to 'bl')
-rw-r--r--bl/feedbl.php30
-rw-r--r--bl/itembl.php4
2 files changed, 26 insertions, 8 deletions
diff --git a/bl/feedbl.php b/bl/feedbl.php
index a77f9bdd2..3f9708234 100644
--- a/bl/feedbl.php
+++ b/bl/feedbl.php
@@ -71,8 +71,10 @@ class FeedBl extends Bl {
$feed->setUserId($userId);
$feed = $this->mapper->insert($feed);
- // insert items
- foreach($items as $item){
+ // insert items in reverse order because the first one is usually the
+ // newest item
+ for($i=count($items)-1; $i>=0; $i--){
+ $item = $items[$i];
$item->setFeedId($feed->getId());
$this->itemMapper->insert($item);
}
@@ -106,8 +108,10 @@ class FeedBl extends Bl {
try {
list($feed, $items) = $this->feedFetcher->fetch($feed->getUrl());
- // update items
- foreach($items as $item){
+ // insert items in reverse order because the first one is usually the
+ // newest item
+ for($i=count($items)-1; $i>=0; $i--){
+ $item = $items[$i];
// if a database exception is being thrown the unique constraint
// on the item guid hash is being violated and we need to update
@@ -116,10 +120,24 @@ class FeedBl extends Bl {
$item->setFeedId($feed->getId());
$this->itemMapper->insert($item);
} catch(\DatabaseException $ex){
+
+ // in case of an update the existing item has to be deleted
+ // if the pub_date changed because we sort by id on the
+ // client side since this is the only reliable way to do it
+ // to not get weird behaviour
$existing = $this->itemMapper->findByGuidHash(
$item->getGuidHash(), $feedId, $userId);
- $item->setId($existing->getId());
- $this->itemMapper->update($item);
+
+ if($existing->getPubDate() !== $item->getPubDate()){
+
+ // because the item is being replaced we need to keep
+ // status flags
+ $item->setStatus($existing->getStatus());
+ $item->setUnread();
+
+ $this->itemMapper->insert($item);
+ }
+
}
}
diff --git a/bl/itembl.php b/bl/itembl.php
index 332a51774..3c8649201 100644
--- a/bl/itembl.php
+++ b/bl/itembl.php
@@ -112,8 +112,8 @@ class ItemBl extends Bl {
}
- public function readFeed($feedId, $userId){
- $this->mapper->readFeed($feedId, $userId);
+ public function readFeed($feedId, $highestItemId, $userId){
+ $this->mapper->readFeed($feedId, $highestItemId, $userId);
}