diff options
Diffstat (limited to 'core/Tracker.php')
-rw-r--r-- | core/Tracker.php | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/core/Tracker.php b/core/Tracker.php index 9ff3dec758..d9e8a04278 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -165,7 +165,7 @@ class Tracker $requests = $jsonData['requests']; } - return array( $requests, $tokenAuth); + return array($requests, $tokenAuth); } private function isBulkTrackingRequireTokenAuth() @@ -178,8 +178,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>"); } @@ -201,8 +201,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; @@ -239,7 +240,7 @@ class Tracker } $this->runScheduledTasksIfAllowed($isAuthenticated); $this->commitTransaction(); - } catch(DbException $e) { + } catch (DbException $e) { Common::printDebug($e->getMessage()); $this->rollbackTransaction(); } @@ -253,6 +254,8 @@ class Tracker $this->end(); $this->flushOutputBuffer(); + + $this->performRedirectToUrlIfSet(); } protected function initOutputBuffer() @@ -273,7 +276,7 @@ class Tracker protected function beginTransaction() { $this->transactionId = null; - if(!$this->shouldUseTransactions()) { + if (!$this->shouldUseTransactions()) { return; } $this->transactionId = self::getDatabase()->beginTransaction(); @@ -281,7 +284,7 @@ class Tracker protected function commitTransaction() { - if(empty($this->transactionId)) { + if (empty($this->transactionId)) { return; } self::getDatabase()->commit($this->transactionId); @@ -289,7 +292,7 @@ class Tracker protected function rollbackTransaction() { - if(empty($this->transactionId)) { + if (empty($this->transactionId)) { return; } self::getDatabase()->rollback($this->transactionId); @@ -309,7 +312,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() @@ -426,13 +429,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, @@ -495,7 +503,7 @@ class Tracker { if ($this->usingBulkTracking) { $result = array( - 'status' => 'success', + 'status' => 'success', 'tracked' => $this->countOfLoggedRequests ); Common::sendHeader('Content-Type: application/json'); @@ -786,7 +794,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); } @@ -901,4 +910,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); + } + } + } |