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
path: root/core
diff options
context:
space:
mode:
authorFabian Becker <fabian.becker@uni-tuebingen.de>2013-09-08 23:43:52 +0400
committerFabian Becker <fabian.becker@uni-tuebingen.de>2013-09-08 23:43:52 +0400
commitf985d168e35b38f4c84d09d72430a2f46d1c1b00 (patch)
tree7befa70d81261f22ebd946ede4473d01cd0bef9f /core
parent1a6b565e726bb7db58ea306c7015f56250f75e7f (diff)
Properly catch exception on failed authentication for bulk import
Set correct header for application/json refs #4141
Diffstat (limited to 'core')
-rw-r--r--core/Tracker.php16
1 files changed, 10 insertions, 6 deletions
diff --git a/core/Tracker.php b/core/Tracker.php
index 96d05f5078..82997c2c97 100644
--- a/core/Tracker.php
+++ b/core/Tracker.php
@@ -181,7 +181,7 @@ class Tracker
}
$tokenAuth = Common::getRequestVar('token_auth', false, null, $jsonData);
if (empty($tokenAuth)) {
- throw new Exception(" token_auth must be specified when using Bulk Tracking Import. See <a href='http://piwik.org/docs/tracking-api/reference/'>Tracking Doc</a>");
+ throw new Exception("token_auth must be specified when using Bulk Tracking Import. See <a href='http://piwik.org/docs/tracking-api/reference/'>Tracking Doc</a>");
}
if (!empty($this->requests)) {
$idSitesForAuthentication = array();
@@ -207,7 +207,7 @@ class Tracker
foreach($idSitesForAuthentication as $idSiteForAuthentication) {
// a Bulk Tracking request that is not authenticated should fail
if (!Request::authenticateSuperUserOrAdmin($tokenAuth, $idSiteForAuthentication)) {
- throw new Exception(" token_auth specified is not valid for site " . intval($idSiteForAuthentication));
+ throw new Exception("token_auth specified is not valid for site " . intval($idSiteForAuthentication));
}
}
}
@@ -221,7 +221,11 @@ class Tracker
*/
public function main($args = null)
{
- $tokenAuth = $this->initRequests($args);
+ try {
+ $tokenAuth = $this->initRequests($args);
+ } catch (Exception $ex) {
+ $this->exitWithException($ex, true);
+ }
if (!empty($this->requests)) {
foreach ($this->requests as $params) {
@@ -389,9 +393,11 @@ class Tracker
if ((isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG']) || $authenticated) {
$result['error'] = $this->getMessageFromException($e);
}
+ $this->sendHeader('Content-Type: application/json');
echo Common::json_encode($result);
exit;
}
+
if (isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG']) {
Common::sendHeader('Content-Type: text/html; charset=utf-8');
$trailer = '<span style="color: #888888">Backtrace:<br /><pre>' . $e->getTraceAsString() . '</pre></span>';
@@ -607,9 +613,7 @@ class Tracker
{
// Adding &dp=1 will disable the provider plugin, if token_auth is used (used to speed up bulk imports)
$disableProvider = $request->getParam('dp');
- if (!empty($disableProvider)
- && $request->isAuthenticated()
- ) {
+ if (!empty($disableProvider) && $request->isAuthenticated()) {
Tracker::setPluginsNotToLoad(array('Provider'));
}