From 4b994c97ad878cc3886ffbea1a6a2bf6b4a98def Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 4 Apr 2013 13:12:07 +0200 Subject: autopurge all read items which are not starred if there are more than 1000 --- bl/feedbl.php | 26 ++++++++++++++++++++++++-- bl/folderbl.php | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) (limited to 'bl') diff --git a/bl/feedbl.php b/bl/feedbl.php index 661f1f8f5..07cf5df8f 100644 --- a/bl/feedbl.php +++ b/bl/feedbl.php @@ -39,13 +39,16 @@ class FeedBl extends Bl { private $feedFetcher; private $itemMapper; private $api; + private $autoPurgeCount; public function __construct(FeedMapper $feedMapper, Fetcher $feedFetcher, - ItemMapper $itemMapper, API $api){ + ItemMapper $itemMapper, API $api, + $autoPurgeCount=0){ parent::__construct($feedMapper); $this->feedFetcher = $feedFetcher; $this->itemMapper = $itemMapper; $this->api = $api; + $this->autoPurgeCount = $autoPurgeCount; } @@ -154,5 +157,24 @@ class FeedBl extends Bl { $this->mapper->update($feed); } - // TODO: delete associated items + + /** + * This method deletes all unread feeds that are not starred and over the + * count of $this->autoPurgeCount starting by the oldest. This is to clean + * up the database so that old entries dont spam your db. As criteria for + * old, the id is taken + */ + public function autoPurgeOld(){ + $readAndNotStarred = + $this->mapper->getReadOlderThanThreshold($this->autoPurgeCount); + + // delete entries with a lower id than last item + if($this->autoPurgeCount > 0 + && isset($readAndNotStarred[$this->autoPurgeCount-1])){ + $this->mapper->deleteReadOlderThanId( + $readAndNotStarred[$this->autoPurgeCount-1]->getId()); + } + } + + } diff --git a/bl/folderbl.php b/bl/folderbl.php index c17c516ba..3fcf48c7f 100644 --- a/bl/folderbl.php +++ b/bl/folderbl.php @@ -81,6 +81,6 @@ class FolderBl extends Bl { $this->mapper->update($folder); } - // TODO: delete associated items + } -- cgit v1.2.3