diff options
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | README.rst | 18 | ||||
-rw-r--r-- | dependencyinjection/dicontainer.php | 2 | ||||
-rw-r--r-- | tests/unit/utility/ConfigTest.php | 39 | ||||
-rw-r--r-- | utility/config.php | 24 |
5 files changed, 41 insertions, 44 deletions
@@ -8,7 +8,7 @@ owncloud-news (1.401) * Throw proper error codes when creating invalid folders through the API * More whitespace to fit ownCloud 6 design better * Increased unread count from 99+ to maximum of 999+ because there is now more space -* Use a configuration file in data/news/config/config.json to not overwrite uservalues on update +* Use a configuration file in data/news/config/config.ini to not overwrite uservalues on update owncloud-news (1.206) * Also handle URLErrors in updater script that are thrown when the domain of a feed is not found diff --git a/README.rst b/README.rst index f4fb68959..1e5da0e1f 100644 --- a/README.rst +++ b/README.rst @@ -147,19 +147,17 @@ This problem is related to opcode caching, `check the issue tracker for how to s Configuration ------------- -All configuration values are set inside :file:`owncloud/data/news/config/config.json` +All configuration values are set inside :file:`owncloud/data/news/config/config.ini` -The configuration is in **JSON** and looks like this: +The configuration is in **INI** format and looks like this: -.. code-block:: js +.. code-block:: ini + + autoPurgeMinimumInterval = 60 + autoPurgeCount = 200 + simplePieCacheDuration = 1800 + feedFetcherTimeout = 60 - { - "autoPurgeMinimumInterval": 60, - "autoPurgeCount": 200, - "simplePieCacheDuration": 1800, - "feedFetcherTimeout": 60, - "useCronUpdates": true - } * **autoPurgeMinimumInterval**: Minimum amount of seconds after deleted feeds and folders are removed from the database. * **autoPurgeCount**: To let people have more read and unstarred items per feed before they are purged increase this value diff --git a/dependencyinjection/dicontainer.php b/dependencyinjection/dicontainer.php index 697ee0b88..650a402e2 100644 --- a/dependencyinjection/dicontainer.php +++ b/dependencyinjection/dicontainer.php @@ -91,7 +91,7 @@ class DIContainer extends BaseContainer { $this['Config'] = $this->share(function($c) { $config = new Config($c['configView'], $c['API']); - $config->read('config.json', true); + $config->read('config.ini', true); return $config; }); diff --git a/tests/unit/utility/ConfigTest.php b/tests/unit/utility/ConfigTest.php index 849fe37fd..455abf810 100644 --- a/tests/unit/utility/ConfigTest.php +++ b/tests/unit/utility/ConfigTest.php @@ -62,11 +62,12 @@ class ConfigFetcherTest extends \OCA\AppFramework\Utility\TestUtility { $this->fileSystem->expects($this->once()) ->method('file_get_contents') ->with($this->equalTo($this->configPath)) - ->will($this->returnValue('{"autoPurgeCount": 3}')); + ->will($this->returnValue("autoPurgeCount = 3\nuseCronUpdates = true")); $this->config->read($this->configPath); $this->assertEquals(3, $this->config->getAutoPurgeCount()); + $this->assertEquals(true, $this->config->getUseCronUpdates()); } @@ -74,7 +75,7 @@ class ConfigFetcherTest extends \OCA\AppFramework\Utility\TestUtility { $this->fileSystem->expects($this->once()) ->method('file_get_contents') ->with($this->equalTo($this->configPath)) - ->will($this->returnValue('{"autoPurgeCounts": 3}')); + ->will($this->returnValue('autoPurgeCounts = 3')); $this->api->expects($this->once()) ->method('log') ->with($this->equalTo('Configuration value "autoPurgeCounts" ' . @@ -85,14 +86,14 @@ class ConfigFetcherTest extends \OCA\AppFramework\Utility\TestUtility { } - public function testReadLogsInvalidJSON() { + public function testReadLogsInvalidINI() { $this->fileSystem->expects($this->once()) ->method('file_get_contents') ->with($this->equalTo($this->configPath)) - ->will($this->returnValue(null)); + ->will($this->returnValue('')); $this->api->expects($this->once()) ->method('log') - ->with($this->equalTo('Configuration contains invalid JSON'), + ->with($this->equalTo('Configuration invalid. Ignoring values.'), $this->equalTo('warn')); $this->config->read($this->configPath); @@ -100,13 +101,11 @@ class ConfigFetcherTest extends \OCA\AppFramework\Utility\TestUtility { public function testWrite () { - $json = "{\n" . - " \"autoPurgeMinimumInterval\": 60,\n" . - " \"autoPurgeCount\": 3,\n" . - " \"simplePieCacheDuration\": 1800,\n" . - " \"feedFetcherTimeout\": 60,\n" . - " \"useCronUpdates\": true\n" . - "}"; + $json = "autoPurgeMinimumInterval = 60\n" . + "autoPurgeCount = 3\n" . + "simplePieCacheDuration = 1800\n" . + "feedFetcherTimeout = 60\n" . + "useCronUpdates = true"; $this->config->setAutoPurgeCount(3); $this->fileSystem->expects($this->once()) @@ -123,14 +122,14 @@ class ConfigFetcherTest extends \OCA\AppFramework\Utility\TestUtility { ->method('file_exists') ->with($this->equalTo($this->configPath)) ->will($this->returnValue(false)); - - $json = "{\n" . - " \"autoPurgeMinimumInterval\": 60,\n" . - " \"autoPurgeCount\": 200,\n" . - " \"simplePieCacheDuration\": 1800,\n" . - " \"feedFetcherTimeout\": 60,\n" . - " \"useCronUpdates\": true\n" . - "}"; + + $this->config->setUseCronUpdates(false); + + $json = "autoPurgeMinimumInterval = 60\n" . + "autoPurgeCount = 200\n" . + "simplePieCacheDuration = 1800\n" . + "feedFetcherTimeout = 60\n" . + "useCronUpdates = false"; $this->fileSystem->expects($this->once()) ->method('file_put_contents') diff --git a/utility/config.php b/utility/config.php index e00ad940f..7841b3f5f 100644 --- a/utility/config.php +++ b/utility/config.php @@ -111,10 +111,10 @@ class Config { } else { $content = $this->fileSystem->file_get_contents($configPath); - $configValues = json_decode($content, true); + $configValues = parse_ini_string($content); - if($configValues === null) { - $this->api->log('Configuration contains invalid JSON' , 'warn'); + if($configValues === false || count($configValues) === 0) { + $this->api->log('Configuration invalid. Ignoring values.' , 'warn'); } else { foreach($configValues as $key => $value) { @@ -132,15 +132,15 @@ class Config { public function write($configPath) { - $json = json_encode(array( - "autoPurgeMinimumInterval" => $this->autoPurgeMinimumInterval, - "autoPurgeCount" => $this->autoPurgeCount, - "simplePieCacheDuration" => $this->simplePieCacheDuration, - "feedFetcherTimeout" => $this->feedFetcherTimeout, - "useCronUpdates" => $this->useCronUpdates, - ), JSON_PRETTY_PRINT); - - $this->fileSystem->file_put_contents($configPath, $json); + $ini = + "autoPurgeMinimumInterval = " . $this->autoPurgeMinimumInterval . "\n" . + "autoPurgeCount = " . $this->autoPurgeCount . "\n" . + "simplePieCacheDuration = " . $this->simplePieCacheDuration . "\n" . + "feedFetcherTimeout = " . $this->feedFetcherTimeout . "\n" . + "useCronUpdates = " . var_export($this->useCronUpdates, true) + ; + + $this->fileSystem->file_put_contents($configPath, $ini); } |