summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Brahmer <info@b-brahmer.de>2020-05-23 21:27:34 +0200
committerBenjamin Brahmer <info@b-brahmer.de>2020-06-20 14:01:41 +0200
commit5da918a062b85562471b86239267b19adbb48faa (patch)
tree04475853d5d9fff45eae9ea5226a19dd6b5cb9e2
parent92e0ecd17756c36f7ae2030eb0de329bc71b5b74 (diff)
Update to new BackgroudJob logicbackroundjob
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
-rw-r--r--appinfo/info.xml2
-rw-r--r--js/admin/Admin.js7
-rw-r--r--lib/Config/Config.php12
-rw-r--r--lib/Controller/AdminController.php7
-rw-r--r--lib/Cron/Updater.php7
-rw-r--r--lib/Settings/Admin.php1
-rw-r--r--templates/admin.php19
-rw-r--r--tests/Unit/Controller/AdminControllerTest.php18
8 files changed, 65 insertions, 8 deletions
diff --git a/appinfo/info.xml b/appinfo/info.xml
index 86e355f1f..b41983682 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -8,7 +8,7 @@
Before you update to a new version, [check the changelog](https://github.com/nextcloud/news/blob/master/CHANGELOG.md) to avoid surprises.
**Important**: To enable feed updates you will need to enable either [Nextcloud system cron](https://docs.nextcloud.org/server/latest/admin_manual/configuration_server/background_jobs_configuration.html#cron) or use [an updater](https://github.com/nextcloud/news-updater) which uses the built in update API and disable cron updates. More information can be found [in the README](https://github.com/nextcloud/news).]]></description>
- <version>14.1.11</version>
+ <version>14.2.0</version>
<licence>agpl</licence>
<author>Benjamin Brahmer</author>
<author>Sean Molenaar</author>
diff --git a/js/admin/Admin.js b/js/admin/Admin.js
index d60dd483f..7a7015ea7 100644
--- a/js/admin/Admin.js
+++ b/js/admin/Admin.js
@@ -29,6 +29,8 @@
$('#news input[name="news-max-size"]');
var exploreUrlInput =
$('#news input[name="news-explore-url"]');
+ var updateInterval =
+ $('#news input[name="news-update-interval"]');
var savedMessage = $('#news-saved-message');
var saved = function () {
@@ -50,6 +52,7 @@
var feedFetcherTimeout = feedFetcherTimeoutInput.val();
var maxSize = maxSizeInput.val();
var exploreUrl = exploreUrlInput.val();
+ var updateInterval = updateIntervalInput.val()
var useCronUpdates = useCronUpdatesInput.is(':checked');
var data = {
@@ -60,7 +63,8 @@
feedFetcherTimeout: parseInt(feedFetcherTimeout, 10),
maxSize: parseInt(maxSize, 10),
useCronUpdates: useCronUpdates,
- exploreUrl: exploreUrl
+ exploreUrl: exploreUrl,
+ updateInterval: parseInt(updateInterval, 10)
};
var url = OC.generateUrl('/apps/news/admin');
@@ -81,6 +85,7 @@
feedFetcherTimeoutInput.val(data.feedFetcherTimeout);
useCronUpdatesInput.prop('checked', data.useCronUpdates);
exploreUrlInput.val(data.exploreUrl);
+ updateInterval.val(data.updateInterval);
});
};
diff --git a/lib/Config/Config.php b/lib/Config/Config.php
index dea1f5814..35d947871 100644
--- a/lib/Config/Config.php
+++ b/lib/Config/Config.php
@@ -32,6 +32,7 @@ class Config
private $loggerParams;
private $maxSize;
private $exploreUrl;
+ private $updateInterval;
public function __construct(
Folder $fileSystem,
@@ -48,6 +49,7 @@ class Config
$this->logger = $logger;
$this->exploreUrl = '';
$this->loggerParams = $LoggerParameters;
+ $this->updateInterval = 3600;
}
public function getAutoPurgeMinimumInterval()
@@ -94,6 +96,10 @@ class Config
return $this->exploreUrl;
}
+ public function getUpdateInterval()
+ {
+ return $this->updateInterval;
+ }
public function setAutoPurgeMinimumInterval($value)
{
@@ -135,6 +141,12 @@ class Config
$this->exploreUrl = $value;
}
+ public function setUpdateInterval($value)
+ {
+ $this->updateInterval = $value;
+ }
+
+
public function read($configPath, $createIfNotExists = false)
{
diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php
index 3ce09a0d1..a8fcf7891 100644
--- a/lib/Controller/AdminController.php
+++ b/lib/Controller/AdminController.php
@@ -73,6 +73,7 @@ class AdminController extends Controller
'useCronUpdates' => $this->config->getUseCronUpdates(),
'maxSize' => $this->config->getMaxSize(),
'exploreUrl' => $this->config->getExploreUrl(),
+ 'updateInterval' => $this->config->getupdateInterval(),
];
return new TemplateResponse($this->appName, 'admin', $data, 'blank');
}
@@ -88,6 +89,7 @@ class AdminController extends Controller
* @param int $maxSize New max feed size
* @param bool $useCronUpdates Whether or not to use cron updates
* @param string $exploreUrl URL to use for the explore feed
+ * @param int $updateInterval Interval in which the feeds will be updated
*
* @return array with the updated values
*/
@@ -98,7 +100,8 @@ class AdminController extends Controller
$feedFetcherTimeout,
$maxSize,
$useCronUpdates,
- $exploreUrl
+ $exploreUrl,
+ $updateInterval
) {
$this->config->setAutoPurgeMinimumInterval($autoPurgeMinimumInterval);
$this->config->setAutoPurgeCount($autoPurgeCount);
@@ -107,6 +110,7 @@ class AdminController extends Controller
$this->config->setFeedFetcherTimeout($feedFetcherTimeout);
$this->config->setUseCronUpdates($useCronUpdates);
$this->config->setExploreUrl($exploreUrl);
+ $this->config->setupdateInterval($updateInterval);
$this->config->write($this->configPath);
return [
@@ -118,6 +122,7 @@ class AdminController extends Controller
'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(),
'useCronUpdates' => $this->config->getUseCronUpdates(),
'exploreUrl' => $this->config->getExploreUrl(),
+ 'updateInterval' => $this->config->getupdateInterval(),
];
}
}
diff --git a/lib/Cron/Updater.php b/lib/Cron/Updater.php
index 55afe0a38..66ca4a908 100644
--- a/lib/Cron/Updater.php
+++ b/lib/Cron/Updater.php
@@ -11,13 +11,13 @@
namespace OCA\News\Cron;
-use OC\BackgroundJob\Job;
+use OC\BackgroundJob\TimedJob;
use OCA\News\Config\Config;
use OCA\News\Service\StatusService;
use OCA\News\Utility\Updater as UpdaterService;
-class Updater extends Job
+class Updater extends TimedJob
{
/**
@@ -34,6 +34,7 @@ class Updater extends Job
private $updaterService;
public function __construct(
+ ITimeFactroy $time,
Config $config,
StatusService $status,
UpdaterService $updaterService
@@ -41,6 +42,8 @@ class Updater extends Job
$this->config = $config;
$this->status = $status;
$this->updaterService = $updaterService;
+
+ parent::setInterval($this->config->getupdateInterval());
}
protected function run($argument)
diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php
index 737f44cc1..e8c9a0cb2 100644
--- a/lib/Settings/Admin.php
+++ b/lib/Settings/Admin.php
@@ -27,6 +27,7 @@ class Admin implements ISettings
'useCronUpdates' => $this->config->getUseCronUpdates(),
'maxSize' => $this->config->getMaxSize(),
'exploreUrl' => $this->config->getExploreUrl(),
+ 'updateInterval' => $this->config->getUpdateInterval(),
];
return new TemplateResponse('news', 'admin', $data, '');
}
diff --git a/templates/admin.php b/templates/admin.php
index cf69c33de..28f72dffd 100644
--- a/templates/admin.php
+++ b/templates/admin.php
@@ -125,6 +125,25 @@ style('news', 'admin');
<p><input type="text" name="news-explore-url"
value="<?php p($_['exploreUrl']); ?>"></p>
</div>
+ <div class="form-line">
+ <p>
+ <label for="news-updater-interval">
+ <?php p($l->t('Update Interval')); ?>
+ </label>
+ </p>
+ <p>
+ <em>
+ <?php p($l->t(
+ 'Interval in which the feeds will be updated '
+ )); ?>.
+ </em>
+ <a href="https://github.com/nextcloud/news/tree/master/docs/updateInterval"><?php p($l->t(
+ 'For more information check the wiki'
+ )); ?></a>
+ </p>
+ <p><input type="text" name="news-update-interval"
+ value="<?php p($_['updateInterval']); ?>"></p>
+ </div>
<div id="news-saved-message">
<span class="msg success"><?php p($l->t('Saved')); ?></span>
</div>
diff --git a/tests/Unit/Controller/AdminControllerTest.php b/tests/Unit/Controller/AdminControllerTest.php
index 2b148e67d..b0b551006 100644
--- a/tests/Unit/Controller/AdminControllerTest.php
+++ b/tests/Unit/Controller/AdminControllerTest.php
@@ -62,7 +62,8 @@ class AdminControllerTest extends TestCase
'feedFetcherTimeout' => 4,
'useCronUpdates' => 5,
'maxSize' => 7,
- 'exploreUrl' => 'test'
+ 'exploreUrl' => 'test',
+ 'updateInterval' => 3600
];
$this->config->expects($this->once())
->method('getAutoPurgeMinimumInterval')
@@ -85,6 +86,9 @@ class AdminControllerTest extends TestCase
$this->config->expects($this->once())
->method('getExploreUrl')
->will($this->returnValue($expected['exploreUrl']));
+ $this->config->expects($this->once())
+ ->method('getUpdateInterval')
+ ->will($this->returnValue($expected['updateInterval']));
$response = $this->controller->index();
$data = $response->getParams();
@@ -106,7 +110,8 @@ class AdminControllerTest extends TestCase
'feedFetcherTimeout' => 4,
'useCronUpdates' => 5,
'maxSize' => 7,
- 'exploreUrl' => 'test'
+ 'exploreUrl' => 'test',
+ 'updateInterval' => 3600
];
$this->config->expects($this->once())
@@ -128,6 +133,9 @@ class AdminControllerTest extends TestCase
->method('setExploreUrl')
->with($this->equalTo($expected['exploreUrl']));
$this->config->expects($this->once())
+ ->method('setUpdateInterval')
+ ->with($this->equalTo($expected['updateInterval']));
+ $this->config->expects($this->once())
->method('write')
->with($this->equalTo($this->configPath));
@@ -152,6 +160,9 @@ class AdminControllerTest extends TestCase
$this->config->expects($this->once())
->method('getExploreUrl')
->will($this->returnValue($expected['exploreUrl']));
+ $this->config->expects($this->once())
+ ->method('getUpdateInterval')
+ ->will($this->returnValue($expected['updateInterval']));
$response = $this->controller->update(
$expected['autoPurgeMinimumInterval'],
@@ -160,7 +171,8 @@ class AdminControllerTest extends TestCase
$expected['feedFetcherTimeout'],
$expected['maxSize'],
$expected['useCronUpdates'],
- $expected['exploreUrl']
+ $expected['exploreUrl'],
+ $expected['updateInterval']
);
$this->assertEquals($expected, $response);