Ejegg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/171889
Change subject: Include 'Do Not Solicit' field in offline imports
......................................................................
Include 'Do Not Solicit' field in offline imports
Change-Id: I8884cd6f970f4ab5e02e3cdc8c7b36ef0101a9dd
---
M sites/all/modules/offline2civicrm/ChecksFile.php
M sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
3 files changed, 49 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/89/171889/1
diff --git a/sites/all/modules/offline2civicrm/ChecksFile.php
b/sites/all/modules/offline2civicrm/ChecksFile.php
index c16a0ef..07231e6 100644
--- a/sites/all/modules/offline2civicrm/ChecksFile.php
+++ b/sites/all/modules/offline2civicrm/ChecksFile.php
@@ -250,6 +250,7 @@
'Do Not Mail' => 'do_not_mail',
'Do Not Phone' => 'do_not_phone',
'Do Not SMS' => 'do_not_sms',
+ 'Do Not Solicit' => 'do_not_solicit',
'Email' => 'email',
'First Name' => 'first_name',
'Gift Source' => 'gift_source',
diff --git a/sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php
b/sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php
index ccac575..60518f9 100644
--- a/sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php
+++ b/sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php
@@ -82,6 +82,28 @@
}
/**
+ * Make sure we import 'Do Not Solicit' values to the wmf_donor table
+ */
+ public function testImportDoNotSolicit() {
+ $msg = array(
+ 'email' => '[email protected]',
+ 'gross' => '1.23',
+ 'currency' => 'USD',
+ 'payment_method' => 'cc',
+ 'gateway' => 'test_gateway',
+ 'do_not_solicit' => 'Y',
+ 'gateway_txn_id' => mt_rand(),
+ );
+ $contribution = wmf_civicrm_contribution_message_import( $msg );
+ $donor_fields = wmf_civicrm_contribution_get_custom_values(
+ $contribution['contact_id'],
+ array( 'do_not_solicit' ),
+ 'wmf_donor'
+ );
+ $this->assertEquals( '1', $donor_fields['do_not_solicit'] );
+ }
+
+ /**
* Remove unique stuff which cannot be expected
*/
function stripUniques( &$contribution ) {
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index 6a5a08d..971352d 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -126,13 +126,12 @@
return array_merge( $contribution, $custom_values );
}
-// FIXME all of these custom field helpers share flaws: they do not consider
entity type, or custom group name
-function wmf_civicrm_contribution_get_custom_values( $contribution_id, $names )
+function wmf_civicrm_contribution_get_custom_values( $entity_id, $names,
$group_name = null )
{
$names = (array)$names;
- $params[ 'entityID' ] = $contribution_id;
+ $params[ 'entityID' ] = $entity_id;
foreach ( $names as $name ) {
- $field = wmf_civicrm_get_custom_field_name( $name );
+ $field = wmf_civicrm_get_custom_field_name( $name, $group_name );
$params[ $field ] = 1;
$field_map[ $field ] = $name;
}
@@ -146,13 +145,12 @@
return $ret;
}
-// FIXME: this is only valid for contributions
-function wmf_civicrm_set_custom_field_values($entity_id, $map)
+function wmf_civicrm_set_custom_field_values($entity_id, $map, $group_name =
null)
{
$params = array(
'entityID' => $entity_id,
);
- $custom_fields = wmf_civicrm_get_custom_field_map(array_keys($map));
+ $custom_fields = wmf_civicrm_get_custom_field_map(array_keys($map),
$group_name);
foreach ($map as $field_name => $value)
{
$params[$custom_fields[$field_name]] = $value;
@@ -181,8 +179,8 @@
return $custom_fields;
}
-function wmf_civicrm_get_custom_field_name( $field_name ) {
- $custom_fields = wmf_civicrm_get_custom_field_map( array( $field_name ) );
+function wmf_civicrm_get_custom_field_name( $field_name, $group_name = null ) {
+ $custom_fields = wmf_civicrm_get_custom_field_map( array( $field_name ),
$group_name );
return $custom_fields[ $field_name ];
}
@@ -912,9 +910,27 @@
"Contact could not be added. Aborting import. Contact data was " .
print_r($contact, true) . " Original error: " . $ex->getMessage()
);
}
+ $contact_id = $contact_result['id'];
+
+ // Add any wmf_donor custom field values
+ $wmf_donor_fields = array(
+ 'do_not_solicit',
+ );
+ $wmf_donor_values = array();
+ foreach ( $wmf_donor_fields as $donor_field ) {
+ if ( isset( $msg[$donor_field] ) ) {
+ $wmf_donor_values[$donor_field] = $msg[$donor_field];
+ }
+ }
+ if ( !empty( $wmf_donor_values ) ) {
+ try {
+ wmf_civicrm_set_custom_field_values( $contact_id,
$wmf_donor_values, 'wmf_donor' );
+ } catch ( WmfException $ex ) {
+ watchdog( 'wmf_civicrm', "Setting wmf_donor custom field values
failed with details: {$ex->getMessage()}", array(), WATCHDOG_ERROR );
+ }
+ }
// Do we have any tags we need to add to this contact?
- $contact_id = $contact_result['id'];
if ( $msg['contact_tags'] ) {
$supported_tags = array_flip(CRM_Core_PseudoConstant::tag());
$stacked_ex = array();
--
To view, visit https://gerrit.wikimedia.org/r/171889
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8884cd6f970f4ab5e02e3cdc8c7b36ef0101a9dd
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits