Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions changelog/unreleased/40413
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Enhancement: Setting for recursive extra config.php search

Before this change extra config.php files were required to be placed directly in the config folder.
This change allows to have nested folders configuration structure,
enabled by config value OC_CONFIG_EXTRA_RECURSIVE_SEARCH, that can be useful in some deployments.

NOTE: due to the fact that `config_extra_recursive_search` setting controls the configuration itself,
it is only possible to enable this via environment variable. It is not possible to enable it with *.config.php file.

https://github.com/owncloud/core/pull/40413
https://github.com/owncloud/enterprise/issues/5406
29 changes: 28 additions & 1 deletion lib/private/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,33 @@ protected function delete($key) {
], 'config', 'deletevalue');
}

/**
* This function scans for extra config.php files.
*
* NOTE: due to the fact that `config_extra_recursive_search` setting controls the configuration itself,
* it is only possible to enable this via environment variable. It is not possible to enable it with *.config.php file.
*
* @return string[] paths to extra config.php files
*/
private function findExtraConfigFiles() {
if ($this->getValue('config_extra_recursive_search', false) === 'true') {
$foundConfigFiles = [];
$configItr = new \RecursiveDirectoryIterator($this->configDir);
foreach (new \RecursiveIteratorIterator($configItr) as $file) {
// find all extra config files matching config file name,
// except for default config filepath
if (\preg_match("/{$this->configFileName}\$/", $file->getFileName()) &&
$file->getPathName() !== $this->configFilePath) {
$foundConfigFiles[] = $file->getPathName();
}
}
return $foundConfigFiles;
} else {
// default is to search in config directory (as of owncloud 10.11)
return \glob($this->configDir . '*.' . $this->configFileName);
}
}

/**
* Loads the config file
*
Expand All @@ -228,7 +255,7 @@ private function readData() {
$configFiles = [$this->configFilePath];

// Add all files in the config dir ending with the same file name
$extra = \glob($this->configDir.'*.'.$this->configFileName);
$extra = $this->findExtraConfigFiles();
if (\is_array($extra)) {
\natsort($extra);
$configFiles = \array_merge($configFiles, $extra);
Expand Down
42 changes: 42 additions & 0 deletions tests/lib/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,48 @@ public function testConfigMerge() {
\unlink($additionalConfigPath);
}

public function providerNestedConfig() {
return [
[true],
[false]
];
}

/**
* @dataProvider providerNestedConfig
*
* @param boolean $configExtraRecursiveSearchEnabled
*/
public function testNestedConfig($configExtraRecursiveSearchEnabled) {
// enable recursive search for extra config files
if ($configExtraRecursiveSearchEnabled) {
\putenv('OC_config_extra_recursive_search=true');
}

// Create additional config in nested dir
\mkdir($this->randomTmpDir.'nested1', 0755, true);
$additionalConfig = '<?php $CONFIG=array("php53"=>"totallyOutdated");';
$additionalConfigPath = $this->randomTmpDir.'nested1/additionalConfig.testconfig.php';
\file_put_contents($additionalConfigPath, $additionalConfig);

// Reinstantiate the config to force a read-in of the additional configs
$this->config = new \OC\Config($this->randomTmpDir, 'testconfig.php');

if ($configExtraRecursiveSearchEnabled) {
// nested config got correctly read
$this->assertSame('totallyOutdated', $this->config->getValue('php53', 'defaultValue'));
$this->assertStringEqualsFile($this->configFile, self::TESTCONTENT);
} else {
// nested config got ignored
$this->assertSame('defaultValue', $this->config->getValue('php53', 'defaultValue'));
$this->assertStringEqualsFile($this->configFile, self::TESTCONTENT);
}

// Cleanup
\putenv('OC_config_extra_recursive_search');
\unlink($additionalConfigPath);
}

private function checkConfigMatchesExpected($expectedConfig) {
foreach ($expectedConfig as $key => $value) {
$this->assertEquals($value, $this->config->getValue($key));
Expand Down