settingsProvider = $settingsProvider; $this->translator = $translator; } public function validate() { $inTrackerRequest = SettingsServer::isTrackerApiRequest(); $inConsole = Common::isPhpCliMode(); $this->checkConfigFileExists($this->settingsProvider->getPathGlobal()); $this->checkConfigFileExists($this->settingsProvider->getPathLocal(), $startInstaller = !$inTrackerRequest && !$inConsole); } /** * @param $path * @param bool $startInstaller * @throws \Exception */ private function checkConfigFileExists($path, $startInstaller = false) { if (is_readable($path)) { return; } $message = $this->translator->translate('General_ExceptionConfigurationFileNotFound', array($path)); if (Common::isPhpCliMode()) { $message .= "\n" . $this->translator->translate('General_ExceptionConfigurationFileNotFound2', array($path, get_current_user())); } $exception = new \Exception($message); if ($startInstaller) { /** * Triggered when the configuration file cannot be found or read, which usually * means Piwik is not installed yet. * * This event can be used to start the installation process or to display a custom error message. * * @param \Exception $exception The exception that was thrown by `Config::getInstance()`. */ Piwik::postEvent('Config.NoConfigurationFile', array($exception), $pending = true); } else { throw $exception; } } }