summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--service/itemservice.php9
-rw-r--r--templates/admin.php3
-rw-r--r--tests/unit/service/ItemServiceTest.php32
4 files changed, 30 insertions, 16 deletions
diff --git a/README.md b/README.md
index 0f13067fb..ce3487c68 100644
--- a/README.md
+++ b/README.md
@@ -174,7 +174,7 @@ useCronUpdates = true
* **autoPurgeMinimumInterval**: Minimum amount of seconds after deleted feeds and folders are removed from the database. Values below 60 seconds are ignored
-* **autoPurgeCount**: Defines the minimum amount of articles that can be unread per feed before they get deleted
+* **autoPurgeCount**: Defines the minimum amount of articles that can be unread per feed before they get deleted, a negative value will turn off deleting articles completely
* **maxRedirects**: How many redirects the updater should follow
* **feedFetcherTimeout**: Maximum number of seconds to wait for an RSS or Atom feed to load. If a feed takes longer than that number of seconds to update, the update will be aborted
* **useCronUpdates**: To use a custom update/cron script you need to disable the cronjob which is run by ownCloud by default by setting this to false
diff --git a/service/itemservice.php b/service/itemservice.php
index 628f89206..329283a92 100644
--- a/service/itemservice.php
+++ b/service/itemservice.php
@@ -24,7 +24,7 @@ use \OCA\News\Config\Config;
class ItemService extends Service {
private $statusFlag;
- private $autoPurgeCount;
+ private $config;
private $timeFactory;
private $itemMapper;
@@ -34,7 +34,7 @@ class ItemService extends Service {
Config $config){
parent::__construct($itemMapper);
$this->statusFlag = $statusFlag;
- $this->autoPurgeCount = $config->getAutoPurgeCount();
+ $this->config = $config;
$this->timeFactory = $timeFactory;
$this->itemMapper = $itemMapper;
}
@@ -197,7 +197,10 @@ class ItemService extends Service {
* old, the id is taken
*/
public function autoPurgeOld(){
- $this->itemMapper->deleteReadOlderThanThreshold($this->autoPurgeCount);
+ $count = $this->config->getAutoPurgeCount();
+ if ($count >= 0) {
+ $this->itemMapper->deleteReadOlderThanThreshold($count);
+ }
}
diff --git a/templates/admin.php b/templates/admin.php
index 0379390a5..ea608c8eb 100644
--- a/templates/admin.php
+++ b/templates/admin.php
@@ -47,7 +47,8 @@ style('news', 'admin');
'Defines the maximum amount of articles that can be read per ' .
"feed which won't be deleted by the cleanup job; ".
'if old articles reappear after being read, increase ' .
- 'this value'
+ 'this value; negative values will turn this feature off ' .
+ 'completely'
)); ?></em>
</p>
<p><input type="text" name="news-auto-purge-count"
diff --git a/tests/unit/service/ItemServiceTest.php b/tests/unit/service/ItemServiceTest.php
index 4f5672e20..1b6eb6c00 100644
--- a/tests/unit/service/ItemServiceTest.php
+++ b/tests/unit/service/ItemServiceTest.php
@@ -29,34 +29,31 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
private $status;
private $time;
private $newestItemId;
+ private $config;
protected function setUp(){
$this->time = 222;
- $timeFactory = $this->getMock('TimeFactory', ['getTime']);
- $timeFactory->expects($this->any())
+ $this->timeFactory = $this->getMock('TimeFactory', ['getTime']);
+ $this->timeFactory->expects($this->any())
->method('getTime')
->will($this->returnValue($this->time));
$this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper')
->disableOriginalConstructor()
->getMock();
- $statusFlag = $this->getMockBuilder('\OCA\News\Db\StatusFlag')
+ $this->statusFlag = $this->getMockBuilder('\OCA\News\Db\StatusFlag')
->disableOriginalConstructor()
->getMock();
$this->status = StatusFlag::STARRED;
- $statusFlag->expects($this->any())
+ $this->statusFlag->expects($this->any())
->method('typeToStatus')
->will($this->returnValue($this->status));
- $this->threshold = 2;
- $config = $this->getMockBuilder(
+ $this->config = $this->getMockBuilder(
'\OCA\News\Config\Config')
->disableOriginalConstructor()
->getMock();
- $config->expects($this->any())
- ->method('getAutoPurgeCount')
- ->will($this->returnValue($this->threshold));
$this->itemService = new ItemService($this->mapper,
- $statusFlag, $timeFactory, $config);
+ $this->statusFlag, $this->timeFactory, $this->config);
$this->user = 'jack';
$this->id = 3;
$this->updatedSince = 20333;
@@ -356,9 +353,22 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
public function testAutoPurgeOldWillPurgeOld(){
+ $this->config->expects($this->once())
+ ->method('getAutoPurgeCount')
+ ->will($this->returnValue(2));
$this->mapper->expects($this->once())
->method('deleteReadOlderThanThreshold')
- ->with($this->equalTo($this->threshold));
+ ->with($this->equalTo(2));
+
+ $this->itemService->autoPurgeOld();
+ }
+
+ public function testAutoPurgeOldWontPurgeOld(){
+ $this->config->expects($this->once())
+ ->method('getAutoPurgeCount')
+ ->will($this->returnValue(-1));
+ $this->mapper->expects($this->never())
+ ->method('deleteReadOlderThanThreshold');
$this->itemService->autoPurgeOld();
}