Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-09-02 10:55:13 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-09-02 10:55:13 +0400
commit097393972e41a5c8a429b6b625cd2bf0b16b178d (patch)
tree4f873fdcd7283d866a7d57db0c50da77a34e7002 /core/Tracker.php
parent7d27436ab7b208549117e4d92746b39498e6eead (diff)
refs #4996 make sure redirect works even if mysql is down or any other error occurs
Diffstat (limited to 'core/Tracker.php')
-rw-r--r--core/Tracker.php60
1 files changed, 42 insertions, 18 deletions
diff --git a/core/Tracker.php b/core/Tracker.php
index ae289d7be5..3b6e5ba178 100644
--- a/core/Tracker.php
+++ b/core/Tracker.php
@@ -172,7 +172,7 @@ class Tracker
$requests = $jsonData['requests'];
}
- return array( $requests, $tokenAuth);
+ return array($requests, $tokenAuth);
}
private function isBulkTrackingRequireTokenAuth()
@@ -185,8 +185,8 @@ class Tracker
list($this->requests, $tokenAuth) = $this->getRequestsArrayFromBulkRequest($rawData);
$bulkTrackingRequireTokenAuth = $this->isBulkTrackingRequireTokenAuth();
- if($bulkTrackingRequireTokenAuth) {
- if(empty($tokenAuth)) {
+ if ($bulkTrackingRequireTokenAuth) {
+ if (empty($tokenAuth)) {
throw new Exception("token_auth must be specified when using Bulk Tracking Import. "
. " See <a href='http://developer.piwik.org/api-reference/tracking-api'>Tracking Doc</a>");
}
@@ -208,8 +208,9 @@ class Tracker
$requestObj = new Request($request, $tokenAuth);
$this->loadTrackerPlugins($requestObj);
- if($bulkTrackingRequireTokenAuth
- && !$requestObj->isAuthenticated()) {
+ if ($bulkTrackingRequireTokenAuth
+ && !$requestObj->isAuthenticated()
+ ) {
throw new Exception(sprintf("token_auth specified does not have Admin permission for idsite=%s", $requestObj->getIdSite()));
}
$request = $requestObj;
@@ -243,7 +244,7 @@ class Tracker
}
$this->runScheduledTasksIfAllowed($isAuthenticated);
$this->commitTransaction();
- } catch(DbException $e) {
+ } catch (DbException $e) {
Common::printDebug($e->getMessage());
$this->rollbackTransaction();
}
@@ -258,11 +259,7 @@ class Tracker
$this->flushOutputBuffer();
- $redirectUrl = Common::getRequestVar('redirecturl', false, 'string');
- if ($redirectUrl) {
- // TODO only redirecti if domain is trusted in config?
- header('Location: ' . $redirectUrl);
- }
+ $this->performRedirectToUrlIfSet();
}
protected function initOutputBuffer()
@@ -283,7 +280,7 @@ class Tracker
protected function beginTransaction()
{
$this->transactionId = null;
- if(!$this->shouldUseTransactions()) {
+ if (!$this->shouldUseTransactions()) {
return;
}
$this->transactionId = self::getDatabase()->beginTransaction();
@@ -291,7 +288,7 @@ class Tracker
protected function commitTransaction()
{
- if(empty($this->transactionId)) {
+ if (empty($this->transactionId)) {
return;
}
self::getDatabase()->commit($this->transactionId);
@@ -299,7 +296,7 @@ class Tracker
protected function rollbackTransaction()
{
- if(empty($this->transactionId)) {
+ if (empty($this->transactionId)) {
return;
}
self::getDatabase()->rollback($this->transactionId);
@@ -319,7 +316,7 @@ class Tracker
*/
protected function isTransactionSupported()
{
- return (bool) Config::getInstance()->Tracker['bulk_requests_use_transaction'];
+ return (bool)Config::getInstance()->Tracker['bulk_requests_use_transaction'];
}
protected function shouldRunScheduledTasks()
@@ -436,13 +433,18 @@ class Tracker
*/
protected function exitWithException($e, $authenticated = false)
{
+ if ($this->hasRedirectUrl()) {
+ $this->performRedirectToUrlIfSet();
+ exit;
+ }
+
Common::sendHeader('HTTP/1.1 500 Internal Server Error');
error_log(sprintf("Error in Piwik (tracker): %s", str_replace("\n", " ", $this->getMessageFromException($e))));
if ($this->usingBulkTracking) {
// when doing bulk tracking we return JSON so the caller will know how many succeeded
$result = array(
- 'status' => 'error',
+ 'status' => 'error',
'tracked' => $this->countOfLoggedRequests
);
// send error when in debug mode or when authenticated (which happens when doing log importing,
@@ -505,7 +507,7 @@ class Tracker
{
if ($this->usingBulkTracking) {
$result = array(
- 'status' => 'success',
+ 'status' => 'success',
'tracked' => $this->countOfLoggedRequests
);
Common::sendHeader('Content-Type: application/json');
@@ -799,7 +801,8 @@ class Tracker
// Tests using window_look_back_for_visitor
if (Common::getRequestVar('forceLargeWindowLookBackForVisitor', false, null, $args) == 1
// also look for this in bulk requests (see fake_logs_replay.log)
- || strpos( json_encode($args, true), '"forceLargeWindowLookBackForVisitor":"1"' ) !== false) {
+ || strpos(json_encode($args, true), '"forceLargeWindowLookBackForVisitor":"1"') !== false
+ ) {
self::updateTrackerConfig('window_look_back_for_visitor', 2678400);
}
@@ -920,4 +923,25 @@ class Tracker
return file_get_contents("php://input");
}
+ private function getRedirectUrl()
+ {
+ // TODO only redirecti if domain is trusted in config?
+ return Common::getRequestVar('redirecturl', false, 'string');
+ }
+
+ private function hasRedirectUrl()
+ {
+ $redirectUrl = $this->getRedirectUrl();
+
+ return !empty($redirectUrl);
+ }
+
+ private function performRedirectToUrlIfSet()
+ {
+ if ($this->hasRedirectUrl()) {
+ $redirectUrl = $this->getRedirectUrl();
+ header('Location: ' . $redirectUrl);
+ }
+ }
+
}