Eileen has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/350102 )
Change subject: Fix payment instrument lookup function to work above the 25
limit.
......................................................................
Fix payment instrument lookup function to work above the 25 limit.
The optionValue api call has a limit of 25 by default, so not all are
retrieved. The getoptions
has the advantage of better caching too.
I have doubts about the value of doing our own translations at all here, but
leaving that out of scope
Change-Id: Ib98883909a5a3a570dbe84a4dc0fd0c6b7365241
---
M sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
2 files changed, 32 insertions(+), 11 deletions(-)
Approvals:
jenkins-bot: Verified
Ejegg: Looks good to me, approved
diff --git
a/sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php
b/sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php
index cb9bc15..0307afc 100644
--- a/sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php
+++ b/sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php
@@ -26,6 +26,28 @@
$this->assertEquals(1, $languages['count']);
}
+ /**
+ * Test that the payment instrument is converted to an id.
+ *
+ * Use a high number to ensure the default 25 limit does not hurt us.
+ */
+ public function testGetCiviID() {
+ civicrm_initialize();
+ $paymentMethodID = wmf_civicrm_get_civi_id('payment_instrument_id',
'Trilogy');
+ $this->assertTrue(is_numeric($paymentMethodID));
+ }
+
+ /**
+ * Test that the payment instrument is converted to an id.
+ *
+ * Use a high number to ensure the default 25 limit does not hurt us.
+ */
+ public function testGetInvalidCiviID() {
+ civicrm_initialize();
+ $paymentMethodID = wmf_civicrm_get_civi_id('payment_instrument_id',
'Monopoly money');
+ $this->assertEquals(FALSE, $paymentMethodID);
+ }
+
/**
* Test wmf custom api entity get detail.
*
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index a3fb78f..ba78a5d 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -500,7 +500,11 @@
}
/**
- * @fixme TODO: make the v3 API calls use the wrapper function
+ * Translate option value to CiviCRM id.
+ *
+ * Note that in general we do not need to translate these names to ids as the
CiviCRM
+ * api does that. This allows us to add additional error checking, although
+ * possibly for not much gain.
*
* @param string $type
* @param $name
@@ -545,17 +549,10 @@
}
return $id;
case 'payment_instrument_id':
- require_once 'api/v3/OptionValue.php';
- $group_id = civicrm_api3_option_value_get(
- array('option_group_name' => 'payment_instrument', 'label'=>
$name, 'version' => '3'));
- if($group_id['count'] == 1){
- $civi_ids[$type][$name] =
$group_id['values'][strval($group_id['id'])]['value'];
- watchdog('wmf_civicrm', "Found value for payment_instrument
$name :" . $civi_ids[$type][$name]);
- return $civi_ids[$type][$name];
- } else {
- throw new WmfException("CIVI_CONFIG", t("Payment Instrument
'!name' not found!", array("!name" => $name)));
- }
+ $instruments = civicrm_api3('Contribution', 'getoptions',
array('field' => 'payment_instrument_id'));
+ return array_search($name, $instruments['values']);
break;
+
default:
throw new WmfException("CIVI_CONFIG", t("Civi lookup for type
'!type' not implemented", array("!type" => $type)));
}
@@ -1765,6 +1762,8 @@
throw new WmfException( 'INVALID_MESSAGE', 'No payment
instrument specified' );
}
}
+ // CiviCRM does not require us to do this translation. It will do the
same thing
+ // if we don't & through a mandatory_missing error.
$msg['payment_instrument_id'] = wmf_civicrm_get_civi_id(
'payment_instrument_id', $msg['payment_instrument'] );
}
if ( !$msg['payment_instrument_id'] ) {
--
To view, visit https://gerrit.wikimedia.org/r/350102
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib98883909a5a3a570dbe84a4dc0fd0c6b7365241
Gerrit-PatchSet: 2
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Eileen <[email protected]>
Gerrit-Reviewer: Eileen <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits