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:
authorMatthieu Aubry <matt@piwik.org>2014-11-07 09:14:16 +0300
committerMatthieu Aubry <matt@piwik.org>2014-11-07 09:14:16 +0300
commit4ab8054b8bdd3f8a1f831b0d1a25ec8c6c754563 (patch)
tree81500cac0ddeec857cbf44c02c507ef0efbba453
parent34d0b74bb147290b7f09e09ddb0551d1bb80c517 (diff)
parent72163b22570fff1f275e992f0740e8c13ecb323d (diff)
Merge pull request #6610 from piwik/64352.9.0-b7
Fix wrong database values when float representation is not set to English standard
-rw-r--r--core/ArchiveProcessor.php3
-rw-r--r--core/Common.php21
-rw-r--r--core/Config.php4
-rwxr-xr-xcore/DataTable/Filter/CalculateEvolutionFilter.php3
-rw-r--r--core/Tracker/Action.php12
-rw-r--r--core/Tracker/Db.php1
-rw-r--r--core/Tracker/GoalManager.php15
-rw-r--r--core/Tracker/Visit.php4
-rw-r--r--libs/PiwikTracker/PiwikTracker.php34
-rw-r--r--libs/upgradephp/upgrade.php2
-rw-r--r--plugins/Goals/API.php8
-rw-r--r--plugins/Goals/Columns/BaseConversion.php5
-rw-r--r--plugins/SitesManager/API.php2
-rw-r--r--plugins/UserCountry/Columns/Latitude.php5
-rw-r--r--plugins/UserCountry/Columns/Longitude.php5
-rw-r--r--tests/PHPUnit/System/AutoSuggestAPITest.php4
16 files changed, 113 insertions, 15 deletions
diff --git a/core/ArchiveProcessor.php b/core/ArchiveProcessor.php
index 71e90cde23..c93e913e0c 100644
--- a/core/ArchiveProcessor.php
+++ b/core/ArchiveProcessor.php
@@ -260,6 +260,7 @@ class ArchiveProcessor
$metrics = $this->getAggregatedNumericMetrics($columns, $operationToApply);
foreach($metrics as $column => $value) {
+ $value = Common::forceDotAsSeparatorForDecimalPoint($value);
$this->archiveWriter->insertRecord($column, $value);
}
// if asked for only one field to sum
@@ -314,6 +315,8 @@ class ArchiveProcessor
public function insertNumericRecord($name, $value)
{
$value = round($value, 2);
+ $value = Common::forceDotAsSeparatorForDecimalPoint($value);
+
$this->archiveWriter->insertRecord($name, $value);
}
diff --git a/core/Common.php b/core/Common.php
index 76c9777605..6dfa2d22fa 100644
--- a/core/Common.php
+++ b/core/Common.php
@@ -474,7 +474,10 @@ class Common
} elseif ($varType === 'integer') {
if ($value == (string)(int)$value) $ok = true;
} elseif ($varType === 'float') {
- if ($value == (string)(float)$value) $ok = true;
+ $valueToCompare = (string)(float)$value;
+ $valueToCompare = Common::forceDotAsSeparatorForDecimalPoint($valueToCompare);
+
+ if ($value == $valueToCompare) $ok = true;
} elseif ($varType === 'array') {
if (is_array($value)) $ok = true;
} else {
@@ -1078,6 +1081,22 @@ class Common
}
/**
+ * Force the separator for decimal point to be a dot. See https://github.com/piwik/piwik/issues/6435
+ * If for instance a German locale is used it would be a comma otherwise.
+ *
+ * @param float|string $value
+ * @return string
+ */
+ public static function forceDotAsSeparatorForDecimalPoint($value)
+ {
+ if (null === $value || false === $value) {
+ return $value;
+ }
+
+ return str_replace(',', '.', $value);
+ }
+
+ /**
* Sets outgoing header.
*
* @param string $header The header.
diff --git a/core/Config.php b/core/Config.php
index 95f4e62e6c..db2e1e5d6a 100644
--- a/core/Config.php
+++ b/core/Config.php
@@ -382,6 +382,10 @@ class Config extends Singleton
$value = $this->encodeValues($value);
}
} else {
+ if (is_float($values)) {
+ $values = Common::forceDotAsSeparatorForDecimalPoint($values);
+ }
+
$values = htmlentities($values, ENT_COMPAT, 'UTF-8');
$values = str_replace('$', '&#36;', $values);
}
diff --git a/core/DataTable/Filter/CalculateEvolutionFilter.php b/core/DataTable/Filter/CalculateEvolutionFilter.php
index 0ef6a30a2f..5fa55b329e 100755
--- a/core/DataTable/Filter/CalculateEvolutionFilter.php
+++ b/core/DataTable/Filter/CalculateEvolutionFilter.php
@@ -8,6 +8,7 @@
*/
namespace Piwik\DataTable\Filter;
+use Piwik\Common;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Site;
@@ -122,6 +123,8 @@ class CalculateEvolutionFilter extends ColumnCallbackAddColumnPercentage
$value = self::getPercentageValue($value, $divisor, $this->quotientPrecision);
$value = self::appendPercentSign($value);
+ $value = Common::forceDotAsSeparatorForDecimalPoint($value);
+
return $value;
}
diff --git a/core/Tracker/Action.php b/core/Tracker/Action.php
index 23372538ac..b892866781 100644
--- a/core/Tracker/Action.php
+++ b/core/Tracker/Action.php
@@ -290,6 +290,11 @@ abstract class Action
$value = $dimension->onLookupAction($this->request, $this);
if (false !== $value) {
+
+ if (is_float($value)) {
+ $value = Common::forceDotAsSeparatorForDecimalPoint($value);
+ }
+
$field = $dimension->getColumnName();
if (empty($field)) {
@@ -342,6 +347,11 @@ abstract class Action
$value = $dimension->onNewAction($this->request, $visitor, $this);
if ($value !== false) {
+
+ if (is_float($value)) {
+ $value = Common::forceDotAsSeparatorForDecimalPoint($value);
+ }
+
$visitAction[$dimension->getColumnName()] = $value;
}
}
@@ -357,7 +367,7 @@ abstract class Action
$customValue = $this->getCustomFloatValue();
if (!empty($customValue)) {
- $visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = $customValue;
+ $visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = Common::forceDotAsSeparatorForDecimalPoint($customValue);
}
$customVariables = $this->getCustomVariables();
diff --git a/core/Tracker/Db.php b/core/Tracker/Db.php
index 1fe081daac..0c419d8f6e 100644
--- a/core/Tracker/Db.php
+++ b/core/Tracker/Db.php
@@ -102,6 +102,7 @@ abstract class Db
foreach ($this->queriesProfiling as $query => $info) {
$time = $info['sum_time_ms'];
+ $time = Common::forceDotAsSeparatorForDecimalPoint($time);
$count = $info['count'];
$queryProfiling = "INSERT INTO " . Common::prefixTable('log_profiling') . "
diff --git a/core/Tracker/GoalManager.php b/core/Tracker/GoalManager.php
index 9f989df935..0d4bd2bfcb 100644
--- a/core/Tracker/GoalManager.php
+++ b/core/Tracker/GoalManager.php
@@ -273,11 +273,13 @@ class GoalManager
*/
protected function getRevenue($revenue)
{
- if (round($revenue) == $revenue) {
- return $revenue;
+ if (round($revenue) != $revenue) {
+ $revenue = round($revenue, self::REVENUE_PRECISION);
}
- return round($revenue, self::REVENUE_PRECISION);
+ $revenue = Common::forceDotAsSeparatorForDecimalPoint($revenue);
+
+ return $revenue;
}
/**
@@ -633,7 +635,7 @@ class GoalManager
'idaction_category3' => (int)$item[self::INTERNAL_ITEM_CATEGORY3],
'idaction_category4' => (int)$item[self::INTERNAL_ITEM_CATEGORY4],
'idaction_category5' => (int)$item[self::INTERNAL_ITEM_CATEGORY5],
- 'price' => $item[self::INTERNAL_ITEM_PRICE],
+ 'price' => Common::forceDotAsSeparatorForDecimalPoint($item[self::INTERNAL_ITEM_PRICE]),
'quantity' => $item[self::INTERNAL_ITEM_QUANTITY],
'deleted' => isset($item['deleted']) ? $item['deleted'] : 0, //deleted
'idorder' => isset($goal['idorder']) ? $goal['idorder'] : self::ITEM_IDORDER_ABANDONED_CART, //idorder = 0 in log_conversion_item for carts
@@ -815,6 +817,11 @@ class GoalManager
$value = $dimension->$hook($this->request, $visitor, $action, $this);
if (false !== $value) {
+
+ if (is_float($value)) {
+ $value = Common::forceDotAsSeparatorForDecimalPoint($value);
+ }
+
$fieldName = $dimension->getColumnName();
$visitor->setVisitorColumn($fieldName, $value);
diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php
index 8bdf641ece..9dee4196b7 100644
--- a/core/Tracker/Visit.php
+++ b/core/Tracker/Visit.php
@@ -532,6 +532,10 @@ class Visit implements VisitInterface
$fieldName = $dimension->getColumnName();
$visitor->setVisitorColumn($fieldName, $value);
+ if (is_float($value)) {
+ $value = Common::forceDotAsSeparatorForDecimalPoint($value);
+ }
+
if ($valuesToUpdate !== null) {
$valuesToUpdate[$fieldName] = $value;
} else {
diff --git a/libs/PiwikTracker/PiwikTracker.php b/libs/PiwikTracker/PiwikTracker.php
index 051cb74745..39eb82b6bd 100644
--- a/libs/PiwikTracker/PiwikTracker.php
+++ b/libs/PiwikTracker/PiwikTracker.php
@@ -646,6 +646,9 @@ class PiwikTracker
if (empty($sku)) {
throw new Exception("You must specify a SKU for the Ecommerce item");
}
+
+ $price = $this->forceDotAsSeparatorForDecimalPoint($price);
+
$this->ecommerceItems[$sku] = array($sku, $name, $category, $price, $quantity);
}
@@ -747,7 +750,9 @@ class PiwikTracker
$this->pageCustomVar[self::CVAR_INDEX_ECOMMERCE_ITEM_CATEGORY] = array('_pkc', $category);
if (!empty($price)) {
- $this->pageCustomVar[self::CVAR_INDEX_ECOMMERCE_ITEM_PRICE] = array('_pkp', (float)$price);
+ $price = (float) $price;
+ $price = $this->forceDotAsSeparatorForDecimalPoint($price);
+ $this->pageCustomVar[self::CVAR_INDEX_ECOMMERCE_ITEM_PRICE] = array('_pkp', $price);
}
// On a category page, do not record "Product name not defined"
@@ -764,6 +769,22 @@ class PiwikTracker
}
/**
+ * Force the separator for decimal point to be a dot. See https://github.com/piwik/piwik/issues/6435
+ * If for instance a German locale is used it would be a comma otherwise.
+ *
+ * @param float|string $value
+ * @return string
+ */
+ private function forceDotAsSeparatorForDecimalPoint($value)
+ {
+ if (null === $value || false === $value) {
+ return $value;
+ }
+
+ return str_replace(',', '.', $value);
+ }
+
+ /**
* Returns URL used to track Ecommerce Cart updates
* Calling this function will reinitializes the property ecommerceItems to empty array
* so items will have to be added again via addEcommerceItem()
@@ -807,18 +828,23 @@ class PiwikTracker
$url = $this->getRequest($this->idSite);
$url .= '&idgoal=0';
if (!empty($grandTotal)) {
+ $grandTotal = $this->forceDotAsSeparatorForDecimalPoint($grandTotal);
$url .= '&revenue=' . $grandTotal;
}
if (!empty($subTotal)) {
+ $subTotal = $this->forceDotAsSeparatorForDecimalPoint($subTotal);
$url .= '&ec_st=' . $subTotal;
}
if (!empty($tax)) {
+ $tax = $this->forceDotAsSeparatorForDecimalPoint($tax);
$url .= '&ec_tx=' . $tax;
}
if (!empty($shipping)) {
+ $shipping = $this->forceDotAsSeparatorForDecimalPoint($shipping);
$url .= '&ec_sh=' . $shipping;
}
if (!empty($discount)) {
+ $discount = $this->forceDotAsSeparatorForDecimalPoint($discount);
$url .= '&ec_dt=' . $discount;
}
if (!empty($this->ecommerceItems)) {
@@ -876,7 +902,8 @@ class PiwikTracker
$url .= '&e_n=' . urlencode($name);
}
if(strlen($value) > 0) {
- $url .= '&e_v=' . $value;
+ $value = $this->forceDotAsSeparatorForDecimalPoint($value);
+ $url .= '&e_v=' . $value;
}
return $url;
}
@@ -982,7 +1009,8 @@ class PiwikTracker
$url = $this->getRequest($this->idSite);
$url .= '&idgoal=' . $idGoal;
if (!empty($revenue)) {
- $url .= '&revenue=' . $revenue;
+ $revenue = $this->forceDotAsSeparatorForDecimalPoint($revenue);
+ $url .= '&revenue=' . $revenue;
}
return $url;
}
diff --git a/libs/upgradephp/upgrade.php b/libs/upgradephp/upgrade.php
index 498e877280..322ffd0455 100644
--- a/libs/upgradephp/upgrade.php
+++ b/libs/upgradephp/upgrade.php
@@ -349,7 +349,7 @@ function _safe_serialize( $value )
}
if(is_float($value))
{
- return 'd:'.$value.';';
+ return 'd:'.str_replace(',', '.', $value).';';
}
if(is_string($value))
{
diff --git a/plugins/Goals/API.php b/plugins/Goals/API.php
index c76054aab9..735b647866 100644
--- a/plugins/Goals/API.php
+++ b/plugins/Goals/API.php
@@ -98,6 +98,8 @@ class API extends \Piwik\Plugin\API
$name = $this->checkName($name);
$pattern = $this->checkPattern($pattern);
+ $revenue = Common::forceDotAsSeparatorForDecimalPoint((float)$revenue);
+
$goal = array(
'name' => $name,
'match_attribute' => $matchAttribute,
@@ -105,7 +107,7 @@ class API extends \Piwik\Plugin\API
'pattern_type' => $patternType,
'case_sensitive' => (int)$caseSensitive,
'allow_multiple' => (int)$allowMultipleConversionsPerVisit,
- 'revenue' => (float)$revenue,
+ 'revenue' => $revenue,
'deleted' => 0,
);
@@ -144,6 +146,8 @@ class API extends \Piwik\Plugin\API
$pattern = $this->checkPattern($pattern);
$this->checkPatternIsValid($patternType, $pattern, $matchAttribute);
+ $revenue = Common::forceDotAsSeparatorForDecimalPoint((float)$revenue);
+
$this->getModel()->updateGoal($idSite, $idGoal, array(
'name' => $name,
'match_attribute' => $matchAttribute,
@@ -151,7 +155,7 @@ class API extends \Piwik\Plugin\API
'pattern_type' => $patternType,
'case_sensitive' => (int) $caseSensitive,
'allow_multiple' => (int) $allowMultipleConversionsPerVisit,
- 'revenue' => (float) $revenue,
+ 'revenue' => $revenue,
));
Cache::regenerateCacheWebsiteAttributes($idSite);
diff --git a/plugins/Goals/Columns/BaseConversion.php b/plugins/Goals/Columns/BaseConversion.php
index d2c3e24dd7..7d9bf6bc9d 100644
--- a/plugins/Goals/Columns/BaseConversion.php
+++ b/plugins/Goals/Columns/BaseConversion.php
@@ -8,6 +8,7 @@
*/
namespace Piwik\Plugins\Goals\Columns;
+use Piwik\Common;
use Piwik\Plugin\Dimension\ConversionDimension;
use Piwik\Tracker\GoalManager;
@@ -29,6 +30,8 @@ abstract class BaseConversion extends ConversionDimension
return $revenue;
}
- return round($revenue, GoalManager::REVENUE_PRECISION);
+ $value = round($revenue, GoalManager::REVENUE_PRECISION);
+
+ return $value;
}
} \ No newline at end of file
diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php
index 02f50a1ece..24bb750f12 100644
--- a/plugins/SitesManager/API.php
+++ b/plugins/SitesManager/API.php
@@ -1244,6 +1244,8 @@ class API extends \Piwik\Plugin\API
$return = array();
foreach ($GmtOffsets as $offset) {
+ $offset = Common::forceDotAsSeparatorForDecimalPoint($offset);
+
if ($offset > 0) {
$offset = '+' . $offset;
} elseif ($offset == 0) {
diff --git a/plugins/UserCountry/Columns/Latitude.php b/plugins/UserCountry/Columns/Latitude.php
index cce2b910e2..0e27285f9d 100644
--- a/plugins/UserCountry/Columns/Latitude.php
+++ b/plugins/UserCountry/Columns/Latitude.php
@@ -8,6 +8,7 @@
*/
namespace Piwik\Plugins\UserCountry\Columns;
+use Piwik\Common;
use Piwik\Piwik;
use Piwik\Plugins\UserCountry\LocationProvider;
use Piwik\Plugins\UserCountry\Segment;
@@ -50,7 +51,9 @@ class Latitude extends Base
$userInfo = $this->getUserInfo($request, $visitor);
- return $this->getLocationDetail($userInfo, LocationProvider::LATITUDE_KEY);
+ $latitude = $this->getLocationDetail($userInfo, LocationProvider::LATITUDE_KEY);
+
+ return $latitude;
}
/**
diff --git a/plugins/UserCountry/Columns/Longitude.php b/plugins/UserCountry/Columns/Longitude.php
index ec63431f6f..f185506add 100644
--- a/plugins/UserCountry/Columns/Longitude.php
+++ b/plugins/UserCountry/Columns/Longitude.php
@@ -8,6 +8,7 @@
*/
namespace Piwik\Plugins\UserCountry\Columns;
+use Piwik\Common;
use Piwik\Piwik;
use Piwik\Plugins\UserCountry\LocationProvider;
use Piwik\Plugins\UserCountry\Segment;
@@ -50,7 +51,9 @@ class Longitude extends Base
$userInfo = $this->getUserInfo($request, $visitor);
- return $this->getLocationDetail($userInfo, LocationProvider::LONGITUDE_KEY);
+ $longitude = $this->getLocationDetail($userInfo, LocationProvider::LONGITUDE_KEY);
+
+ return $longitude;
}
/**
diff --git a/tests/PHPUnit/System/AutoSuggestAPITest.php b/tests/PHPUnit/System/AutoSuggestAPITest.php
index d7d23f58c5..77026a3cf1 100644
--- a/tests/PHPUnit/System/AutoSuggestAPITest.php
+++ b/tests/PHPUnit/System/AutoSuggestAPITest.php
@@ -8,6 +8,7 @@
namespace Piwik\Tests\System;
use Piwik\API\Request;
+use Piwik\Common;
use Piwik\Date;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Tests\Fixtures\ManyVisitsWithGeoIP;
@@ -97,6 +98,9 @@ class AutoSuggestAPITest extends SystemTestCase
$topSegmentValue = @$response[0];
if ($topSegmentValue !== false && !is_null($topSegmentValue)) {
+ if (is_numeric($topSegmentValue) || is_float($topSegmentValue) || preg_match('/^\d*?,\d*$/', $topSegmentValue)) {
+ $topSegmentValue = Common::forceDotAsSeparatorForDecimalPoint($topSegmentValue);
+ }
// Now build the segment request
$segmentValue = rawurlencode(html_entity_decode($topSegmentValue));
$params['segment'] = $params['segmentToComplete'] . '==' . $segmentValue;