diff --git a/core/FrontController.php b/core/FrontController.php index 77e1f737147..de341ec9711 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -260,6 +260,7 @@ public function init() try { Db::createDatabaseObject(); + Piwik_GetOption('TestingIfDatabaseConnectionWorked'); } catch (Exception $e) { if (self::shouldRethrowException()) { throw $e; diff --git a/core/SettingsPiwik.php b/core/SettingsPiwik.php index 51e7c006a85..d615aad7a87 100644 --- a/core/SettingsPiwik.php +++ b/core/SettingsPiwik.php @@ -175,7 +175,11 @@ public static function isUniqueVisitorsEnabled($periodLabel) */ public static function rewriteTmpPathWithHostname($path) { - $configByHost = Config::getInstance()->getConfigHostnameIfSet(); + try { + $configByHost = Config::getInstance()->getConfigHostnameIfSet(); + } catch(Exception $e) { + // Config file not found + } if(empty($configByHost)) { return $path; } diff --git a/core/Url.php b/core/Url.php index f2cb601d459..ea8e07766e1 100644 --- a/core/Url.php +++ b/core/Url.php @@ -267,6 +267,16 @@ static public function getHost($checkIfTrusted = true) return false; } + /** + * Sets the host. Useful for CLI scripts, eg. archive.php + * + * @param $host string + */ + static public function setHost($host) + { + $_SERVER['HTTP_HOST'] = $host; + } + /** * If current URL is "http://example.org/dir1/dir2/index.php?param1=value1¶m2=value2" * will return "example.org" diff --git a/index.php b/index.php index 0ffa6ea99c0..0369da7a7fa 100644 --- a/index.php +++ b/index.php @@ -40,14 +40,16 @@ require_once PIWIK_INCLUDE_PATH . '/core/Loader.php'; require_once PIWIK_INCLUDE_PATH . '/core/functions.php'; +define('PIWIK_PRINT_ERROR_BACKTRACE', false); + if (!defined('PIWIK_ENABLE_ERROR_HANDLER') || PIWIK_ENABLE_ERROR_HANDLER) { require_once PIWIK_INCLUDE_PATH . '/core/Error.php'; Error::setErrorHandler(); - require_once PIWIK_INCLUDE_PATH . '/core/ExceptionHandler.php'; ExceptionHandler::setUp(); } + if (!defined('PIWIK_ENABLE_DISPATCH') || PIWIK_ENABLE_DISPATCH) { $controller = FrontController::getInstance(); $controller->init(); diff --git a/misc/cron/archive.php b/misc/cron/archive.php index e7160ece36e..cd1747280ea 100644 --- a/misc/cron/archive.php +++ b/misc/cron/archive.php @@ -117,12 +117,12 @@ class CronArchive public function init() { + $this->initPiwikHost(); $this->initCore(); $this->initTokenAuth(); $this->initCheckCli(); $this->initLog(); $this->displayHelp(); - $this->initPiwikHost(); $this->initStateFromParameters(); Piwik::setUserIsSuperUser(true); @@ -675,6 +675,7 @@ private function initCore() FrontController::getInstance()->init(); } catch (Exception $e) { echo "ERROR: During Piwik init, Message: " . $e->getMessage(); + //echo $e->getTraceAsString(); exit; } } @@ -831,6 +832,11 @@ private function initPiwikHost() $piwikUrl .= '/'; } } + + // HOST is required for the Config object + $parsed = parse_url($piwikUrl); + Url::setHost($parsed['host']); + if (Config::getInstance()->General['force_ssl'] == 1) { $piwikUrl = str_replace('http://', 'https://', $piwikUrl); } diff --git a/misc/others/test_generateLotsVisitsWebsites.php b/misc/others/test_generateLotsVisitsWebsites.php index b9309f50b17..f2a4ba94b09 100644 --- a/misc/others/test_generateLotsVisitsWebsites.php +++ b/misc/others/test_generateLotsVisitsWebsites.php @@ -31,7 +31,6 @@ function init() $config = Config::getInstance(); $config->log['log_only_when_debug_parameter'] = 0; $config->log['logger_message'] = array("logger_message" => "screen"); - \Piwik\Log::make(); } function run() diff --git a/piwik.php b/piwik.php index 2df92969dfb..a2ea3fe39a1 100644 --- a/piwik.php +++ b/piwik.php @@ -77,7 +77,6 @@ Common::printDebug("Debug enabled - Input parameters:
" . var_export($_GET, true)); \Piwik\Tracker\Db::enableProfiling(); \Piwik\FrontController::createConfigObject(); - \Piwik\Log::make(); } if (!defined('PIWIK_ENABLE_TRACKING') || PIWIK_ENABLE_TRACKING) { diff --git a/plugins/CoreVisualizations/Visualizations/JqplotGraph/Evolution.php b/plugins/CoreVisualizations/Visualizations/JqplotGraph/Evolution.php index c57677e3b4a..7e8237a6a34 100644 --- a/plugins/CoreVisualizations/Visualizations/JqplotGraph/Evolution.php +++ b/plugins/CoreVisualizations/Visualizations/JqplotGraph/Evolution.php @@ -91,9 +91,9 @@ private function calculateEvolutionDateRange(&$view) $defaultLastN = self::getDefaultLastN($period); $originalDate = Common::getRequestVar('date', 'last' . $defaultLastN, 'string'); - if ($period == 'range') { // show evolution limit if the period is not a range - $view->show_limit_control = false; - } else { + if ($period != 'range') { // show evolution limit if the period is not a range + $view->show_limit_control = true; + // set the evolution_{$period}_last_n query param if (Range::parseDateRange($originalDate)) { // if a multiple period // overwrite last_n param using the date range