diff options
author | mattab <matthieu.aubry@gmail.com> | 2014-10-09 08:01:19 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2014-10-09 08:01:19 +0400 |
commit | 740a7f1f99548cdbed7b7bdec15a972929ebd04c (patch) | |
tree | 01f40d73a9ce7657cd416fad7d94e96edf8cefba /core | |
parent | bb0d2938ece15a0480417ad8e1384f31060671f6 (diff) |
Deprecate setForceIp and setForceDateTime, moved to Request object
Diffstat (limited to 'core')
-rw-r--r-- | core/Tracker.php | 57 | ||||
-rw-r--r-- | core/Tracker/Request.php | 34 |
2 files changed, 17 insertions, 74 deletions
diff --git a/core/Tracker.php b/core/Tracker.php index 72bd3cd289..bd72e04920 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -44,9 +44,6 @@ class Tracker const LENGTH_HEX_ID_STRING = 16; const LENGTH_BINARY_ID = 8; - protected static $forcedDateTime = null; - protected static $forcedIpString = null; - protected static $pluginsNotToLoad = array(); protected static $pluginsToLoad = array(); @@ -90,21 +87,9 @@ class Tracker public function clear() { - self::$forcedIpString = null; - self::$forcedDateTime = null; $this->stateValid = self::STATE_NOTHING_TO_NOTICE; } - public static function setForceIp($ipString) - { - self::$forcedIpString = $ipString; - } - - public static function setForceDateTime($dateTime) - { - self::$forcedDateTime = $dateTime; - } - /** * Do not load the specified plugins (used during testing, to disable Provider plugin) * @param array $plugins @@ -488,15 +473,13 @@ class Tracker /** * Initialization + * @param Request $request */ protected function init(Request $request) { $this->loadTrackerPlugins($request); - $this->handleTrackingApi($request); $this->handleDisabledTracker(); $this->handleEmptyRequest($request); - - Common::printDebug("Current datetime: " . date("Y-m-d H:i:s", $request->getCurrentTimestamp())); } /** @@ -748,29 +731,6 @@ class Tracker return Common::getRequestVar('token_auth', false); } - /** - * This method allows to set custom IP + server time + visitor ID, when using Tracking API. - * These two attributes can be only set by the Super User (passing token_auth). - */ - protected function handleTrackingApi(Request $request) - { - if (!$request->isAuthenticated()) { - return; - } - - // Custom IP to use for this visitor - $customIp = $request->getParam('cip'); - if (!empty($customIp)) { - $this->setForceIp($customIp); - } - - // Custom server date time to use - $customDatetime = $request->getParam('cdt'); - if (!empty($customDatetime)) { - $this->setForceDateTime($customDatetime); - } - } - public static function setTestEnvironment($args = null, $requestMethod = null) { if (is_null($args)) { @@ -816,18 +776,6 @@ class Tracker \Piwik\Plugins\PrivacyManager\IPAnonymizer::activate(); } - // Custom IP to use for this visitor - $customIp = Common::getRequestVar('cip', false, null, $args); - if (!empty($customIp)) { - self::setForceIp($customIp); - } - - // Custom server date time to use - $customDatetime = Common::getRequestVar('cdt', false, null, $args); - if (!empty($customDatetime)) { - self::setForceDateTime($customDatetime); - } - $pluginsDisabled = array('Provider'); // Disable provider plugin, because it is so slow to do many reverse ip lookups @@ -870,8 +818,7 @@ class Tracker try { if ($this->isVisitValid()) { - $request->setForceDateTime(self::$forcedDateTime); - $request->setForceIp(self::$forcedIpString); + Common::printDebug("Current datetime: " . date("Y-m-d H:i:s", $request->getCurrentTimestamp())); $visit = $this->getNewVisitObject(); $visit->setRequest($request); diff --git a/core/Tracker/Request.php b/core/Tracker/Request.php index 212abbd0d2..e78aae6b61 100644 --- a/core/Tracker/Request.php +++ b/core/Tracker/Request.php @@ -322,6 +322,15 @@ class Request return $this->timestamp; } + public function getCustomTimestamp() + { + $cdt = $this->getParam('cdt'); + if (!is_numeric($cdt)) { + $cdt = strtotime($cdt); + } + return $cdt; + } + protected function isTimestampValid($time) { return $time <= $this->getCurrentTimestamp() @@ -521,8 +530,12 @@ class Request public function getIp() { - if (!empty($this->enforcedIp)) { - $ipString = $this->enforcedIp; + $cip = $this->getParam('cip'); + if(!empty($cip)) { + if (!$this->isAuthenticated()) { + throw new Exception("You must specify token_auth parameter to use the 'cip' parameter."); + } + $ipString = $cip; } else { $ipString = IP::getIpFromHeader(); } @@ -531,23 +544,6 @@ class Request return $ip; } - public function setForceIp($ip) - { - if (!empty($ip)) { - $this->enforcedIp = $ip; - } - } - - public function setForceDateTime($dateTime) - { - if (!is_numeric($dateTime)) { - $dateTime = strtotime($dateTime); - } - if (!empty($dateTime)) { - $this->timestamp = $dateTime; - } - } - public function getForcedUserId() { $userId = $this->getParam('uid'); |