Awight has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277692
Change subject: Simplify option value retrieval, fail fast
......................................................................
Simplify option value retrieval, fail fast
Searching the group cache for $key was a bug. We assign using
$row->value as the key, and worse, this function can be legitimately
invoked with $key = null.
Throw an exception when we fail to find a value. Calling code can
catch if desired, but we almost always want to halt execution.
Bug: T128389
Change-Id: Ibcb4864ee347f45aaa000260cc73445029fc1eb8
---
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
1 file changed, 7 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/92/277692/1
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index 4a31066..b0999de 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -5,6 +5,8 @@
/**
* return a map of option value (id) => option name
+ *
+ * FIXME: Break into separate functions rather than magically switching return
type
*/
function civicrm_api_option_group($group_name, $key = null, $force = FALSE)
{
@@ -18,23 +20,17 @@
));
$cached_group[$group_name] = array();
$option_values = $api->values();
- foreach ($option_values as $row)
- {
- if (!array_search($key, $cached_group[$group_name])) {
- $cached_group[$group_name][$row->value] =
$row->name;
- if (empty($row->name)) {
- watchdog('wmf_civicrm', 'Option Value
Not Found: %group_name -> %value',
- array('%group_name' =>
$group_name, '%value' => print_r($row, TRUE)),
- WATCHDOG_NOTICE
- );
- }
- }
+ foreach ($option_values as $row) {
+ $cached_group[$group_name][$row->value] = $row->name;
}
}
if ($key)
{
// In this case, just lookup name and return the option value
$forwards = array_flip( $cached_group[$group_name] );
+ if ( !array_key_exists( $key, $forwards ) ) {
+ throw new DomainException( "Option value not found:
{$group_name} -> {$key}" );
+ }
return $forwards[$key];
}
return $cached_group[$group_name];
--
To view, visit https://gerrit.wikimedia.org/r/277692
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibcb4864ee347f45aaa000260cc73445029fc1eb8
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: deployment
Gerrit-Owner: Awight <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits