diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2019-09-17 23:35:22 +0300 |
---|---|---|
committer | diosmosis <diosmosis@users.noreply.github.com> | 2019-09-17 23:35:22 +0300 |
commit | 42b4ab13bc36511fabbf376e098e07ffae0d674a (patch) | |
tree | 1deef1ec16dca25b3a41cd200d5a481f7803e157 | |
parent | 583d8d1c28cf0b96810a81dfb7c76a3c1140d764 (diff) |
Fix user path was not working as it should (allow placing config file outside webroot) (#14866)
* Fix user path was not working as it should
* fix error
-rw-r--r-- | config/global.php | 2 | ||||
-rw-r--r-- | core/Config.php | 2 | ||||
-rw-r--r-- | core/Container/ContainerFactory.php | 2 | ||||
-rw-r--r-- | core/Filechecks.php | 6 | ||||
-rw-r--r-- | js/tracker.php | 14 | ||||
-rw-r--r-- | misc/cron/updatetoken.php | 10 | ||||
-rw-r--r-- | plugins/CoreUpdater/Updater.php | 5 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/AssetManager/UIAssetMinifierTest.php | 2 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/AssetManagerTest.php | 4 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/HttpTest.php | 4 |
10 files changed, 27 insertions, 24 deletions
diff --git a/config/global.php b/config/global.php index 187e6aae78..17d7b9e012 100644 --- a/config/global.php +++ b/config/global.php @@ -8,7 +8,7 @@ use Piwik\Config; return array( - 'path.root' => PIWIK_USER_PATH, + 'path.root' => PIWIK_DOCUMENT_ROOT, 'path.misc.user' => 'misc/user/', diff --git a/core/Config.php b/core/Config.php index 916b43b6dd..5d4467a9fa 100644 --- a/core/Config.php +++ b/core/Config.php @@ -108,7 +108,7 @@ class Config */ public static function getGlobalConfigPath() { - return PIWIK_USER_PATH . self::DEFAULT_GLOBAL_CONFIG_PATH; + return PIWIK_DOCUMENT_ROOT . self::DEFAULT_GLOBAL_CONFIG_PATH; } /** diff --git a/core/Container/ContainerFactory.php b/core/Container/ContainerFactory.php index 07b416becb..1ae6f6a2df 100644 --- a/core/Container/ContainerFactory.php +++ b/core/Container/ContainerFactory.php @@ -72,7 +72,7 @@ class ContainerFactory $builder->addDefinitions(new IniConfigDefinitionSource($this->settings)); // Global config - $builder->addDefinitions(PIWIK_USER_PATH . '/config/global.php'); + $builder->addDefinitions(PIWIK_DOCUMENT_ROOT . '/config/global.php'); // Plugin configs $this->addPluginConfigs($builder); diff --git a/core/Filechecks.php b/core/Filechecks.php index da1990d31d..1447315bb1 100644 --- a/core/Filechecks.php +++ b/core/Filechecks.php @@ -23,7 +23,7 @@ class Filechecks if (!is_writable(PIWIK_INCLUDE_PATH . '/') || !is_writable(PIWIK_DOCUMENT_ROOT . '/index.php') || !is_writable(PIWIK_INCLUDE_PATH . '/core') || - !is_writable(PIWIK_USER_PATH . '/config/global.ini.php') + !is_writable(PIWIK_DOCUMENT_ROOT . '/config/global.ini.php') ) { return false; } @@ -40,7 +40,9 @@ class Filechecks { $resultCheck = array(); foreach ($directoriesToCheck as $directoryToCheck) { - if (!preg_match('/^' . preg_quote(PIWIK_USER_PATH, '/') . '/', $directoryToCheck)) { + if (!preg_match('/^' . preg_quote(PIWIK_USER_PATH, '/') . '/', $directoryToCheck) + && !preg_match('/^' . preg_quote(PIWIK_DOCUMENT_ROOT, '/') . '/', $directoryToCheck) + && !preg_match('/^' . preg_quote(PIWIK_INCLUDE_PATH, '/') . '/', $directoryToCheck)) { $directoryToCheck = PIWIK_USER_PATH . $directoryToCheck; } diff --git a/js/tracker.php b/js/tracker.php index 1cf637e188..ce9793b9cc 100644 --- a/js/tracker.php +++ b/js/tracker.php @@ -22,9 +22,19 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' * * @see core/Piwik.php */ -define('PIWIK_INCLUDE_PATH', '..'); define('PIWIK_DOCUMENT_ROOT', '..'); -define('PIWIK_USER_PATH', '..'); + +if (file_exists(PIWIK_DOCUMENT_ROOT . '/bootstrap.php')) { + require_once PIWIK_DOCUMENT_ROOT . '/bootstrap.php'; +} + +if (!defined('PIWIK_INCLUDE_PATH')) { + define('PIWIK_INCLUDE_PATH', PIWIK_DOCUMENT_ROOT); +} + +if (!defined('PIWIK_USER_PATH')) { + define('PIWIK_USER_PATH', PIWIK_DOCUMENT_ROOT); +} require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php'; diff --git a/misc/cron/updatetoken.php b/misc/cron/updatetoken.php index d55921badd..b10a21d347 100644 --- a/misc/cron/updatetoken.php +++ b/misc/cron/updatetoken.php @@ -15,19 +15,15 @@ use Piwik\Application\Environment; use Piwik\Tests\Framework\TestingEnvironmentManipulator; use Piwik\Tests\Framework\TestingEnvironmentVariables; -if (!defined('PIWIK_INCLUDE_PATH')) { - define('PIWIK_INCLUDE_PATH', realpath(dirname(__FILE__) . "/../..")); -} - -if (!defined('PIWIK_USER_PATH')) { - define('PIWIK_USER_PATH', PIWIK_INCLUDE_PATH); +if (!defined('PIWIK_DOCUMENT_ROOT')) { + define('PIWIK_DOCUMENT_ROOT', realpath(dirname(__FILE__) . "/../..")); } define('PIWIK_ENABLE_DISPATCH', false); define('PIWIK_ENABLE_ERROR_HANDLER', false); define('PIWIK_ENABLE_SESSION_START', false); -require_once PIWIK_INCLUDE_PATH . "/index.php"; +require_once PIWIK_DOCUMENT_ROOT . "/index.php"; if (!Common::isPhpCliMode()) { return; diff --git a/plugins/CoreUpdater/Updater.php b/plugins/CoreUpdater/Updater.php index 951230a412..7baee1d46a 100644 --- a/plugins/CoreUpdater/Updater.php +++ b/plugins/CoreUpdater/Updater.php @@ -298,11 +298,6 @@ class Updater $model->removeGoneFiles($extractedArchiveDirectory, PIWIK_DOCUMENT_ROOT); } - // Config files may be user (account) specific - if (PIWIK_INCLUDE_PATH !== PIWIK_USER_PATH) { - Filesystem::copyRecursive($extractedArchiveDirectory . '/config', PIWIK_USER_PATH . '/config'); - } - Filesystem::unlinkRecursive($extractedArchiveDirectory, true); Filesystem::clearPhpCaches(); diff --git a/tests/PHPUnit/Integration/AssetManager/UIAssetMinifierTest.php b/tests/PHPUnit/Integration/AssetManager/UIAssetMinifierTest.php index 9fde0b351b..c45c92876a 100644 --- a/tests/PHPUnit/Integration/AssetManager/UIAssetMinifierTest.php +++ b/tests/PHPUnit/Integration/AssetManager/UIAssetMinifierTest.php @@ -45,7 +45,7 @@ class UIAssetMinifierTest extends \PHPUnit_Framework_TestCase */ public function test_isMinifiedJs($scriptFileName, $isMinified) { - $scriptFile = new OnDiskUIAsset(PIWIK_USER_PATH, $scriptFileName); + $scriptFile = new OnDiskUIAsset(PIWIK_DOCUMENT_ROOT, $scriptFileName); $this->assertEquals( $isMinified, diff --git a/tests/PHPUnit/Integration/AssetManagerTest.php b/tests/PHPUnit/Integration/AssetManagerTest.php index d6bfcc067a..82654af55a 100644 --- a/tests/PHPUnit/Integration/AssetManagerTest.php +++ b/tests/PHPUnit/Integration/AssetManagerTest.php @@ -336,7 +336,7 @@ class AssetManagerTest extends IntegrationTestCase */ private function getExpectedMergedJs($filename) { - $expectedMergeResult = new OnDiskUIAsset(PIWIK_USER_PATH, self::ASSET_MANAGER_TEST_DIR .'scripts/' . $filename); + $expectedMergeResult = new OnDiskUIAsset(PIWIK_DOCUMENT_ROOT, self::ASSET_MANAGER_TEST_DIR .'scripts/' . $filename); $expectedContent = $expectedMergeResult->getContent(); @@ -357,7 +357,7 @@ class AssetManagerTest extends IntegrationTestCase */ private function getExpectedMergedStylesheet() { - $expectedMergeResult = new OnDiskUIAsset(PIWIK_USER_PATH, self::ASSET_MANAGER_TEST_DIR .'stylesheets/ExpectedMergeResult.css'); + $expectedMergeResult = new OnDiskUIAsset(PIWIK_DOCUMENT_ROOT, self::ASSET_MANAGER_TEST_DIR .'stylesheets/ExpectedMergeResult.css'); $expectedContent = $expectedMergeResult->getContent(); diff --git a/tests/PHPUnit/Integration/HttpTest.php b/tests/PHPUnit/Integration/HttpTest.php index f179276443..ef2585ad5d 100644 --- a/tests/PHPUnit/Integration/HttpTest.php +++ b/tests/PHPUnit/Integration/HttpTest.php @@ -42,7 +42,7 @@ class HttpTest extends \PHPUnit_Framework_TestCase public function testFetchApiLatestVersion() { - $destinationPath = PIWIK_USER_PATH . '/tmp/latest/LATEST'; + $destinationPath = PIWIK_DOCUMENT_ROOT . '/tmp/latest/LATEST'; Http::fetchRemoteFile(Fixture::getRootUrl(), $destinationPath, 3); $this->assertFileExists($destinationPath); $this->assertGreaterThan(0, filesize($destinationPath)); @@ -50,7 +50,7 @@ class HttpTest extends \PHPUnit_Framework_TestCase public function testFetchLatestZip() { - $destinationPath = PIWIK_USER_PATH . '/tmp/latest/latest.zip'; + $destinationPath = PIWIK_DOCUMENT_ROOT . '/tmp/latest/latest.zip'; Http::fetchRemoteFile(Fixture::getRootUrl() . 'tests/PHPUnit/Integration/Http/fixture.zip', $destinationPath, 3, 30); $this->assertFileExists($destinationPath); $this->assertGreaterThan(0, filesize($destinationPath)); |