From e620f0ba6d80381d896d5e6a06cb35a345a3cf37 Mon Sep 17 00:00:00 2001 From: mattab Date: Mon, 19 May 2014 15:30:42 +1200 Subject: Fixes #5181 Renamed method --- config/global.ini.php | 5 +++ core/AssetManager.php | 2 +- core/CacheFile.php | 2 +- core/CliMulti.php | 2 +- core/Db/BatchInsert.php | 2 +- core/Filechecks.php | 2 +- core/Log.php | 2 +- core/ReportRenderer.php | 2 +- core/Session.php | 4 +-- core/SettingsPiwik.php | 45 ++++++++++++++++++------ core/Twig.php | 2 +- core/Url.php | 7 +--- plugins/CoreAdminHome/CustomLogo.php | 2 +- plugins/CoreConsole/Commands/WatchLog.php | 2 +- plugins/CorePluginsAdmin/PluginInstaller.php | 6 ++-- plugins/CoreUpdater/Controller.php | 4 +-- plugins/ImageGraph/StaticGraph.php | 2 +- plugins/ScheduledReports/config/tcpdf_config.php | 2 +- tests/PHPUnit/Core/DeprecatedMethodsTest.php | 3 ++ tests/PHPUnit/Integration/Core/LogTest.php | 2 +- 20 files changed, 63 insertions(+), 37 deletions(-) diff --git a/config/global.ini.php b/config/global.ini.php index c8eb245981..8722c0e5d9 100644 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -358,6 +358,11 @@ enable_trusted_host_check = 1 ;trusted_hosts[] = example.com ;trusted_hosts[] = stats.example.com +; If you use this Piwik instance over multiple hostnames, Piwik will need to know +; a unique instance_id for this instance, so that Piwik can serve the right custom logo and tmp/* assets, +; independantly of the hostname Piwik is currently running under. +; instance_id = stats.example.com + ; The release server is an essential part of the Piwik infrastructure/ecosystem ; to provide the latest software version. latest_version_url = http://builds.piwik.org/latest.zip diff --git a/core/AssetManager.php b/core/AssetManager.php index 90185a43f3..4a0de2e3b0 100644 --- a/core/AssetManager.php +++ b/core/AssetManager.php @@ -253,7 +253,7 @@ class AssetManager extends Singleton public function getAssetDirectory() { $mergedFileDirectory = PIWIK_USER_PATH . "/tmp/assets"; - $mergedFileDirectory = SettingsPiwik::rewriteTmpPathWithHostname($mergedFileDirectory); + $mergedFileDirectory = SettingsPiwik::rewriteTmpPathWithInstanceId($mergedFileDirectory); if (!is_dir($mergedFileDirectory)) { Filesystem::mkdir($mergedFileDirectory); diff --git a/core/CacheFile.php b/core/CacheFile.php index 043770b3db..5d9000332f 100644 --- a/core/CacheFile.php +++ b/core/CacheFile.php @@ -43,7 +43,7 @@ class CacheFile public function __construct($directory, $timeToLiveInSeconds = 300) { $cachePath = PIWIK_USER_PATH . '/tmp/cache/' . $directory . '/'; - $this->cachePath = SettingsPiwik::rewriteTmpPathWithHostname($cachePath); + $this->cachePath = SettingsPiwik::rewriteTmpPathWithInstanceId($cachePath); if ($timeToLiveInSeconds < self::MINIMUM_TTL) { $timeToLiveInSeconds = self::MINIMUM_TTL; diff --git a/core/CliMulti.php b/core/CliMulti.php index cb53c4ed4a..740528ecb3 100644 --- a/core/CliMulti.php +++ b/core/CliMulti.php @@ -203,7 +203,7 @@ class CliMulti { public static function getTmpPath() { $dir = PIWIK_INCLUDE_PATH . '/tmp/climulti'; - return SettingsPiwik::rewriteTmpPathWithHostname($dir); + return SettingsPiwik::rewriteTmpPathWithInstanceId($dir); } private function findPhpBinary() diff --git a/core/Db/BatchInsert.php b/core/Db/BatchInsert.php index 659954d06a..3a05e516d6 100644 --- a/core/Db/BatchInsert.php +++ b/core/Db/BatchInsert.php @@ -59,7 +59,7 @@ class BatchInsert public static function tableInsertBatch($tableName, $fields, $values, $throwException = false) { $filePath = PIWIK_USER_PATH . '/tmp/assets/' . $tableName . '-' . Common::generateUniqId() . '.csv'; - $filePath = SettingsPiwik::rewriteTmpPathWithHostname($filePath); + $filePath = SettingsPiwik::rewriteTmpPathWithInstanceId($filePath); $loadDataInfileEnabled = Config::getInstance()->General['enable_load_data_infile']; diff --git a/core/Filechecks.php b/core/Filechecks.php index 52cb995bad..7bbf0f1162 100644 --- a/core/Filechecks.php +++ b/core/Filechecks.php @@ -44,7 +44,7 @@ class Filechecks } if(strpos($directoryToCheck, '/tmp/') !== false) { - $directoryToCheck = SettingsPiwik::rewriteTmpPathWithHostname($directoryToCheck); + $directoryToCheck = SettingsPiwik::rewriteTmpPathWithInstanceId($directoryToCheck); } Filesystem::mkdir($directoryToCheck); diff --git a/core/Log.php b/core/Log.php index 09d548a7f0..ab4093cb5f 100644 --- a/core/Log.php +++ b/core/Log.php @@ -323,7 +323,7 @@ class Log extends Singleton ) { $logPath = PIWIK_USER_PATH . DIRECTORY_SEPARATOR . $logPath; } - $logPath = SettingsPiwik::rewriteTmpPathWithHostname($logPath); + $logPath = SettingsPiwik::rewriteTmpPathWithInstanceId($logPath); if (is_dir($logPath)) { $logPath .= '/piwik.log'; } diff --git a/core/ReportRenderer.php b/core/ReportRenderer.php index 4634f9197c..42a5f72570 100644 --- a/core/ReportRenderer.php +++ b/core/ReportRenderer.php @@ -144,7 +144,7 @@ abstract class ReportRenderer protected static function getOutputPath($filename) { $outputFilename = PIWIK_USER_PATH . '/tmp/assets/' . $filename; - $outputFilename = SettingsPiwik::rewriteTmpPathWithHostname($outputFilename); + $outputFilename = SettingsPiwik::rewriteTmpPathWithInstanceId($outputFilename); @chmod($outputFilename, 0600); @unlink($outputFilename); diff --git a/core/Session.php b/core/Session.php index b2e91f7e68..7cf8ab4f9c 100644 --- a/core/Session.php +++ b/core/Session.php @@ -122,7 +122,7 @@ class Session extends Zend_Session } $pathToSessions = Filechecks::getErrorMessageMissingPermissions(Filesystem::getPathToPiwikRoot() . '/tmp/sessions/'); - $pathToSessions = SettingsPiwik::rewriteTmpPathWithHostname($pathToSessions); + $pathToSessions = SettingsPiwik::rewriteTmpPathWithInstanceId($pathToSessions); $message = sprintf("Error: %s %s %s\n
Debug: the original error was \n%s
", Piwik::translate('General_ExceptionUnableToStartSession'), $pathToSessions, @@ -142,7 +142,7 @@ class Session extends Zend_Session public static function getSessionsDirectory() { $path = PIWIK_USER_PATH . '/tmp/sessions'; - return SettingsPiwik::rewriteTmpPathWithHostname($path); + return SettingsPiwik::rewriteTmpPathWithInstanceId($path); } public static function close() diff --git a/core/SettingsPiwik.php b/core/SettingsPiwik.php index 723ea065dc..61b27607e3 100644 --- a/core/SettingsPiwik.php +++ b/core/SettingsPiwik.php @@ -256,16 +256,24 @@ class SettingsPiwik return $result; } + /** + * @deprecated Use SettingsPiwik::rewriteTmpPathWithInstanceId instead + */ + public static function rewriteTmpPathWithHostname($path) + { + return self::rewriteTmpPathWithInstanceId($path); + } + /** * If Piwik uses per-domain config file, also make tmp/ folder per-domain * @param $path * @return string * @throws \Exception */ - public static function rewriteTmpPathWithHostname($path) + public static function rewriteTmpPathWithInstanceId($path) { $tmp = '/tmp/'; - $path = self::rewritePathAppendHostname($path, $tmp); + $path = self::rewritePathAppendPiwikInstanceId($path, $tmp); return $path; } @@ -274,10 +282,10 @@ class SettingsPiwik * @param $path * @return mixed */ - public static function rewriteMiscUserPathWithHostname($path) + public static function rewriteMiscUserPathWithInstanceId($path) { $tmp = 'misc/user/'; - $path = self::rewritePathAppendHostname($path, $tmp); + $path = self::rewritePathAppendPiwikInstanceId($path, $tmp); return $path; } @@ -345,10 +353,10 @@ class SettingsPiwik * @return mixed * @throws \Exception */ - protected static function rewritePathAppendHostname($pathToRewrite, $leadingPathToAppendHostnameTo) + protected static function rewritePathAppendPiwikInstanceId($pathToRewrite, $leadingPathToAppendHostnameTo) { - $hostname = self::getConfigHostname(); - if (empty($hostname)) { + $instanceId = self::getPiwikInstanceId(); + if (empty($instanceId)) { return $pathToRewrite; } @@ -356,7 +364,7 @@ class SettingsPiwik throw new Exception("The path $pathToRewrite was expected to contain the string $leadingPathToAppendHostnameTo"); } - $tmpToReplace = $leadingPathToAppendHostnameTo . $hostname . '/'; + $tmpToReplace = $leadingPathToAppendHostnameTo . $instanceId . '/'; // replace only the latest occurrence (in case path contains twice /tmp) $pathToRewrite = substr_replace($pathToRewrite, $tmpToReplace, $posTmp, strlen($leadingPathToAppendHostnameTo)); @@ -364,16 +372,31 @@ class SettingsPiwik } /** - * @return bool|string + * @throws \Exception + * @return string or False if not set */ - protected static function getConfigHostname() + protected static function getPiwikInstanceId() { + // until Piwik is installed, we use hostname as instance_id if(!self::isPiwikInstalled() && Common::isPhpCliMode()) { // enterprise:install use case return Config::getHostname(); } - return Config::getInstance()->getConfigHostnameIfSet(); + + $instanceId = @Config::getInstance()->General['instance_id']; + if(!empty($instanceId)) { + return $instanceId; + } + + // Backward compatbility, in case the instance_id is not in the config file yet + $configHostname = Config::getInstance()->getConfigHostnameIfSet(); + if(!empty($configHostname)) { + return $configHostname; + } + + // do not rewrite the path as Piwik uses the standard config.ini.php file + return false; } /** diff --git a/core/Twig.php b/core/Twig.php index 6b628c9be7..8c5ce8a2ef 100755 --- a/core/Twig.php +++ b/core/Twig.php @@ -60,7 +60,7 @@ class Twig // Create new Twig Environment and set cache dir $templatesCompiledPath = PIWIK_USER_PATH . '/tmp/templates_c'; - $templatesCompiledPath = SettingsPiwik::rewriteTmpPathWithHostname($templatesCompiledPath); + $templatesCompiledPath = SettingsPiwik::rewriteTmpPathWithInstanceId($templatesCompiledPath); $this->twig = new Twig_Environment($chainLoader, array( diff --git a/core/Url.php b/core/Url.php index 7d5d05d08d..fbcd379df5 100644 --- a/core/Url.php +++ b/core/Url.php @@ -557,12 +557,7 @@ class Url public static function getTrustedHosts() { - $trustedHosts = self::getTrustedHostsFromConfig(); - - /* used by Piwik PRO */ - Piwik::postEvent('Url.filterTrustedHosts', array(&$trustedHosts)); - - return $trustedHosts; + return self::getTrustedHostsFromConfig(); } /** diff --git a/plugins/CoreAdminHome/CustomLogo.php b/plugins/CoreAdminHome/CustomLogo.php index f4c95c49b3..7f543973c3 100644 --- a/plugins/CoreAdminHome/CustomLogo.php +++ b/plugins/CoreAdminHome/CustomLogo.php @@ -147,7 +147,7 @@ class CustomLogo protected static function rewritePath($path) { - return SettingsPiwik::rewriteMiscUserPathWithHostname($path); + return SettingsPiwik::rewriteMiscUserPathWithInstanceId($path); } public function copyUploadedLogoToFilesystem() diff --git a/plugins/CoreConsole/Commands/WatchLog.php b/plugins/CoreConsole/Commands/WatchLog.php index ce89fa85e4..fc06dae46a 100644 --- a/plugins/CoreConsole/Commands/WatchLog.php +++ b/plugins/CoreConsole/Commands/WatchLog.php @@ -27,7 +27,7 @@ class WatchLog extends ConsoleCommand protected function execute(InputInterface $input, OutputInterface $output) { $path = sprintf('%s/tmp/logs/', PIWIK_DOCUMENT_ROOT); - $path = SettingsPiwik::rewriteTmpPathWithHostname($path); + $path = SettingsPiwik::rewriteTmpPathWithInstanceId($path); $cmd = sprintf('tail -f %s*.log', $path); $output->writeln('Executing command: ' . $cmd); diff --git a/plugins/CorePluginsAdmin/PluginInstaller.php b/plugins/CorePluginsAdmin/PluginInstaller.php index 434332b81f..a3ecdecff2 100644 --- a/plugins/CorePluginsAdmin/PluginInstaller.php +++ b/plugins/CorePluginsAdmin/PluginInstaller.php @@ -35,8 +35,8 @@ class PluginInstaller $tmpPluginZip = PIWIK_USER_PATH . self::PATH_TO_DOWNLOAD . $this->pluginName . '.zip'; $tmpPluginFolder = PIWIK_USER_PATH . self::PATH_TO_DOWNLOAD . $this->pluginName; - $tmpPluginZip = SettingsPiwik::rewriteTmpPathWithHostname($tmpPluginZip); - $tmpPluginFolder = SettingsPiwik::rewriteTmpPathWithHostname($tmpPluginFolder); + $tmpPluginZip = SettingsPiwik::rewriteTmpPathWithInstanceId($tmpPluginZip); + $tmpPluginFolder = SettingsPiwik::rewriteTmpPathWithInstanceId($tmpPluginFolder); try { $this->makeSureFoldersAreWritable(); @@ -63,7 +63,7 @@ class PluginInstaller public function installOrUpdatePluginFromFile($pathToZip) { $tmpPluginFolder = PIWIK_USER_PATH . self::PATH_TO_DOWNLOAD . $this->pluginName; - $tmpPluginFolder = SettingsPiwik::rewriteTmpPathWithHostname($tmpPluginFolder); + $tmpPluginFolder = SettingsPiwik::rewriteTmpPathWithInstanceId($tmpPluginFolder); try { $this->makeSureFoldersAreWritable(); diff --git a/plugins/CoreUpdater/Controller.php b/plugins/CoreUpdater/Controller.php index 11c2d160cb..126701f540 100644 --- a/plugins/CoreUpdater/Controller.php +++ b/plugins/CoreUpdater/Controller.php @@ -179,7 +179,7 @@ class Controller extends \Piwik\Plugin\Controller private function oneClick_Download() { $pathPiwikZip = PIWIK_USER_PATH . self::PATH_TO_EXTRACT_LATEST_VERSION . 'latest.zip'; - $this->pathPiwikZip = SettingsPiwik::rewriteTmpPathWithHostname($pathPiwikZip); + $this->pathPiwikZip = SettingsPiwik::rewriteTmpPathWithInstanceId($pathPiwikZip); Filechecks::dieIfDirectoriesNotWritable(array(self::PATH_TO_EXTRACT_LATEST_VERSION)); @@ -192,7 +192,7 @@ class Controller extends \Piwik\Plugin\Controller private function oneClick_Unpack() { $pathExtracted = PIWIK_USER_PATH . self::PATH_TO_EXTRACT_LATEST_VERSION; - $pathExtracted = SettingsPiwik::rewriteTmpPathWithHostname($pathExtracted); + $pathExtracted = SettingsPiwik::rewriteTmpPathWithInstanceId($pathExtracted); $this->pathRootExtractedPiwik = $pathExtracted . 'piwik'; diff --git a/plugins/ImageGraph/StaticGraph.php b/plugins/ImageGraph/StaticGraph.php index 10c20260db..71d08162e2 100644 --- a/plugins/ImageGraph/StaticGraph.php +++ b/plugins/ImageGraph/StaticGraph.php @@ -240,7 +240,7 @@ abstract class StaticGraph protected static function getOutputPath($filename) { $outputFilename = PIWIK_USER_PATH . '/tmp/assets/' . $filename; - $outputFilename = SettingsPiwik::rewriteTmpPathWithHostname($outputFilename); + $outputFilename = SettingsPiwik::rewriteTmpPathWithInstanceId($outputFilename); @chmod($outputFilename, 0600); @unlink($outputFilename); diff --git a/plugins/ScheduledReports/config/tcpdf_config.php b/plugins/ScheduledReports/config/tcpdf_config.php index 9d5317156c..e084760949 100644 --- a/plugins/ScheduledReports/config/tcpdf_config.php +++ b/plugins/ScheduledReports/config/tcpdf_config.php @@ -15,7 +15,7 @@ define('K_PATH_MAIN', PIWIK_INCLUDE_PATH . '/libs/tcpdf/'); $pathTmpTCPDF = PIWIK_USER_PATH . '/tmp/tcpdf/'; -$pathTmpTCPDF = \Piwik\SettingsPiwik::rewriteTmpPathWithHostname($pathTmpTCPDF); +$pathTmpTCPDF = \Piwik\SettingsPiwik::rewriteTmpPathWithInstanceId($pathTmpTCPDF); define('K_PATH_CACHE', $pathTmpTCPDF); define('K_PATH_IMAGES', $pathTmpTCPDF); diff --git a/tests/PHPUnit/Core/DeprecatedMethodsTest.php b/tests/PHPUnit/Core/DeprecatedMethodsTest.php index 148b3489a8..e3c7336e93 100644 --- a/tests/PHPUnit/Core/DeprecatedMethodsTest.php +++ b/tests/PHPUnit/Core/DeprecatedMethodsTest.php @@ -22,6 +22,9 @@ class DeprecatedMethodsTest extends PHPUnit_Framework_TestCase $validTill = '2014-10-01'; $this->assertDeprecatedMethodIsRemoved('\Piwik\Config', 'getConfigSuperUserForBackwardCompatibility', $validTill); + + $validTill = '2014-10-15'; + $this->assertDeprecatedMethodIsRemoved('\Piwik\SettingsPiwik', 'rewriteTmpPathWithHostname', $validTill); } private function assertDeprecatedMethodIsRemoved($className, $method, $removalDate) diff --git a/tests/PHPUnit/Integration/Core/LogTest.php b/tests/PHPUnit/Integration/Core/LogTest.php index a7c76aa078..5fada09e1a 100644 --- a/tests/PHPUnit/Integration/Core/LogTest.php +++ b/tests/PHPUnit/Integration/Core/LogTest.php @@ -270,7 +270,7 @@ dummy backtrace' public static function getLogFileLocation() { $path = self::getDefaultLogFileLocation(); - $path = \Piwik\SettingsPiwik::rewriteTmpPathWithHostname($path); + $path = \Piwik\SettingsPiwik::rewriteTmpPathWithInstanceId($path); return $path; } -- cgit v1.2.3