summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-10-27 14:36:00 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2014-10-27 14:36:00 +0100
commit7b058820f5cd34666b389de28afe3a11f451f742 (patch)
treeccf3ff784cd6a9a20940395df4400a45b3de2f65
parenta772db735eacdf2508b8608c2e3fd00447039c9a (diff)
only update unread per article count if its bigger than the current one
-rw-r--r--CHANGELOG.md1
-rw-r--r--service/feedservice.php19
2 files changed, 15 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a53b17cbc..a8267cf14 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@ owncloud-news (4.001)
* **Enhancement**: Get rid SimplePie feed parser library and switch to PicoFeed because SimplePie is unmaintained and full of bugs
* **Enhancement**: Use ownCloud internal proxy settings
* **Enhancement**: Also provide feed last modified and etag headers over API
+* **Enhancement**: Allow to turn off article purging by setting a negative number
owncloud-news (3.406)
* **Enhancement**: Make config.ini editable in the admin interface
diff --git a/service/feedservice.php b/service/feedservice.php
index 6ecf543b1..4ee7cb92d 100644
--- a/service/feedservice.php
+++ b/service/feedservice.php
@@ -109,9 +109,10 @@ class FeedService extends Service {
} catch(DoesNotExistException $ex){}
// insert feed
+ $itemCount = count($items);
$feed->setFolderId($folderId);
$feed->setUserId($userId);
- $feed->setArticlesPerUpdate(count($items));
+ $feed->setArticlesPerUpdate($itemCount);
if ($title) {
$feed->setTitle($title);
@@ -122,7 +123,7 @@ class FeedService extends Service {
// insert items in reverse order because the first one is usually
// the newest item
$unreadCount = 0;
- for($i=count($items)-1; $i>=0; $i--){
+ for($i=$itemCount-1; $i>=0; $i--){
$item = $items[$i];
$item->setFeedId($feed->getId());
@@ -205,16 +206,24 @@ class FeedService extends Service {
}
// update number of articles on every feed update
- if($existingFeed->getArticlesPerUpdate() !== count($items)) {
- $existingFeed->setArticlesPerUpdate(count($items));
+ $itemCount = count($items);
+
+ // this is needed to adjust to updates that add more items
+ // than when the feed was created. You can't update the count
+ // if it's lower because it may be due to the caching headers
+ // that were sent as the request and it might cause unwanted
+ // deletion and reappearing of feeds
+ if ($itemCount > $existingFeed->getArticlesPerUpdate()) {
+ $existingFeed->setArticlesPerUpdate($itemCount);
}
+
$existingFeed->setLastModified($fetchedFeed->getLastModified());
$existingFeed->setEtag($fetchedFeed->getEtag());
$this->feedMapper->update($existingFeed);
// insert items in reverse order because the first one is
// usually the newest item
- for($i=count($items)-1; $i>=0; $i--){
+ for($i=$itemCount-1; $i>=0; $i--){
$item = $items[$i];
$item->setFeedId($existingFeed->getId());