diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-04 13:23:03 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-04 13:23:03 +0200 |
commit | 1f2391b0cdf8e7a9f8d922c7c2f71acfc4bc6388 (patch) | |
tree | 6d4976b4bc1e0d3b5ecf6c4764ecf5a98bf7559c /bl/itembl.php | |
parent | 3ec631a5c799e35ff5dbe519a3151ad62ad186b8 (diff) |
move autopurge to itembl
Diffstat (limited to 'bl/itembl.php')
-rw-r--r-- | bl/itembl.php | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/bl/itembl.php b/bl/itembl.php index ee87d373a..eaf69c3ca 100644 --- a/bl/itembl.php +++ b/bl/itembl.php @@ -34,10 +34,13 @@ use \OCA\News\Db\FeedType; class ItemBl extends Bl { private $statusFlag; + private $autoPurgeCount; - public function __construct(ItemMapper $itemMapper, StatusFlag $statusFlag){ + public function __construct(ItemMapper $itemMapper, StatusFlag $statusFlag, + $autoPurgeCount=0){ parent::__construct($itemMapper); $this->statusFlag = $statusFlag; + $this->autoPurgeCount = $autoPurgeCount; } @@ -118,4 +121,23 @@ class ItemBl extends Bl { } + /** + * 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()); + } + } + + } |