From 1f2391b0cdf8e7a9f8d922c7c2f71acfc4bc6388 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 4 Apr 2013 13:23:03 +0200 Subject: move autopurge to itembl --- bl/itembl.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'bl/itembl.php') 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()); + } + } + + } -- cgit v1.2.3