Awight has uploaded a new change for review. https://gerrit.wikimedia.org/r/150164
Change subject: Make double-normalization harmless ...................................................................... Make double-normalization harmless This fixes a bug which is currently breaking recurring import, where double-normalization causes source_enqueued_time to be encoded wrong. Change-Id: Ice385c5d21b7015e4296498bf8a2ec52d1520f08 --- A sites/all/modules/wmf_civicrm/tests/phpunit/NormalizeMessageTest.php M sites/all/modules/wmf_civicrm/wmf_civicrm.module 2 files changed, 88 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm refs/changes/64/150164/1 diff --git a/sites/all/modules/wmf_civicrm/tests/phpunit/NormalizeMessageTest.php b/sites/all/modules/wmf_civicrm/tests/phpunit/NormalizeMessageTest.php new file mode 100644 index 0000000..8c62687 --- /dev/null +++ b/sites/all/modules/wmf_civicrm/tests/phpunit/NormalizeMessageTest.php @@ -0,0 +1,73 @@ +<?php + +class NormalizeMessageTest extends BaseWmfDrupalPhpUnitTestCase { + public static function getInfo() { + return array( + 'name' => 'WmfCivicrm message normalization', + 'group' => 'Pipeline', + 'description' => 'Checks for queue message normalization behavior', + ); + } + + public function testDoubleNormalization() { + // Start with a message already in normal form, to make comparison easy + $original_msg = array( + 'anonymous' => 0, + 'check_number' => '', + 'city' => '', + 'comment' => '', + 'contact_id' => mt_rand(), + 'contribution_recur_id' => mt_rand(), + 'contribution_tracking_id' => mt_rand(), + 'contribution_tracking_update' => '1', + 'contribution_type' => 'cash', + 'contribution_type_id' => '9', + 'country' => 'IL', + 'create_date' => time() + 11, + 'currency' => 'USD', + 'date' => time() + 1, + 'effort_id' => '2', + 'email' => 'test...@localhost.net', + 'fee' => 0.5, + 'first_name' => 'test', + 'gateway' => 'paypal', + 'gateway_txn_id' => '1234AB1234-2', + 'gross' => 5.8, + 'last_name' => 'es', + 'letter_code' => '', + 'middle_name' => '', + 'net' => 5.29, + 'optout' => 0, + 'organization_name' => '', + 'original_currency' => 'ILS', + 'original_gross' => '20.00', + 'payment_date' => time(), + 'payment_instrument_id' => '25', + 'payment_instrument' => 'Paypal', + 'postal_code' => '', + 'postmark_date' => null, + 'recurring' => '1', + 'source_enqueued_time' => time() + 2, + 'source_host' => 'thulium', + 'source_name' => 'PayPal IPN (legacy)', + 'source_run_id' => mt_rand(), + 'source_type' => 'listener', + 'source_version' => 'legacy', + 'start_date' => time() + 10, + 'state_province' => '', + 'street_address' => '', + 'subscr_id' => 'TEST-S-1234567' . mt_rand(), + 'supplemental_address_1' => '', + 'supplemental_address_2' => '', + 'thankyou_date' => '', + 'txn_type' => 'subscr_payment', + 'utm_campaign' => '', + ); + + $msg = $original_msg; + $normal_msg_1 = wmf_civicrm_normalize_msg( $msg ); + $this->assertEquals( $original_msg, $normal_msg_1 ); + $normal_msg_2 = wmf_civicrm_normalize_msg( $normal_msg_1 ); + $this->assertEquals( $original_msg, $normal_msg_2 ); + } +} diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module b/sites/all/modules/wmf_civicrm/wmf_civicrm.module index a76b65d..10bd02c 100644 --- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module +++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module @@ -346,6 +346,19 @@ } } + // Transform any unix timestamps into an unambiguous MySQL datetime literal. + $date_mangle = array( + 'postmark_date', + 'source_enqueued_time', + ); + foreach ( $date_mangle as $field ) { + if ( is_numeric( $custom_vars[$field] ) + and strlen( $custom_vars[$field] ) < 14 + ) { + $custom_vars[$field] = wmf_common_date_unix_to_sql( $custom_vars[$field] ); + } + } + $custom_vars += $custom_field_defaults; wmf_civicrm_set_custom_field_values( $contribution_result[ 'id' ], $custom_vars ); @@ -1100,6 +1113,7 @@ 'country' => '', 'state_province' => '', 'postal_code' => '', + 'postmark_date' => null, 'check_number' => null, 'letter_code' => null, 'thankyou_date' => null, @@ -1150,6 +1164,7 @@ $anonymous = ( array_key_exists( 'anonymous', $msg) && $msg['anonymous'] == true && strtoupper( $msg['anonymous'] ) != "FALSE" ) ? 1 : 0; $optout = ( array_key_exists( 'optout', $msg ) && $msg['optout'] == true && strtoupper( $msg['optout'] ) != "FALSE" ) ? 1 : 0; + // FIXME $contribution_tracking_id = wmf_civicrm_insert_contribution_tracking( '..' . $msg['payment_method'], 'civicrm', wmf_common_date_unix_to_sql( $msg['date'] ), null, $optout, $anonymous ); //ACK! this should not be handled this way! should be dynamic! watchdog( 'wmf_civicrm', 'Newly inserted contribution tracking id: @id', array( '@id' => $contribution_tracking_id ), WATCHDOG_DEBUG ); $msg['contribution_tracking_id'] = $contribution_tracking_id; @@ -1217,16 +1232,6 @@ $msg['direct_mail_appeal'] = $msg['utm_campaign']; break; } - } - - if ( isset( $msg['source_enqueued_time'] ) - and is_numeric( $msg['source_enqueued_time'] ) - ) { - $msg['source_enqueued_time'] = wmf_common_date_unix_to_sql( $msg['source_enqueued_time'] ); - } - - if ( isset( $msg['postmark_date'] ) ) { - $msg['postmark_date'] = wmf_common_date_unix_to_sql( $msg['postmark_date'] ); } $msg['anonymous'] = ((!empty( $msg['anonymous'] ) && strtoupper($msg['anonymous'] ) !== "FALSE") ? 1 : 0); -- To view, visit https://gerrit.wikimedia.org/r/150164 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ice385c5d21b7015e4296498bf8a2ec52d1520f08 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Awight <awi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits