diff --git a/core/Tracker.php b/core/Tracker.php index 5ad8e29e36f416857fe8efd90f660b3422399806..99b827ef708f9f57dc367a8b956ef911027f9599 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -212,6 +212,7 @@ class Piwik_Tracker try { if ($this->isVisitValid()) { + self::connectDatabaseIfNotConnected(); $visit = $this->getNewVisitObject(); @@ -226,6 +227,7 @@ class Piwik_Tracker printDebug("The request is invalid: empty request, or maybe tracking is disabled in the config.ini.php via record_statistics=0"); } } catch (Piwik_Tracker_Db_Exception $e) { + $this->outputTransparentGif(); printDebug("<b>" . $e->getMessage() . "</b>"); $this->exitWithException($e, $isAuthenticated); } catch (Piwik_Tracker_Visit_Excluded $e) { @@ -373,19 +375,29 @@ class Piwik_Tracker if ($this->usingBulkTracking) { // when doing bulk tracking we return JSON so the caller will know how many succeeded $result = array('succeeded' => $this->countOfLoggedRequests); - // send error when in debug mode or when authenticated (which happens when doing log importing, - // for example) if ((isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG']) || $authenticated) { $result['error'] = Piwik_Tracker_GetErrorMessage($e); } - echo Piwik_Common::json_encode($result); - exit; + } + if (isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG']) { + Piwik_Common::sendHeader('Content-Type: text/html; charset=utf-8'); + $trailer = '<span style="color: #888888">Backtrace:<br /><pre>' . $e->getTraceAsString() . '</pre></span>'; + $headerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Zeitgeist/templates/simpleLayoutHeader.tpl'); + $footerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Zeitgeist/templates/simpleLayoutFooter.tpl'); + $headerPage = str_replace('{$HTML_TITLE}', 'Piwik › Error', $headerPage); + + echo $headerPage . '<p>' . Piwik_Tracker_GetErrorMessage($e) . '</p>' . $trailer . $footerPage; + } // If not debug, but running authenticated (eg. during log import) then we display raw errors + elseif ($authenticated) { + Piwik_Common::sendHeader('Content-Type: text/html; charset=utf-8'); + echo Piwik_Tracker_GetErrorMessage($e); } else { - Piwik_Tracker_ExitWithException($e, $authenticated); + $this->outputTransparentGif(); } + exit; } /** @@ -431,7 +443,7 @@ class Piwik_Tracker case self::STATE_NOSCRIPT_REQUEST: case self::STATE_NOTHING_TO_NOTICE: default: - $this->outputTransparentGif(); + $this->outputTransparentGif(); printDebug("Nothing to notice => default behaviour"); break; } @@ -749,28 +761,3 @@ function Piwik_Tracker_GetErrorMessage($e) return $e->getMessage(); } } - -/** - * Displays exception in a friendly UI and exits. - * - * @param Exception $e - * @param bool $authenticated - */ -function Piwik_Tracker_ExitWithException($e, $authenticated = false) -{ - Piwik_Common::sendHeader('Content-Type: text/html; charset=utf-8'); - - if (isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG']) { - $trailer = '<span style="color: #888888">Backtrace:<br /><pre>' . $e->getTraceAsString() . '</pre></span>'; - $headerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Zeitgeist/templates/simpleLayoutHeader.tpl'); - $footerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Zeitgeist/templates/simpleLayoutFooter.tpl'); - $headerPage = str_replace('{$HTML_TITLE}', 'Piwik › Error', $headerPage); - - echo $headerPage . '<p>' . Piwik_Tracker_GetErrorMessage($e) . '</p>' . $trailer . $footerPage; - } // If not debug, but running authenticated (eg. during log import) then we display raw errors - elseif ($authenticated) { - echo Piwik_Tracker_GetErrorMessage($e); - } - exit; -} - diff --git a/piwik.php b/piwik.php index 5fca8f90265f2409fed54c4fbb70c1982e2a06f2..efc21743109d6f62c5350ca9d52651f4ca606746 100644 --- a/piwik.php +++ b/piwik.php @@ -7,7 +7,7 @@ * * @package Piwik */ -$GLOBALS['PIWIK_TRACKER_DEBUG'] = !false; +$GLOBALS['PIWIK_TRACKER_DEBUG'] = false; $GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'] = false; define('PIWIK_ENABLE_TRACKING', true);