summaryrefslogtreecommitdiffstats
path: root/lib/Controller
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2020-09-20 22:03:05 +0200
committerBenjamin Brahmer <info@b-brahmer.de>2020-09-25 19:18:04 +0200
commit60ab4941cc7e6ede095e9e4aee3c2bf9a5c3bff6 (patch)
treebaf0b07dd1c545efeb59437af46a99f4d9f69425 /lib/Controller
parent2c8b4fa019749113658b9ed8cae211b679e4cbc0 (diff)
Move to nextcloud config and update phpunit
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib/Controller')
-rw-r--r--lib/Controller/AdminController.php94
-rw-r--r--lib/Controller/PageController.php68
2 files changed, 88 insertions, 74 deletions
diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php
index c5a476577..addc53591 100644
--- a/lib/Controller/AdminController.php
+++ b/lib/Controller/AdminController.php
@@ -14,11 +14,12 @@
namespace OCA\News\Controller;
+use OCA\News\AppInfo\Application;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
use OCP\IRequest;
use OCP\AppFramework\Controller;
-use OCA\News\Config\Config;
use OCA\News\Service\ItemService;
/**
@@ -28,8 +29,15 @@ use OCA\News\Service\ItemService;
*/
class AdminController extends Controller
{
+
+ /**
+ * @var IConfig
+ */
private $config;
- private $configPath;
+
+ /**
+ * @var ItemService
+ */
private $itemService;
/**
@@ -37,20 +45,17 @@ class AdminController extends Controller
*
* @param string $appName The name of the app
* @param IRequest $request The request
- * @param Config $config Config for nextcloud
+ * @param IConfig $config Config for nextcloud
* @param ItemService $itemService Service for items
- * @param string $configFile Path to the config
*/
public function __construct(
- $appName,
+ string $appName,
IRequest $request,
- Config $config,
- ItemService $itemService,
- $configFile
+ IConfig $config,
+ ItemService $itemService
) {
parent::__construct($appName, $request);
$this->config = $config;
- $this->configPath = $configFile;
$this->itemService = $itemService;
}
@@ -64,20 +69,23 @@ class AdminController extends Controller
*/
public function index()
{
- $data = [
- 'autoPurgeMinimumInterval' =>
- $this->config->getAutoPurgeMinimumInterval(),
- 'autoPurgeCount' => $this->config->getAutoPurgeCount(),
- 'maxRedirects' => $this->config->getMaxRedirects(),
- 'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(),
- 'useCronUpdates' => $this->config->getUseCronUpdates(),
- 'maxSize' => $this->config->getMaxSize(),
- 'exploreUrl' => $this->config->getExploreUrl(),
- 'updateInterval' => $this->config->getupdateInterval(),
- ];
- return new TemplateResponse($this->appName, 'admin', $data, 'blank');
+ return new TemplateResponse($this->appName, 'admin', $this->getData(), 'blank');
}
+ private function getData()
+ {
+ $data = [];
+
+ foreach (array_keys(Application::DEFAULT_SETTINGS) as $setting) {
+ $data[$setting] = $this->config->getAppValue(
+ Application::NAME,
+ $setting,
+ Application::DEFAULT_SETTINGS[$setting]
+ );
+ }
+
+ return $data;
+ }
/**
* Update the app config.
@@ -86,7 +94,6 @@ class AdminController extends Controller
* @param int $autoPurgeCount New value of auto-purge count
* @param int $maxRedirects New value for max amount of redirects
* @param int $feedFetcherTimeout New timeout value for feed fetcher
- * @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
@@ -94,35 +101,22 @@ class AdminController extends Controller
* @return array with the updated values
*/
public function update(
- $autoPurgeMinimumInterval,
- $autoPurgeCount,
- $maxRedirects,
- $feedFetcherTimeout,
- $maxSize,
- $useCronUpdates,
- $exploreUrl,
- $updateInterval
+ int $autoPurgeMinimumInterval,
+ int $autoPurgeCount,
+ int $maxRedirects,
+ int $feedFetcherTimeout,
+ bool $useCronUpdates,
+ string $exploreUrl,
+ int $updateInterval
) {
- $this->config->setAutoPurgeMinimumInterval($autoPurgeMinimumInterval);
- $this->config->setAutoPurgeCount($autoPurgeCount);
- $this->config->setMaxRedirects($maxRedirects);
- $this->config->setMaxSize($maxSize);
- $this->config->setFeedFetcherTimeout($feedFetcherTimeout);
- $this->config->setUseCronUpdates($useCronUpdates);
- $this->config->setExploreUrl($exploreUrl);
- $this->config->setUpdateInterval($updateInterval);
- $this->config->write($this->configPath);
+ $this->config->setAppValue($this->appName, 'autoPurgeMinimumInterval', $autoPurgeMinimumInterval);
+ $this->config->setAppValue($this->appName, 'autoPurgeCount', $autoPurgeCount);
+ $this->config->setAppValue($this->appName, 'maxRedirects', $maxRedirects);
+ $this->config->setAppValue($this->appName, 'feedFetcherTimeout', $feedFetcherTimeout);
+ $this->config->setAppValue($this->appName, 'useCronUpdates', $useCronUpdates);
+ $this->config->setAppValue($this->appName, 'exploreUrl', $exploreUrl);
+ $this->config->setAppValue($this->appName, 'updateInterval', $updateInterval);
- return [
- 'autoPurgeMinimumInterval' =>
- $this->config->getAutoPurgeMinimumInterval(),
- 'autoPurgeCount' => $this->config->getAutoPurgeCount(),
- 'maxRedirects' => $this->config->getMaxRedirects(),
- 'maxSize' => $this->config->getMaxSize(),
- 'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(),
- 'useCronUpdates' => $this->config->getUseCronUpdates(),
- 'exploreUrl' => $this->config->getExploreUrl(),
- 'updateInterval' => $this->config->getUpdateInterval(),
- ];
+ return $this->getData();
}
}
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index 6ae01811d..d88f8181d 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -13,6 +13,7 @@
namespace OCA\News\Controller;
+use OCA\News\AppInfo\Application;
use OCP\IRequest;
use OCP\IConfig;
use OCP\IL10N;
@@ -24,7 +25,6 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCA\News\Service\StatusService;
-use OCA\News\Config\Config;
use OCA\News\Explore\RecommendedSites;
use OCA\News\Explore\RecommendedSiteNotFoundException;
use OCA\News\Db\FeedType;
@@ -33,32 +33,51 @@ class PageController extends Controller
{
use JSONHttpError;
+ /**
+ * @var IConfig
+ */
private $settings;
+
+ /**
+ * @var IL10N
+ */
private $l10n;
+
+ /**
+ * @var string
+ */
private $userId;
+
+ /**
+ * @var IURLGenerator
+ */
private $urlGenerator;
- private $config;
+
+ /**
+ * @var RecommendedSites
+ */
private $recommendedSites;
+ /**
+ * @var StatusService
+ */
private $statusService;
public function __construct(
- $appName,
+ string $appName,
IRequest $request,
IConfig $settings,
IURLGenerator $urlGenerator,
- Config $config,
IL10N $l10n,
RecommendedSites $recommendedSites,
StatusService $statusService,
- $UserId
+ string $UserId
) {
parent::__construct($appName, $request);
$this->settings = $settings;
$this->urlGenerator = $urlGenerator;
$this->l10n = $l10n;
$this->userId = $UserId;
- $this->config = $config;
$this->recommendedSites = $recommendedSites;
$this->statusService = $statusService;
}
@@ -109,7 +128,11 @@ class PageController extends Controller
'compactExpand'
];
- $exploreUrl = $this->config->getExploreUrl();
+ $exploreUrl = $this->settings->getAppValue(
+ $this->appName,
+ 'exploreUrl',
+ Application::DEFAULT_SETTINGS['exploreUrl']
+ );
if (trim($exploreUrl) === '') {
// default url should not feature the sites.en.json
$exploreUrl = $this->urlGenerator->linkToRoute(
@@ -142,28 +165,25 @@ class PageController extends Controller
* @param bool $compact
* @param bool $preventReadOnScroll
* @param bool $oldestFirst
+ * @param bool $compactExpand
*/
public function updateSettings(
- $showAll,
- $compact,
- $preventReadOnScroll,
- $oldestFirst,
- $compactExpand
+ bool $showAll,
+ bool $compact,
+ bool $preventReadOnScroll,
+ bool $oldestFirst,
+ bool $compactExpand
) {
$settings = [
- 'showAll',
- 'compact',
- 'preventReadOnScroll',
- 'oldestFirst',
- 'compactExpand'
+ 'showAll' => $showAll,
+ 'compact' => $compact,
+ 'preventReadOnScroll' => $preventReadOnScroll,
+ 'oldestFirst' => $oldestFirst,
+ 'compactExpand' => $compactExpand,
];
- foreach ($settings as $setting) {
- if (${$setting}) {
- $value = '1';
- } else {
- $value = '0';
- }
+ foreach ($settings as $setting => $value) {
+ $value = $value ? '1' : '0';
$this->settings->setUserValue(
$this->userId,
$this->appName,
@@ -178,7 +198,7 @@ class PageController extends Controller
*
* @param string $lang
*/
- public function explore($lang)
+ public function explore(string $lang)
{
$this->settings->setUserValue(
$this->userId,