From 74ca348e3d4f0c63dace7ff667c6f96e22dac306 Mon Sep 17 00:00:00 2001
From: sgiehl <stefan@piwik.org>
Date: Tue, 16 Jun 2015 23:39:25 +0200
Subject: [PATCH] refs #8085 - fix segment for language rows

---
 plugins/UserLanguage/API.php                  |  7 +++++-
 .../test___UserLanguage.getLanguage_day.xml   | 22 +++++++++----------
 ...woVisits__UserLanguage.getLanguage_day.xml |  2 +-
 3 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/plugins/UserLanguage/API.php b/plugins/UserLanguage/API.php
index eaaa1c1304..c9e3c83b13 100644
--- a/plugins/UserLanguage/API.php
+++ b/plugins/UserLanguage/API.php
@@ -38,8 +38,13 @@ class API extends \Piwik\Plugin\API
     public function getLanguage($idSite, $period, $date, $segment = false)
     {
         $dataTable = $this->getDataTable(Archiver::LANGUAGE_RECORD_NAME, $idSite, $period, $date, $segment);
-        $dataTable->filter('AddSegmentValue');
         $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\groupByLangCallback'));
+        $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'segment', function($label) {
+            if (empty($label) || $label == 'xx') {
+                return 'languageCode==xx';
+            }
+            return sprintf('languageCode==%1$s,languageCode=@%1$s-', $label);
+        }));
         $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\languageTranslate'));
 
         return $dataTable;
diff --git a/plugins/UserLanguage/tests/System/expected/test___UserLanguage.getLanguage_day.xml b/plugins/UserLanguage/tests/System/expected/test___UserLanguage.getLanguage_day.xml
index b5cd869274..ed492ed690 100644
--- a/plugins/UserLanguage/tests/System/expected/test___UserLanguage.getLanguage_day.xml
+++ b/plugins/UserLanguage/tests/System/expected/test___UserLanguage.getLanguage_day.xml
@@ -10,7 +10,7 @@
 		<sum_visit_length>0</sum_visit_length>
 		<bounce_count>4</bounce_count>
 		<nb_visits_converted>0</nb_visits_converted>
-		<segment>languageCode==fr-be</segment>
+		<segment>languageCode==fr,languageCode=@fr-</segment>
 	</row>
 	<row>
 		<label>Polish</label>
@@ -22,7 +22,7 @@
 		<sum_visit_length>0</sum_visit_length>
 		<bounce_count>3</bounce_count>
 		<nb_visits_converted>0</nb_visits_converted>
-		<segment>languageCode==pl</segment>
+		<segment>languageCode==pl,languageCode=@pl-</segment>
 	</row>
 	<row>
 		<label>English</label>
@@ -34,7 +34,7 @@
 		<sum_visit_length>0</sum_visit_length>
 		<bounce_count>2</bounce_count>
 		<nb_visits_converted>0</nb_visits_converted>
-		<segment>languageCode==en</segment>
+		<segment>languageCode==en,languageCode=@en-</segment>
 	</row>
 	<row>
 		<label>Arabic</label>
@@ -46,7 +46,7 @@
 		<sum_visit_length>0</sum_visit_length>
 		<bounce_count>1</bounce_count>
 		<nb_visits_converted>0</nb_visits_converted>
-		<segment>languageCode==ar-qa</segment>
+		<segment>languageCode==ar,languageCode=@ar-</segment>
 	</row>
 	<row>
 		<label>Basque</label>
@@ -58,7 +58,7 @@
 		<sum_visit_length>0</sum_visit_length>
 		<bounce_count>1</bounce_count>
 		<nb_visits_converted>0</nb_visits_converted>
-		<segment>languageCode==eu-es</segment>
+		<segment>languageCode==eu,languageCode=@eu-</segment>
 	</row>
 	<row>
 		<label>Chinese</label>
@@ -70,7 +70,7 @@
 		<sum_visit_length>0</sum_visit_length>
 		<bounce_count>1</bounce_count>
 		<nb_visits_converted>0</nb_visits_converted>
-		<segment>languageCode==zh-sg</segment>
+		<segment>languageCode==zh,languageCode=@zh-</segment>
 	</row>
 	<row>
 		<label>Czech</label>
@@ -82,7 +82,7 @@
 		<sum_visit_length>0</sum_visit_length>
 		<bounce_count>1</bounce_count>
 		<nb_visits_converted>0</nb_visits_converted>
-		<segment>languageCode==cs-cz</segment>
+		<segment>languageCode==cs,languageCode=@cs-</segment>
 	</row>
 	<row>
 		<label>German</label>
@@ -94,7 +94,7 @@
 		<sum_visit_length>0</sum_visit_length>
 		<bounce_count>1</bounce_count>
 		<nb_visits_converted>0</nb_visits_converted>
-		<segment>languageCode==de</segment>
+		<segment>languageCode==de,languageCode=@de-</segment>
 	</row>
 	<row>
 		<label>Greek</label>
@@ -106,7 +106,7 @@
 		<sum_visit_length>0</sum_visit_length>
 		<bounce_count>1</bounce_count>
 		<nb_visits_converted>0</nb_visits_converted>
-		<segment>languageCode==el-gr</segment>
+		<segment>languageCode==el,languageCode=@el-</segment>
 	</row>
 	<row>
 		<label>Serbian</label>
@@ -118,7 +118,7 @@
 		<sum_visit_length>0</sum_visit_length>
 		<bounce_count>1</bounce_count>
 		<nb_visits_converted>0</nb_visits_converted>
-		<segment>languageCode==sr-rs</segment>
+		<segment>languageCode==sr,languageCode=@sr-</segment>
 	</row>
 	<row>
 		<label>Thai</label>
@@ -130,7 +130,7 @@
 		<sum_visit_length>0</sum_visit_length>
 		<bounce_count>1</bounce_count>
 		<nb_visits_converted>0</nb_visits_converted>
-		<segment>languageCode==th</segment>
+		<segment>languageCode==th,languageCode=@th-</segment>
 	</row>
 	<row>
 		<label>Unknown</label>
diff --git a/tests/PHPUnit/System/expected/test_OneVisitorTwoVisits__UserLanguage.getLanguage_day.xml b/tests/PHPUnit/System/expected/test_OneVisitorTwoVisits__UserLanguage.getLanguage_day.xml
index ce3a3e16fa..bab68538ab 100644
--- a/tests/PHPUnit/System/expected/test_OneVisitorTwoVisits__UserLanguage.getLanguage_day.xml
+++ b/tests/PHPUnit/System/expected/test_OneVisitorTwoVisits__UserLanguage.getLanguage_day.xml
@@ -9,6 +9,6 @@
 		<sum_visit_length>1621</sum_visit_length>
 		<bounce_count>1</bounce_count>
 		<nb_visits_converted>2</nb_visits_converted>
-		<segment>languageCode==fr</segment>
+		<segment>languageCode==fr,languageCode=@fr-</segment>
 	</row>
 </result>
\ No newline at end of file
-- 
GitLab