diff --git a/core/Application/Kernel/EnvironmentValidator.php b/core/Application/Kernel/EnvironmentValidator.php index 862593a108d..5efed4b666e 100644 --- a/core/Application/Kernel/EnvironmentValidator.php +++ b/core/Application/Kernel/EnvironmentValidator.php @@ -77,7 +77,7 @@ private function checkConfigFileExists($path, $startInstaller = false) $message = $this->getSpecificMessageWhetherFileExistsOrNot($path); - $exception = new \Exception($message); + $exception = new NotYetInstalledException($message); if ($startInstaller) { $this->startInstallation($exception); diff --git a/plugins/Installation/Installation.php b/plugins/Installation/Installation.php index aa4ff1c6dfa..a1d29643437 100644 --- a/plugins/Installation/Installation.php +++ b/plugins/Installation/Installation.php @@ -107,8 +107,13 @@ public function dispatch($exception = null) $action = Common::getRequestVar('action', 'welcome', 'string'); - if ($this->isAllowedAction($action)) { + if ($this->isAllowedAction($action) && (!defined('PIWIK_ENABLE_DISPATCH') || PIWIK_ENABLE_DISPATCH)) { echo FrontController::getInstance()->dispatch('Installation', $action, array($message)); + } elseif (defined('PIWIK_ENABLE_DISPATCH') && !PIWIK_ENABLE_DISPATCH) { + if ($exception && $exception instanceof \Exception) { + throw $exception; + } + return; } else { Piwik::exitWithErrorMessage($this->getMessageToInviteUserToInstallPiwik($message)); } diff --git a/plugins/Installation/tests/System/APITest.php b/plugins/Installation/tests/System/APITest.php index d8ae5523c8a..887e5e17ba9 100644 --- a/plugins/Installation/tests/System/APITest.php +++ b/plugins/Installation/tests/System/APITest.php @@ -61,6 +61,13 @@ public function test_shouldReturnValidApiResponse_IfWrongDbInfo_formatJSON() $this->assertContains('Access denied', $data); } + public function test_shouldReturnEmptyResultWhenNotInstalledAndDispatchIsDisabled() + { + $url = Fixture::getTestRootUrl() . 'nodispatchnotinstalled.php'; + $response = $this->sendHttpRequest($url); + $this->assertSame('', $response['data']); + } + private function getUrl() { return Fixture::getRootUrl() . 'tests/PHPUnit/proxy/index.php?module=API&method=API.getPiwikVersion'; diff --git a/tests/PHPUnit/proxy/nodispatchnotinstalled.php b/tests/PHPUnit/proxy/nodispatchnotinstalled.php new file mode 100644 index 00000000000..f4fabeecf1b --- /dev/null +++ b/tests/PHPUnit/proxy/nodispatchnotinstalled.php @@ -0,0 +1,20 @@ +configFileLocal = PIWIK_INCLUDE_PATH . "tmp/test.config.ini.php"; +$testEnvironment->save(); + +Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator($testEnvironment)); + +include PIWIK_INCLUDE_PATH . '/index.php'; \ No newline at end of file