summaryrefslogtreecommitdiffstats
path: root/lib/Config
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/Config
parent2c8b4fa019749113658b9ed8cae211b679e4cbc0 (diff)
Move to nextcloud config and update phpunit
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib/Config')
-rw-r--r--lib/Config/Config.php207
-rw-r--r--lib/Config/FetcherConfig.php31
-rw-r--r--lib/Config/LegacyConfig.php87
3 files changed, 102 insertions, 223 deletions
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
+ );
+ }
+ }
+ }
+ }
+}