Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <tsteur@users.noreply.github.com>2019-03-11 08:06:06 +0300
committerGitHub <noreply@github.com>2019-03-11 08:06:06 +0300
commit5f1d88e08efa92bd25c8109bc71d75ff16bb9c55 (patch)
tree9b89f6dc51f063b06c6adde8d65e0113d2c3f2da /core/Config.php
parenta345c2f22b8356dd3300d66f5ade3df24f69d900 (diff)
Allow config files to be placed per hostname in misc/user directory (#13999)
Diffstat (limited to 'core/Config.php')
-rw-r--r--core/Config.php65
1 files changed, 46 insertions, 19 deletions
diff --git a/core/Config.php b/core/Config.php
index 4f2d6f33cd..533ca78311 100644
--- a/core/Config.php
+++ b/core/Config.php
@@ -145,12 +145,23 @@ class Config
private static function getLocalConfigInfoForHostname($hostname)
{
+ if (!$hostname) {
+ return array();
+ }
+
// Remove any port number to get actual hostname
$hostname = Url::getHostSanitized($hostname);
- $perHostFilename = $hostname . '.config.ini.php';
+ $standardConfigName = 'config.ini.php';
+ $perHostFilename = $hostname . '.' . $standardConfigName;
$pathDomainConfig = PIWIK_USER_PATH . '/config/' . $perHostFilename;
+ $pathDomainMiscUser = PIWIK_USER_PATH . '/misc/user/' . $hostname . '/' . $standardConfigName;
+
+ $locations = array(
+ array('file' => $perHostFilename, 'path' => $pathDomainConfig),
+ array('file' => $standardConfigName, 'path' => $pathDomainMiscUser)
+ );
- return array('file' => $perHostFilename, 'path' => $pathDomainConfig);
+ return $locations;
}
public function getConfigHostnameIfSet()
@@ -190,13 +201,16 @@ class Config
public static function getByDomainConfigPath()
{
$host = self::getHostname();
- $hostConfig = self::getLocalConfigInfoForHostname($host);
+ $hostConfigs = self::getLocalConfigInfoForHostname($host);
- if (Filesystem::isValidFilename($hostConfig['file'])
- && file_exists($hostConfig['path'])
- ) {
- return $hostConfig['path'];
+ foreach ($hostConfigs as $hostConfig) {
+ if (Filesystem::isValidFilename($hostConfig['file'])
+ && file_exists($hostConfig['path'])
+ ) {
+ return $hostConfig['path'];
+ }
}
+
return false;
}
@@ -225,28 +239,41 @@ class Config
* $config->save();
*
* @param string $hostname eg piwik.example.com
+ * @param string $preferredPath If there are different paths for the config that can be used, eg /config/* and /misc/user/*,
+ * and a preferred path is given, then the config path must contain the preferred path.
* @return string
* @throws \Exception In case the domain contains not allowed characters
* @internal
*/
- public function forceUsageOfLocalHostnameConfig($hostname)
+ public function forceUsageOfLocalHostnameConfig($hostname, $preferredPath = null)
{
- $hostConfig = self::getLocalConfigInfoForHostname($hostname);
+ $hostConfigs = self::getLocalConfigInfoForHostname($hostname);
+ $fileNames = '';
- $filename = $hostConfig['file'];
- if (!Filesystem::isValidFilename($filename)) {
- throw new Exception('Matomo domain is not a valid looking hostname (' . $filename . ').');
- }
+ foreach ($hostConfigs as $hostConfig) {
+ if (count($hostConfigs) > 1
+ && $preferredPath
+ && strpos($hostConfig['path'], $preferredPath) === false) {
+ continue;
+ }
- $pathLocal = $hostConfig['path'];
+ $filename = $hostConfig['file'];
+ $fileNames .= $filename . ' ';
- try {
- $this->reload($pathLocal);
- } catch (Exception $ex) {
- // pass (not required for local file to exist at this point)
+ if (Filesystem::isValidFilename($filename)) {
+ $pathLocal = $hostConfig['path'];
+
+ try {
+ $this->reload($pathLocal);
+ } catch (Exception $ex) {
+ // pass (not required for local file to exist at this point)
+ }
+
+ return $pathLocal;
+ }
}
- return $pathLocal;
+ throw new Exception('Matomo domain is not a valid looking hostname (' . trim($fileNames) . ').');
}
/**