summaryrefslogtreecommitdiffstats
path: root/lib
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
parent2c8b4fa019749113658b9ed8cae211b679e4cbc0 (diff)
Move to nextcloud config and update phpunit
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php80
-rw-r--r--lib/Command/ShowFeed.php10
-rw-r--r--lib/Config/Config.php207
-rw-r--r--lib/Config/FetcherConfig.php31
-rw-r--r--lib/Config/LegacyConfig.php87
-rw-r--r--lib/Controller/AdminController.php94
-rw-r--r--lib/Controller/PageController.php68
-rw-r--r--lib/Cron/Updater.php25
-rwxr-xr-xlib/Fetcher/FeedFetcher.php3
-rw-r--r--lib/Migration/MigrateConfig.php59
-rw-r--r--lib/Scraper/Scraper.php5
-rw-r--r--lib/Service/FeedService.php15
-rw-r--r--lib/Service/FolderService.php16
-rw-r--r--lib/Service/ItemService.php15
-rw-r--r--lib/Service/StatusService.php16
-rw-r--r--lib/Settings/Admin.php44
-rw-r--r--lib/Settings/AdminSettings.php47
-rw-r--r--lib/Utility/PsrLogger.php97
-rw-r--r--lib/Utility/Updater.php12
19 files changed, 409 insertions, 522 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index b0d2d1e4f..005a264a4 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -18,28 +18,32 @@ use HTMLPurifier;
use HTMLPurifier_Config;
use Favicon\Favicon;
+use OC\Encryption\Update;
+use OCA\News\Config\LegacyConfig;
use OCA\News\Config\FetcherConfig;
+use OCA\News\Db\FolderMapper;
+use OCA\News\Service\FeedService;
+use OCA\News\Service\FolderService;
+use OCA\News\Service\ItemService;
use OCA\News\Utility\PsrLogger;
-use OCP\BackgroundJob\IJobList;
+use OCA\News\Utility\Updater;
use OCP\IContainer;
-use OCP\INavigationManager;
-use OCP\IURLGenerator;
use OCP\IConfig;
+use OCP\ILogger;
use OCP\ITempManager;
use OCP\AppFramework\App;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
-use OCA\News\Config\AppConfig;
-use OCA\News\Config\Config;
use OCA\News\Db\MapperFactory;
use OCA\News\Db\ItemMapper;
use OCA\News\Fetcher\FeedFetcher;
use OCA\News\Fetcher\Fetcher;
use OCA\News\Fetcher\YoutubeFetcher;
use OCA\News\Scraper\Scraper;
+use Psr\Log\LoggerInterface;
/**
* Class Application
@@ -50,13 +54,31 @@ class Application extends App
{
/**
+ * App Name
+ */
+ public const NAME = 'news';
+
+ /**
+ * List of default settings
+ */
+ public const DEFAULT_SETTINGS = [
+ 'autoPurgeMinimumInterval' => 60,
+ 'autoPurgeCount' => 200,
+ 'maxRedirects' => 10,
+ 'feedFetcherTimeout' => 60,
+ 'useCronUpdates' => true,
+ 'exploreUrl' => '',
+ 'updateInterval' => 3600,
+ ];
+
+ /**
* Application constructor.
*
* @param array $urlParams Parameters
*/
public function __construct(array $urlParams = [])
{
- parent::__construct('news', $urlParams);
+ parent::__construct(self::NAME, $urlParams);
$container = $this->getContainer();
@@ -78,58 +100,30 @@ class Application extends App
});
/**
- * App config parser.
- */
- $container->registerService(AppConfig::class, function (IContainer $c): AppConfig {
- $config = new AppConfig(
- $c->query(INavigationManager::class),
- $c->query(IURLGenerator::class),
- $c->query(IJobList::class)
- );
-
- $config->loadConfig($c->query('info'));
- return $config;
- });
-
- /**
* Core
*/
$container->registerService('LoggerParameters', function (IContainer $c): array {
return ['app' => $c->query('AppName')];
});
- $container->registerService('databaseType', function (IContainer $c) {
- return $c->query(IConfig::class)->getSystemValue('dbtype');
- });
-
- $container->registerService('ConfigView', function (IContainer $c): Node {
+ $container->registerService('ConfigView', function (IContainer $c): ?Node {
/** @var IRootFolder $fs */
$fs = $c->query(IRootFolder::class);
$path = 'news/config';
if ($fs->nodeExists($path)) {
return $fs->get($path);
} else {
- return $fs->newFolder($path);
+ return null;
}
});
- /**
- * Logger base
- */
- $container->registerService(PsrLogger::class, function (IContainer $c): PsrLogger {
- return new PsrLogger(
- $c->query('ServerContainer')->getLogger(),
- $c->query('AppName')
- );
- });
-
- $container->registerService(Config::class, function (IContainer $c): Config {
- $config = new Config(
+ $container->registerService(LegacyConfig::class, function (IContainer $c): LegacyConfig {
+ $config = new LegacyConfig(
$c->query('ConfigView'),
- $c->query(PsrLogger::class),
+ $c->query(LoggerInterface::class),
$c->query('LoggerParameters')
);
- $config->read($c->query('configFile'), true);
+ $config->read($c->query('configFile'), false);
return $config;
});
@@ -175,7 +169,7 @@ class Application extends App
*/
$container->registerService(FetcherConfig::class, function (IContainer $c): FetcherConfig {
$fConfig = new FetcherConfig();
- $fConfig->setConfig($c->query(Config::class))
+ $fConfig->setConfig($c->query(IConfig::class))
->setProxy($c->query(IConfig::class));
return $fConfig;
@@ -183,7 +177,7 @@ class Application extends App
$container->registerService(FeedIo::class, function (IContainer $c): FeedIo {
$config = $c->query(FetcherConfig::class);
- return new FeedIo($config->getClient(), $c->query(PsrLogger::class));
+ return new FeedIo($config->getClient(), $c->query(LoggerInterface::class));
});
$container->registerService(Favicon::class, function (IContainer $c): Favicon {
@@ -209,7 +203,7 @@ class Application extends App
*/
$container->registerService(Scraper::class, function (IContainer $c): Scraper {
return new Scraper(
- $c->query(PsrLogger::class)
+ $c->query(LoggerInterface::class)
);
});
}
diff --git a/lib/Command/ShowFeed.php b/lib/Command/ShowFeed.php
index 572b68e26..878b71123 100644
--- a/lib/Command/ShowFeed.php
+++ b/lib/Command/ShowFeed.php
@@ -13,7 +13,15 @@ namespace OCA\News\Command;
use FeedIo\FeedIo;
use Favicon\Favicon;
+use HTMLPurifier;
+use OCA\News\Db\FeedMapper;
+use OCA\News\Db\ItemMapper;
use OCA\News\Fetcher\Fetcher;
+use OCA\News\Service\FeedService;
+use OCA\News\Utility\Time;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\ILogger;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
@@ -38,8 +46,8 @@ class ShowFeed extends Command
*/
public function __construct(Fetcher $feedFetcher)
{
- $this->feedFetcher = $feedFetcher;
parent::__construct();
+ $this->feedFetcher = $feedFetcher;
}
protected function configure()
diff --git a/lib/Config/Config.php b/lib/Config/Config.php
deleted file mode 100644
index 97099db48..000000000
--- a/lib/Config/Config.php
+++ /dev/null
@@ -1,207 +0,0 @@
-<?php
-/**
- * Nextcloud - News
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright 2012 Alessandro Cosentino
- * @copyright 2012-2014 Bernhard Posselt
- */
-
-namespace OCA\News\Config;
-
-use OCA\News\Utility\PsrLogger;
-use OCP\Files\Folder;
-
-class Config
-{
-
- private $fileSystem;
- private $autoPurgeMinimumInterval; // seconds, used to define how
- // long deleted folders and feeds
- // should still be kept for an
- // undo actions
- private $autoPurgeCount; // number of allowed unread articles per feed
- private $maxRedirects; // seconds
- private $feedFetcherTimeout; // seconds
- private $useCronUpdates; // turn off updates run by the cron
- private $logger;
- private $loggerParams;
- private $maxSize;
- private $exploreUrl;
- private $updateInterval;
-
- public function __construct(
- Folder $fileSystem,
- PsrLogger $logger,
- $LoggerParameters
- ) {
- $this->fileSystem = $fileSystem;
- $this->autoPurgeMinimumInterval = 60;
- $this->autoPurgeCount = 200;
- $this->maxRedirects = 10;
- $this->maxSize = 100 * 1024 * 1024; // 100Mb
- $this->feedFetcherTimeout = 60;
- $this->useCronUpdates = true;
- $this->logger = $logger;
- $this->exploreUrl = '';
- $this->loggerParams = $LoggerParameters;
- $this->updateInterval = 3600;
- }
-
- public function getAutoPurgeMinimumInterval()
- {
- if ($this->autoPurgeMinimumInterval > 60) {
- return $this->autoPurgeMinimumInterval;
- } else {
- return 60;
- }
- }
-
- public function getAutoPurgeCount()
- {
- return $this->autoPurgeCount;
- }
-
-
- public function getMaxRedirects()
- {
- return $this->maxRedirects;
- }
-
-
- public function getFeedFetcherTimeout()
- {
- return $this->feedFetcherTimeout;
- }
-
-
- public function getUseCronUpdates()
- {
- return $this->useCronUpdates;
- }
-
-
- public function getMaxSize()
- {
- return $this->maxSize;
- }
-
-
- public function getExploreUrl()
- {
- return $this->exploreUrl;
- }
-
- public function getUpdateInterval()
- {
- return $this->updateInterval;
- }
-
- public function setAutoPurgeMinimumInterval($value)
- {
- $this->autoPurgeMinimumInterval = $value;
- }
-
-
- public function setAutoPurgeCount($value)
- {
- $this->autoPurgeCount = $value;
- }
-
-
- public function setMaxRedirects($value)
- {
- $this->maxRedirects = $value;
- }
-
-
- public function setFeedFetcherTimeout($value)
- {
- $this->feedFetcherTimeout = $value;
- }
-
-
- public function setUseCronUpdates($value)
- {
- $this->useCronUpdates = $value;
- }
-
- public function setMaxSize($value)
- {
- $this->maxSize = $value;
- }
-
-
- public function setExploreUrl($value)
- {
- $this->exploreUrl = $value;
- }
-
- public function setUpdateInterval($value)
- {
- $this->updateInterval = $value;
- }
-
-
-
- public function read($configPath, $createIfNotExists = false)
- {
- if ($createIfNotExists && !$this->fileSystem->nodeExists($configPath)) {
- $this->fileSystem->newFile($configPath);
- $this->write($configPath);
- } else {
- $content = $this->fileSystem->get($configPath)->getContent();
- $configValues = parse_ini_string($content);
-
- if ($configValues === false || count($configValues) === 0) {
- $this->logger->warning(
- 'Configuration invalid. Ignoring values.',
- $this->loggerParams
- );
- } else {
- foreach ($configValues as $key => $value) {
- if (property_exists($this, $key)) {
- $type = gettype($this->$key);
- settype($value, $type);
- $this->$key = $value;
- } else {
- $this->logger->warning(
- 'Configuration value "' . $key .
- '" does not exist. Ignored value.',
- $this->loggerParams
- );
- }
- }
- }
- }
- }
-
-
- public function write($configPath)
- {
- $ini =
- 'autoPurgeMinimumInterval = ' .
- $this->autoPurgeMinimumInterval . "\n" .
- 'autoPurgeCount = ' .
- $this->autoPurgeCount . "\n" .
- 'maxRedirects = ' .
- $this->maxRedirects . "\n" .
- 'maxSize = ' .
- $this->maxSize . "\n" .
- 'exploreUrl = ' .
- $this->exploreUrl . "\n" .
- 'feedFetcherTimeout = ' .
- $this->feedFetcherTimeout . "\n" .
- 'updateInterval = ' .
- $this->updateInterval . "\n" .
- 'useCronUpdates = ' .
- var_export($this->useCronUpdates, true);
- ;
-
- $this->fileSystem->get($configPath)->putContent($ini);
- }
-}
diff --git a/lib/Config/FetcherConfig.php b/lib/Config/FetcherConfig.php
index 866f9a4f1..1e9b7941e 100644
--- a/lib/Config/FetcherConfig.php
+++ b/lib/Config/FetcherConfig.php
@@ -15,6 +15,7 @@ namespace OCA\News\Config;
use FeedIo\Adapter\ClientInterface;
use \GuzzleHttp\Client;
+use OCA\News\AppInfo\Application;
use OCA\News\Fetcher\Client\FeedIoClient;
use OCA\News\Fetcher\Client\LegacyGuzzleClient;
use OCP\IConfig;
@@ -45,13 +46,6 @@ class FetcherConfig
protected $redirects;
/**
- * Max size of the recieved data.
- * @deprecated guzzle can't handle this
- * @var string
- */
- protected $max_size;
-
- /**
* User agent for the client.
* @var string
*/
@@ -96,8 +90,7 @@ class FetcherConfig
$config['redirect.max'] = $this->redirects;
}
- $guzzle = new Client($config);
- return $guzzle;
+ return new Client($config);
}
/**
@@ -121,22 +114,28 @@ class FetcherConfig
$config['request.options']['redirect.max'] = $this->redirects;
}
- $guzzle = new Client($config);
- return $guzzle;
+ return new Client($config);
}
/**
* Set settings for config.
*
- * @param Config $config The shared configuration
+ * @param IConfig $config The shared configuration
*
* @return self
*/
- public function setConfig(Config $config)
+ public function setConfig(IConfig $config)
{
- $this->client_timeout = $config->getFeedFetcherTimeout();
- $this->redirects = $config->getMaxRedirects();
- $this->max_size = $config->getMaxSize();
+ $this->client_timeout = $config->getAppValue(
+ Application::NAME,
+ 'feedFetcherTimeout',
+ Application::DEFAULT_SETTINGS['feedFetcherTimeout']
+ );
+ $this->redirects = $config->getAppValue(
+ Application::NAME,
+ 'maxRedirects',
+ Application::DEFAULT_SETTINGS['maxRedirects']
+ );
return $this;
}
diff --git a/lib/Config/LegacyConfig.php b/lib/Config/LegacyConfig.php
new file mode 100644
index 000000000..71e19acfa
--- /dev/null
+++ b/lib/Config/LegacyConfig.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Nextcloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
+ */
+
+namespace OCA\News\Config;
+
+use OCA\News\AppInfo\Application;
+use OCA\News\Utility\PsrLogger;
+use OCP\Files\Folder;
+use OCP\IConfig;
+use Psr\Log\LoggerInterface;
+
+class LegacyConfig
+{
+
+ private $fileSystem;
+ public $autoPurgeMinimumInterval; // seconds, used to define how
+ // long deleted folders and feeds
+ // should still be kept for an
+ // undo actions
+ public $autoPurgeCount; // number of allowed unread articles per feed
+ public $maxRedirects; // seconds
+ public $feedFetcherTimeout; // seconds
+ public $useCronUpdates; // turn off updates run by the cron
+ public $logger;
+ public $loggerParams;
+ public $maxSize;
+ public $exploreUrl;
+ public $updateInterval;
+
+ public function __construct(
+ ?Folder $fileSystem,
+ LoggerInterface $logger,
+ $LoggerParameters
+ ) {
+ $this->fileSystem = $fileSystem;
+ $this->autoPurgeMinimumInterval = 60;
+ $this->autoPurgeCount = 200;
+ $this->maxRedirects = 10;
+ $this->maxSize = 100 * 1024 * 1024; // 100Mb
+ $this->feedFetcherTimeout = 60;
+ $this->useCronUpdates = true;
+ $this->logger = $logger;
+ $this->exploreUrl = '';
+ $this->loggerParams = $LoggerParameters;
+ $this->updateInterval = 3600;
+ }
+
+ public function read($configPath, $createIfNotExists = false)
+ {
+ if ($this->fileSystem === null) {
+ return;
+ }
+ $content = $this->fileSystem->get($configPath)->getContent();
+ $configValues = parse_ini_string($content);
+
+ if ($configValues === false || count($configValues) === 0) {
+ $this->logger->warning(
+ 'Configuration invalid. Ignoring values.',
+ $this->loggerParams
+ );
+ } else {
+ foreach ($configValues as $key => $value) {
+ if (property_exists($this, $key)) {
+ $type = gettype($this->$key);
+ settype($value, $type);
+ $this->$key = $value;
+ } else {
+ $this->logger->warning(
+ 'Configuration value "' . $key .
+ '" does not exist. Ignored value.',
+ $this->loggerParams
+ );
+ }
+ }
+ }
+ }
+}
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,
diff --git a/lib/Cron/Updater.php b/lib/Cron/Updater.php
index a33d7e7c1..3d9336df7 100644
--- a/lib/Cron/Updater.php
+++ b/