From b7bfa2b6367371fe0675d1c0d1fd673e6f8294c7 Mon Sep 17 00:00:00 2001 From: Benaka Moorthi Date: Tue, 24 Sep 2013 02:41:47 -0400 Subject: Refs #4041, fix bug where columns query parameter was not correctly overriding default value of columns_to_display display property. --- core/ViewDataTable.php | 7 +++++++ core/ViewDataTable/Properties.php | 10 +--------- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'core') diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php index a74a6c360f..b7c37d9206 100644 --- a/core/ViewDataTable.php +++ b/core/ViewDataTable.php @@ -1276,6 +1276,13 @@ class ViewDataTable $this->getPropertyFromQueryParam($name, $default); } } + + // handle special 'columns' query parameter + $columns = Common::getRequestVar('columns', false); + if ($columns !== false) { + $this->columns_to_display = Piwik::getArrayFromApiParameter($columns); + array_unshift($this->columns_to_display, 'label'); + } } private function getPropertyFromQueryParam($name, $defaultValue) diff --git a/core/ViewDataTable/Properties.php b/core/ViewDataTable/Properties.php index 310c09f3d6..bcb8286c1a 100644 --- a/core/ViewDataTable/Properties.php +++ b/core/ViewDataTable/Properties.php @@ -693,7 +693,7 @@ class Properties */ public static function getDefaultPropertyValues() { - $result = array( + return array( 'footer_icons' => false, 'show_visualization_only' => false, 'datatable_js_type' => 'DataTable', @@ -749,14 +749,6 @@ class Properties 'columns_to_display' => array(), 'y_axis_unit' => false ); - - $columns = Common::getRequestVar('columns', false); - if ($columns !== false) { - $result['columns_to_display'] = Piwik::getArrayFromApiParameter($columns); - array_unshift($result['columns_to_display'], 'label'); - } - - return $result; } private static function getFlippedClassConstantMap($klass) -- cgit v1.2.3 From a0d277eda478650082d27406a60cc927beddeb34 Mon Sep 17 00:00:00 2001 From: mattab Date: Wed, 25 Sep 2013 13:14:24 +1200 Subject: Removing resolution from param list since it's not used https://github.com/piwik/piwik/pull/109 --- core/Tracker/Visit.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'core') diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php index 74ab001bae..f051658bba 100644 --- a/core/Tracker/Visit.php +++ b/core/Tracker/Visit.php @@ -921,7 +921,6 @@ class Visit implements Tracker\VisitInterface $os, $browserName, $browserVersion, - $resolution, $plugin_Flash, $plugin_Java, $plugin_Director, @@ -1036,7 +1035,7 @@ class Visit implements Tracker\VisitInterface * @param $browserLang * @return string */ - protected function getConfigHash($os, $browserName, $browserVersion, $resolution, $plugin_Flash, $plugin_Java, $plugin_Director, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF, $plugin_WindowsMedia, $plugin_Gears, $plugin_Silverlight, $plugin_Cookie, $ip, $browserLang) + protected function getConfigHash($os, $browserName, $browserVersion, $plugin_Flash, $plugin_Java, $plugin_Director, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF, $plugin_WindowsMedia, $plugin_Gears, $plugin_Silverlight, $plugin_Cookie, $ip, $browserLang) { $hash = md5($os . $browserName . $browserVersion . $plugin_Flash . $plugin_Java . $plugin_Director . $plugin_Quicktime . $plugin_RealPlayer . $plugin_PDF . $plugin_WindowsMedia . $plugin_Gears . $plugin_Silverlight . $plugin_Cookie . $ip . $browserLang, $raw_output = true); return Common::substr($hash, 0, Tracker::LENGTH_BINARY_ID); -- cgit v1.2.3 From 085d752a47ad9535cdf7252bd9507830406782e9 Mon Sep 17 00:00:00 2001 From: Benaka Moorthi Date: Tue, 24 Sep 2013 22:58:57 -0400 Subject: Move UserCountry specific logic out of core tracker files and into UserCountry plugin and remove some uses of Zend_Registry in tests. --- core/Tracker/Cache.php | 3 +- core/Tracker/Request.php | 21 +++++++------ core/Tracker/Visit.php | 78 ++---------------------------------------------- 3 files changed, 13 insertions(+), 89 deletions(-) (limited to 'core') diff --git a/core/Tracker/Cache.php b/core/Tracker/Cache.php index 7319818e41..2acf983c78 100644 --- a/core/Tracker/Cache.php +++ b/core/Tracker/Cache.php @@ -15,7 +15,6 @@ use Piwik\Config; use Piwik\Piwik; use Piwik\CacheFile; use Piwik\Tracker; -use Piwik\Plugins\UserCountry\LocationProvider; /** * Simple cache mechanism used in Tracker to avoid requesting settings from mysql on every request @@ -104,8 +103,8 @@ class Cache $cacheContent = array( 'isBrowserTriggerEnabled' => Rules::isBrowserTriggerEnabled(), 'lastTrackerCronRun' => Piwik_GetOption('lastTrackerCronRun'), - 'currentLocationProviderId' => LocationProvider::getCurrentProviderId(), ); + Piwik_PostEvent('Tracker.setTrackerCacheGeneral', array(&$cacheContent)); self::setCacheGeneral($cacheContent); return $cacheContent; } diff --git a/core/Tracker/Request.php b/core/Tracker/Request.php index 0687090245..e81838b233 100644 --- a/core/Tracker/Request.php +++ b/core/Tracker/Request.php @@ -8,7 +8,6 @@ use Piwik\Cookie; use Piwik\IP; use Piwik\Tracker; use Piwik\Tracker\Cache; -use Piwik\Plugins\UserCountry\LocationProvider; /** * Piwik - Open source web analytics @@ -483,29 +482,29 @@ class Request return $this->forcedVisitorId; } - public function enrichLocation($location) + public function overrideLocation(&$visitorInfo) { if (!$this->isAuthenticated()) { - return $location; + return; } // check for location override query parameters (ie, lat, long, country, region, city) static $locationOverrideParams = array( - 'country' => array('string', LocationProvider::COUNTRY_CODE_KEY), - 'region' => array('string', LocationProvider::REGION_CODE_KEY), - 'city' => array('string', LocationProvider::CITY_NAME_KEY), - 'lat' => array('float', LocationProvider::LATITUDE_KEY), - 'long' => array('float', LocationProvider::LONGITUDE_KEY), + 'country' => array('string', 'location_country'), + 'region' => array('string', 'location_region'), + 'city' => array('string', 'location_city'), + 'lat' => array('float', 'location_latitude'), + 'long' => array('float', 'location_longitude'), ); foreach ($locationOverrideParams as $queryParamName => $info) { - list($type, $locationResultKey) = $info; + list($type, $visitorInfoKey) = $info; $value = Common::getRequestVar($queryParamName, false, $type, $this->params); if (!empty($value)) { - $location[$locationResultKey] = $value; + $visitorInfo[$visitorInfoKey] = $value; } } - return $location; + return; } public function getPlugins() diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php index f051658bba..3f3d7588ec 100644 --- a/core/Tracker/Visit.php +++ b/core/Tracker/Visit.php @@ -39,7 +39,6 @@ use Piwik\Tracker\Request; use Piwik\Tracker\Referrer; use Exception; use Piwik\Tracker\VisitExcluded; -use Piwik\Plugins\UserCountry\LocationProvider; use UserAgentParser; /** @@ -477,10 +476,6 @@ class Visit implements Tracker\VisitInterface 'location_browser_lang' => $userInfo['location_browser_lang'], ); - // add optional location components - $location = $this->getVisitorLocation($userInfo['location_browser_lang']); - $this->updateVisitInfoWithLocation($location); - // Add Custom variable key,value to the visitor array $this->visitorInfo = array_merge($this->visitorInfo, $this->visitorCustomVariables); @@ -489,6 +484,8 @@ class Visit implements Tracker\VisitInterface ); Piwik_PostEvent('Tracker.newVisitorInformation', array(&$this->visitorInfo, $extraInfo)); + $this->request->overrideLocation($this->visitorInfo); + $debugVisitInfo = $this->visitorInfo; $debugVisitInfo['idvisitor'] = bin2hex($debugVisitInfo['idvisitor']); $debugVisitInfo['config_id'] = bin2hex($debugVisitInfo['config_id']); @@ -510,77 +507,6 @@ class Visit implements Tracker\VisitInterface return $t; } - /** - * Returns the location of the visitor, based on the visitor's IP and browser language. - * - * @param string $browserLang - * @return array See LocationProvider::getLocation for more info. - */ - private function getVisitorLocation($browserLang) - { - $location = array(); - $userInfo = array('lang' => $browserLang, 'ip' => IP::N2P($this->getVisitorIp())); - Piwik_PostEvent('Tracker.getVisitorLocation', array(&$location, $userInfo)); - - $location = $this->request->enrichLocation($location); - - if (empty($location['country_code'])) // sanity check - { - $location['country_code'] = self::UNKNOWN_CODE; - } - - return $location; - } - - /** - * Sets visitor info array with location info. - * - * @param array $location See LocationProvider::getLocation for more info. - */ - private function updateVisitInfoWithLocation($location) - { - static $logVisitToLowerLocationMapping = array( - 'location_country' => LocationProvider::COUNTRY_CODE_KEY, - ); - - static $logVisitToLocationMapping = array( - 'location_region' => LocationProvider::REGION_CODE_KEY, - 'location_city' => LocationProvider::CITY_NAME_KEY, - 'location_latitude' => LocationProvider::LATITUDE_KEY, - 'location_longitude' => LocationProvider::LONGITUDE_KEY, - ); - - foreach ($logVisitToLowerLocationMapping as $column => $locationKey) { - if (!empty($location[$locationKey])) { - $this->visitorInfo[$column] = strtolower($location[$locationKey]); - } - } - - foreach ($logVisitToLocationMapping as $column => $locationKey) { - if (!empty($location[$locationKey])) { - $this->visitorInfo[$column] = $location[$locationKey]; - } - } - - // if the location has provider/organization info, set it - if (!empty($location[LocationProvider::ISP_KEY])) { - $providerValue = $location[LocationProvider::ISP_KEY]; - - // if the org is set and not the same as the isp, add it to the provider value - if (!empty($location[LocationProvider::ORG_KEY]) - && $location[LocationProvider::ORG_KEY] != $providerValue - ) { - $providerValue .= ' - ' . $location[LocationProvider::ORG_KEY]; - } - } else if (!empty($location[LocationProvider::ORG_KEY])) { - $providerValue = $location[LocationProvider::ORG_KEY]; - } - - if (isset($providerValue)) { - $this->visitorInfo['location_provider'] = $providerValue; - } - } - /** * Save new visitor information to log_visit table. * Provides pre- and post- event hooks (Tracker.saveVisitorInformation and Tracker.saveVisitorInformation.end) for plugins -- cgit v1.2.3 From e1a7acafa59eec66b9458d2b3f665f48c41f051b Mon Sep 17 00:00:00 2001 From: mattab Date: Wed, 25 Sep 2013 17:49:39 +1200 Subject: Thanks for the report. Could you apply this patch and confirm it is working for you? Fixes #4156 Adding ORDER BY clause when DELETING so that it works with replication https://dev.mysql.com/doc/refman/5.1/en/replication-features-limit.html (cherry picked from commit ce6254e) --- core/Db.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/Db.php b/core/Db.php index ef2f756f9d..a8369943ba 100644 --- a/core/Db.php +++ b/core/Db.php @@ -156,11 +156,15 @@ class Db * @param string $where The where clause of the query. Must include the WHERE keyword. * @param int $maxRowsPerQuery The maximum number of rows to delete per DELETE query. * @param array $parameters Parameters to bind in the query. + * @param string $primaryKey Name of primary key to sort by. * @return int The total number of rows deleted. */ - static public function deleteAllRows($table, $where, $maxRowsPerQuery = 100000, $parameters = array()) + static public function deleteAllRows($table, $where, $orderBy, $maxRowsPerQuery = 100000, $parameters = array()) { - $sql = "DELETE FROM $table $where LIMIT " . (int)$maxRowsPerQuery; + $sql = "DELETE FROM $table + $where + ORDER BY $orderBy ASC + LIMIT " . (int)$maxRowsPerQuery; // delete rows w/ a limit $totalRowsDeleted = 0; -- cgit v1.2.3 From bd41f1ae0122cd0ae6eb44633e5cd835c000ef18 Mon Sep 17 00:00:00 2001 From: Benaka Moorthi Date: Wed, 25 Sep 2013 06:57:22 -0400 Subject: Remove use of Zend_Auth_Result. --- core/Access.php | 2 +- core/Auth.php | 72 +++++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 58 insertions(+), 16 deletions(-) (limited to 'core') diff --git a/core/Access.php b/core/Access.php index 303e5d638d..6e13db6579 100644 --- a/core/Access.php +++ b/core/Access.php @@ -162,7 +162,7 @@ class Access // access = array ( idsite => accessIdSite, idsite2 => accessIdSite2) $result = $this->auth->authenticate(); - if (!$result->isValid()) { + if (!$result->wasAuthenticationSuccessful()) { return false; } $this->login = $result->getIdentity(); diff --git a/core/Auth.php b/core/Auth.php index 67edbbabaf..30401d0e04 100644 --- a/core/Auth.php +++ b/core/Auth.php @@ -39,35 +39,57 @@ interface Auth * * @package Piwik * @subpackage Piwik_Auth - * @see Zend_AuthResult, libs/Zend/Auth/Result.php - * @link http://framework.zend.com/manual/en/zend.auth.html */ -class AuthResult extends \Zend_Auth_Result +class AuthResult { + const FAILURE = 0; + const SUCCESS = 1; + const SUCCESS_SUPERUSER_AUTH_CODE = 42; + /** * token_auth parameter used to authenticate in the API * * @var string */ - protected $_token_auth = null; + protected $tokenAuth = null; - const SUCCESS_SUPERUSER_AUTH_CODE = 42; + /** + * The login used to authenticate. + * + * @var string + */ + protected $login = null; + + /** + * The authentication result code. Can be self::FAILURE, self::SUCCESS, or + * self::SUCCESS_SUPERUSER_AUTH_CODE. + * + * @var int + */ + protected $code = null; /** * Constructor for AuthResult * * @param int $code * @param string $login identity - * @param string $token_auth - * @param array $messages + * @param string $tokenAuth + */ + public function __construct($code, $login, $tokenAuth) + { + $this->code = (int)$code; + $this->login = $login; + $this->tokenAuth = $tokenAuth; + } + + /** + * Returns the login used to authenticate. + * + * @return string */ - public function __construct($code, $login, $token_auth, array $messages = array()) + public function getIdentity() { - // AuthResult::SUCCESS_SUPERUSER_AUTH_CODE, AuthResult::SUCCESS, AuthResult::FAILURE - $this->_code = (int)$code; - $this->_identity = $login; - $this->_messages = $messages; - $this->_token_auth = $token_auth; + return $this->login; } /** @@ -77,6 +99,26 @@ class AuthResult extends \Zend_Auth_Result */ public function getTokenAuth() { - return $this->_token_auth; + return $this->tokenAuth; } -} + + /** + * Returns the authentication result code. + * + * @return int + */ + public function getCode() + { + return $this->code; + } + + /** + * Returns true if this result was successfully authentication. + * + * @return bool + */ + public function wasAuthenticationSuccessful() + { + return $this->code > self::FAILURE; + } +} \ No newline at end of file -- cgit v1.2.3