diff --git a/CHANGELOG.md b/CHANGELOG.md index a6e0c517e..63c0ada51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +owncloud-news (5.2.4) +* **Enhancement**: Add a new API route to check for the status and possible problems + owncloud-news (5.2.3) * **Enhancement**: Push explore button at the bottom of the feed list * **Enhancement**: When passing a negative batchSizes to the item API, all items will be returned diff --git a/appinfo/info.xml b/appinfo/info.xml index 14ae0323a..06dac975e 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -7,7 +7,7 @@ Bernhard Posselt, Alessandro Cosentino, Jan-Christoph Borchardt multimedia AGPL - 5.2.3 + 5.2.4 News diff --git a/appinfo/routes.php b/appinfo/routes.php index 4900d3885..c19c20a08 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -58,6 +58,7 @@ // API 1.2 ['name' => 'utility_api#version', 'url' => '/api/v1-2/version', 'verb' => 'GET'], +['name' => 'utility_api#status', 'url' => '/api/v1-2/status', 'verb' => 'GET'], ['name' => 'utility_api#before_update', 'url' => '/api/v1-2/cleanup/before-update', 'verb' => 'GET'], ['name' => 'utility_api#after_update', 'url' => '/api/v1-2/cleanup/after-update', 'verb' => 'GET'], ['name' => 'utility_api#preflighted_cors', 'url' => '/api/v1-2/{path}', 'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']], diff --git a/controller/pagecontroller.php b/controller/pagecontroller.php index 8bb266786..346ef61ef 100644 --- a/controller/pagecontroller.php +++ b/controller/pagecontroller.php @@ -13,18 +13,19 @@ namespace OCA\News\Controller; -use \OCP\AppFramework\Http\TemplateResponse; -use \OCP\AppFramework\Http\JSONResponse; -use \OCP\IRequest; -use \OCP\IConfig; -use \OCP\IL10N; -use \OCP\IURLGenerator; -use \OCP\AppFramework\Controller; - -use \OCA\News\Config\AppConfig; -use \OCA\News\Config\Config; -use \OCA\News\Explore\RecommendedSites; -use \OCA\News\Db\FeedType; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\AppFramework\Http\JSONResponse; +use OCP\IRequest; +use OCP\IConfig; +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\AppFramework\Controller; + +use OCA\News\Service\StatusService; +use OCA\News\Config\AppConfig; +use OCA\News\Config\Config; +use OCA\News\Explore\RecommendedSites; +use OCA\News\Db\FeedType; class PageController extends Controller { @@ -35,6 +36,7 @@ class PageController extends Controller { private $urlGenerator; private $config; private $recommendedSites; + private $statusService; public function __construct($AppName, IRequest $request, @@ -44,6 +46,7 @@ public function __construct($AppName, Config $config, IL10N $l10n, RecommendedSites $recommendedSites, + StatusService $statusService, $UserId){ parent::__construct($AppName, $request); $this->settings = $settings; @@ -53,6 +56,7 @@ public function __construct($AppName, $this->userId = $UserId; $this->config = $config; $this->recommendedSites = $recommendedSites; + $this->statusService = $statusService; } @@ -61,17 +65,10 @@ public function __construct($AppName, * @NoCSRFRequired */ public function index() { - $cronWarning = ''; - $cronMode = $this->settings->getAppValue('core', 'backgroundjobs_mode'); - $cronOn = $this->config->getUseCronUpdates(); - - // check for cron modes which may lead to problems - if ($cronMode !== 'cron' && $cronMode !== 'webcron' && $cronOn) { - $cronWarning = 'ajaxCron'; - } + $status = $this->statusService->getStatus(); return new TemplateResponse($this->appName, 'index', [ - 'cronWarning' => $cronWarning + 'cronWarning' => $status['warnings']['improperlyConfiguredCron'] ]); } diff --git a/controller/utilityapicontroller.php b/controller/utilityapicontroller.php index 0651b5c2f..e613e70a5 100644 --- a/controller/utilityapicontroller.php +++ b/controller/utilityapicontroller.php @@ -19,20 +19,24 @@ use \OCP\AppFramework\Http; use \OCA\News\Utility\Updater; +use \OCA\News\Service\StatusService; class UtilityApiController extends ApiController { private $updater; private $settings; + private $statusService; public function __construct($AppName, IRequest $request, Updater $updater, - IConfig $settings){ + IConfig $settings, + StatusService $statusService){ parent::__construct($AppName, $request); $this->updater = $updater; $this->settings = $settings; + $this->statusService = $statusService; } @@ -50,6 +54,7 @@ public function version() { /** * @NoCSRFRequired + * @CORS */ public function beforeUpdate() { $this->updater->beforeUpdate(); @@ -58,10 +63,21 @@ public function beforeUpdate() { /** * @NoCSRFRequired + * @CORS */ public function afterUpdate() { $this->updater->afterUpdate(); } + /** + * @CORS + * @NoCSRFRequired + * @NoAdminRequired + */ + public function status() { + return $this->statusService->getStatus(); + } + + } diff --git a/service/statusservice.php b/service/statusservice.php new file mode 100644 index 000000000..b578dd7c5 --- /dev/null +++ b/service/statusservice.php @@ -0,0 +1,59 @@ + + * @author Bernhard Posselt + * @copyright Alessandro Cosentino 2012 + * @copyright Bernhard Posselt 2012, 2014 + */ + +namespace OCA\News\Service; + +use OCP\IConfig; + +use OCA\News\Config\Config; + + +class StatusService { + + private $settings; + private $config; + private $appName; + + public function __construct(IConfig $settings, Config $config, $AppName) { + $this->settings = $settings; + $this->config = $config; + $this->appName = $AppName; + } + + + public function getStatus() { + $improperlyConfiguredCron = false; + + $version = $this->settings->getAppValue( + $this->appName, 'installed_version' + ); + $cronMode = $this->settings->getAppValue( + 'core', 'backgroundjobs_mode' + ); + $cronOn = $this->config->getUseCronUpdates(); + + // check for cron modes which may lead to problems + if ($cronMode !== 'cron' && $cronMode !== 'webcron' && $cronOn) { + $improperlyConfiguredCron = true; + } + + + return [ + 'version' => $version, + 'warnings' => [ + 'improperlyConfiguredCron' => $improperlyConfiguredCron + ] + ]; + } + +} \ No newline at end of file diff --git a/templates/part.content.cronwarning.php b/templates/part.content.cronwarning.php index 54ec039f2..57eebe123 100644 --- a/templates/part.content.cronwarning.php +++ b/templates/part.content.cronwarning.php @@ -1,4 +1,4 @@ - +

t('Ajax cron mode detected! Your feeds will ' . 'not be updated correctly. It is recommended to either use ' . diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php index fd548df62..47c85fdd9 100644 --- a/tests/unit/controller/PageControllerTest.php +++ b/tests/unit/controller/PageControllerTest.php @@ -29,6 +29,7 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase { private $configData; private $config; private $recommended; + private $status; /** * Gets run before each test @@ -74,64 +75,44 @@ public function setUp(){ '\OCA\News\Explore\RecommendedSites') ->disableOriginalConstructor() ->getMock(); + $this->status = $this->getMockBuilder( + '\OCA\News\Service\StatusService') + ->disableOriginalConstructor() + ->getMock(); $this->controller = new PageController($this->appName, $this->request, $this->settings, $this->urlGenerator, $this->appConfig, - $this->config, $this->l10n, $this->recommended, $this->user); + $this->config, $this->l10n, $this->recommended, $this->status, + $this->user); } public function testIndex(){ - $this->config->expects($this->once()) - ->method('getUseCronUpdates') - ->will($this->returnValue(true)); - - $this->settings->expects($this->once()) - ->method('getAppValue') - ->with( - $this->equalTo('core'), - $this->equalTo('backgroundjobs_mode') - ) - ->will($this->returnValue('webcron')); + $this->status->expects($this->once()) + ->method('getStatus') + ->will($this->returnValue([ + 'warnings' => [ + 'improperlyConfiguredCron' => false + ] + ])); $response = $this->controller->index(); $this->assertEquals('index', $response->getTemplateName()); - $this->assertSame('', $response->getParams()['cronWarning']); + $this->assertSame(false, $response->getParams()['cronWarning']); } public function testIndexNoCorrectCronAjax(){ - $this->config->expects($this->once()) - ->method('getUseCronUpdates') - ->will($this->returnValue(true)); - - $this->settings->expects($this->once()) - ->method('getAppValue') - ->with( - $this->equalTo('core'), - $this->equalTo('backgroundjobs_mode') - ) - ->will($this->returnValue('ajax')); - - $response = $this->controller->index(); - $this->assertEquals('ajaxCron', $response->getParams()['cronWarning']); - } - - - public function testIndexNoCorrectCronTurnedOff(){ - $this->config->expects($this->once()) - ->method('getUseCronUpdates') - ->will($this->returnValue(false)); + $this->status->expects($this->once()) + ->method('getStatus') + ->will($this->returnValue([ + 'warnings' => [ + 'improperlyConfiguredCron' => true + ] + ])); - $this->settings->expects($this->once()) - ->method('getAppValue') - ->with( - $this->equalTo('core'), - $this->equalTo('backgroundjobs_mode') - ) - ->will($this->returnValue('ajax')); $response = $this->controller->index(); - $this->assertSame('', $response->getParams()['cronWarning']); + $this->assertEquals(true, $response->getParams()['cronWarning']); } diff --git a/tests/unit/controller/UtilityApiControllerTest.php b/tests/unit/controller/UtilityApiControllerTest.php index f4219fddf..292b8d16a 100644 --- a/tests/unit/controller/UtilityApiControllerTest.php +++ b/tests/unit/controller/UtilityApiControllerTest.php @@ -21,6 +21,7 @@ class UtilityApiControllerTest extends \PHPUnit_Framework_TestCase { private $newsAPI; private $updater; private $appName; + private $status; protected function setUp() { $this->appName = 'news'; @@ -36,8 +37,13 @@ protected function setUp() { '\OCA\News\Utility\Updater') ->disableOriginalConstructor() ->getMock(); + $this->status = $this->getMockBuilder( + '\OCA\News\Service\StatusService') + ->disableOriginalConstructor() + ->getMock(); $this->newsAPI = new UtilityApiController( - $this->appName, $this->request, $this->updater, $this->settings + $this->appName, $this->request, $this->updater, $this->settings, + $this->status ); } @@ -70,4 +76,15 @@ public function testAfterUpdate(){ } + public function testStatus(){ + $in = 'hi'; + $this->status->expects($this->once()) + ->method('getStatus') + ->will($this->returnValue($in)); + $result = $this->newsAPI->status(); + + $this->assertEquals($in, $result); + } + + } diff --git a/tests/unit/service/StatusServiceTest.php b/tests/unit/service/StatusServiceTest.php new file mode 100644 index 000000000..40e2ecce9 --- /dev/null +++ b/tests/unit/service/StatusServiceTest.php @@ -0,0 +1,89 @@ + + * @author Bernhard Posselt + * @copyright Alessandro Cosentino 2012 + * @copyright Bernhard Posselt 2012, 2014 + */ + +namespace OCA\News\Service; + +use \OCA\News\Db\FeedType; + + +class StatusServiceTest extends \PHPUnit_Framework_TestCase { + + private $settings; + private $config; + private $service; + private $appName; + + public function setUp(){ + $this->appName = 'news'; + $this->settings = $this->getMockBuilder( + '\OCP\IConfig') + ->disableOriginalConstructor() + ->getMock(); + $this->config = $this->getMockBuilder( + '\OCA\News\Config\Config') + ->disableOriginalConstructor() + ->getMock(); + $this->service = new StatusService($this->settings, $this->config, + $this->appName); + } + + private function beforeStatus($cronMode='webcron', $cronEnabled=true, + $version='1.0') { + $this->settings->expects($this->at(0)) + ->method('getAppValue') + ->with($this->equalTo($this->appName), + $this->equalTo('installed_version')) + ->will($this->returnValue($version)); + + $this->settings->expects($this->at(1)) + ->method('getAppValue') + ->with( + $this->equalTo('core'), + $this->equalTo('backgroundjobs_mode') + ) + ->will($this->returnValue($cronMode)); + + $this->config->expects($this->once()) + ->method('getUseCronUpdates') + ->will($this->returnValue($cronEnabled)); + + } + + + public function testGetStatus(){ + $this->beforeStatus(); + + $response = $this->service->getStatus(); + $this->assertEquals('1.0', $response['version']); + $this->assertFalse($response['warnings']['improperlyConfiguredCron']); + } + + + public function testGetStatusNoCorrectCronAjax(){ + $this->beforeStatus('ajax'); + + $response = $this->service->getStatus(); + $this->assertTrue($response['warnings']['improperlyConfiguredCron']); + } + + + + public function testGetStatusNoCorrectCronTurnedOff(){ + $this->beforeStatus('ajax', false); + + $response = $this->service->getStatus(); + $this->assertFalse($response['warnings']['improperlyConfiguredCron']); + } + + +} \ No newline at end of file