diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-04 13:12:07 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-04 13:12:07 +0200 |
commit | 4b994c97ad878cc3886ffbea1a6a2bf6b4a98def (patch) | |
tree | 85d464146ad809a68372abed3a4026578d4006ad /bl/feedbl.php | |
parent | 312796b1ca251567159368dddcaed1a3f0ddafc0 (diff) |
autopurge all read items which are not starred if there are more than 1000
Diffstat (limited to 'bl/feedbl.php')
-rw-r--r-- | bl/feedbl.php | 26 |
1 files changed, 24 insertions, 2 deletions
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()); + } + } + + } |