[MediaWiki-commits] [Gerrit] wikimedia...crm[deployment]: Only store the full country code if it is on our valid list.

2016-09-21 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Only store the full country code if it is on our valid list.
..


Only store the full country code if it is on our valid list.

If the country code is not on the list then prefer the 2 digit code. This means 
'en' is better than 'en_NO
(Norwegian English). Separately we will look to remove the invalid options we 
already have in our DB.

If neither are valid store the full thing to make it easier to find them

Bug: T96410
Change-Id: Ie7e8a958c2496a738ce738dd827b7ed04b2d9fbd
---
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
1 file changed, 30 insertions(+), 1 deletion(-)

Approvals:
  Eileen: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module 
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index 376d3e8..654f568 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -1089,7 +1089,19 @@
 }
 }
 if (!empty($contact['preferred_language'])) {
-wmf_civicrm_ensure_language_exists($contact['preferred_language']);
+if 
(!wmf_civicrm_check_language_exists($contact['preferred_language'])) {
+  $parts = explode('_', $contact['preferred_language']);
+  if (wmf_civicrm_check_language_exists($parts[0])) {
+// in other words en_NO will be converted to en
+// rather than Norwegian English.
+$contact['preferred_language'] = $parts[0];
+  }
+  else {
+// otherwise let's create it rather than fail.
+// seems like the easiest way not to lose visibility, data or the 
plot.
+wmf_civicrm_ensure_language_exists($contact['preferred_language']);
+  }
+}
 }
 
 // Copy some fields, if they exist
@@ -1258,6 +1270,23 @@
 }
 
 /**
+ * Check if the language string exists.
+ *
+ * @param string $languageAbbreviation
+ *
+ * @return bool
+ */
+function wmf_civicrm_check_language_exists($languageAbbreviation) {
+  static $languages;
+  if (empty($languages)) {
+$available_options = civicrm_api3('Contact', 'getoptions', array(
+  'field' => 'preferred_language',
+));
+$languages = $available_options['values'];
+  }
+  return !empty($languages[$languageAbbreviation]);
+}
+/**
  * Ensure the required option value exists.
  *
  * @param string $option_value

-- 
To view, visit https://gerrit.wikimedia.org/r/312156
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie7e8a958c2496a738ce738dd827b7ed04b2d9fbd
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: deployment
Gerrit-Owner: Eileen 
Gerrit-Reviewer: Eileen 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] wikimedia...crm[deployment]: Only store the full country code if it is on our valid list.

2016-09-21 Thread Eileen (Code Review)
Eileen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312156

Change subject: Only store the full country code if it is on our valid list.
..

Only store the full country code if it is on our valid list.

If the country code is not on the list then prefer the 2 digit code. This means 
'en' is better than 'en_NO
(Norwegian English). Separately we will look to remove the invalid options we 
already have in our DB.

If neither are valid store the full thing to make it easier to find them

Bug: T96410
Change-Id: Ie7e8a958c2496a738ce738dd827b7ed04b2d9fbd
---
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
1 file changed, 30 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/56/312156/1

diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module 
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index 376d3e8..654f568 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -1089,7 +1089,19 @@
 }
 }
 if (!empty($contact['preferred_language'])) {
-wmf_civicrm_ensure_language_exists($contact['preferred_language']);
+if 
(!wmf_civicrm_check_language_exists($contact['preferred_language'])) {
+  $parts = explode('_', $contact['preferred_language']);
+  if (wmf_civicrm_check_language_exists($parts[0])) {
+// in other words en_NO will be converted to en
+// rather than Norwegian English.
+$contact['preferred_language'] = $parts[0];
+  }
+  else {
+// otherwise let's create it rather than fail.
+// seems like the easiest way not to lose visibility, data or the 
plot.
+wmf_civicrm_ensure_language_exists($contact['preferred_language']);
+  }
+}
 }
 
 // Copy some fields, if they exist
@@ -1258,6 +1270,23 @@
 }
 
 /**
+ * Check if the language string exists.
+ *
+ * @param string $languageAbbreviation
+ *
+ * @return bool
+ */
+function wmf_civicrm_check_language_exists($languageAbbreviation) {
+  static $languages;
+  if (empty($languages)) {
+$available_options = civicrm_api3('Contact', 'getoptions', array(
+  'field' => 'preferred_language',
+));
+$languages = $available_options['values'];
+  }
+  return !empty($languages[$languageAbbreviation]);
+}
+/**
  * Ensure the required option value exists.
  *
  * @param string $option_value

-- 
To view, visit https://gerrit.wikimedia.org/r/312156
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie7e8a958c2496a738ce738dd827b7ed04b2d9fbd
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: deployment
Gerrit-Owner: Eileen 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits