jenkins-bot has submitted this change and it was merged.
Change subject: Move donation queue consumer off ActiveMQ
......................................................................
Move donation queue consumer off ActiveMQ
Trying to tread lightly, so this commit preserves the probably-
unused module_invoke_all call and the odd signature of the pending
merge method.
Hard-codes donation queue config key. We should get rid of the UI-
configurable config key for the other queue consumers as well.
Updates donation queue name in audit mirroring to match I73bb2cb8d.
includes/QueueConsumer had a ton of obsolete code. Looks like it
used to be a PHPUnitTestCase descendant but got disowned.
Bug: T131277
Change-Id: Iae39859d0a00a22b8b0388bda525f78bab9f37bf
---
M sites/all/modules/globalcollect_audit/globalcollect_audit.module
A sites/all/modules/queue2civicrm/DonationQueueConsumer.php
M sites/all/modules/queue2civicrm/queue2civicrm.info
M sites/all/modules/queue2civicrm/queue2civicrm.module
D sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php
M sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
M sites/all/modules/wmf_audit/wmf_audit.module
7 files changed, 148 insertions(+), 398 deletions(-)
Approvals:
Awight: Looks good to me, approved
jenkins-bot: Verified
diff --git a/sites/all/modules/globalcollect_audit/globalcollect_audit.module
b/sites/all/modules/globalcollect_audit/globalcollect_audit.module
index 3e25a94..21bfea6 100644
--- a/sites/all/modules/globalcollect_audit/globalcollect_audit.module
+++ b/sites/all/modules/globalcollect_audit/globalcollect_audit.module
@@ -2018,7 +2018,7 @@
// FIXME: register the queue mapping somewhere sane
if ( $queueId === 'donations' ) {
$queuePath = variable_get( 'queue2civicrm_subscription',
'/queue/donations' );
- $configKey = 'data-store/verified-new';
+ $configKey = 'data-store/donations';
} elseif ( $queueId === 'refund' ) {
$queuePath = variable_get( 'refund_queue', '/queue/refund' );
$configKey = 'data-store/refund-new';
diff --git a/sites/all/modules/queue2civicrm/DonationQueueConsumer.php
b/sites/all/modules/queue2civicrm/DonationQueueConsumer.php
new file mode 100644
index 0000000..26ad9fb
--- /dev/null
+++ b/sites/all/modules/queue2civicrm/DonationQueueConsumer.php
@@ -0,0 +1,105 @@
+<?php namespace queue2civicrm;
+
+use Queue2civicrmTrxnCounter;
+use SmashPig\Core\DataStores\PendingDatabase;
+use wmf_common\TransactionalWmfQueueConsumer;
+use WmfException;
+
+class DonationQueueConsumer extends TransactionalWmfQueueConsumer {
+
+ /**
+ * Feed queue messages to wmf_civicrm_contribution_message_import,
+ * logging and merging any extra info from the pending db.
+ *
+ * @param array $message
+ * @throws WmfException
+ */
+ public function processMessage( $message ) {
+
+ /**
+ * prepare data for logging
+ */
+ $log = array(
+ 'gateway' => $message['gateway'],
+ 'gateway_txn_id' => $message['gateway_txn_id'],
+ 'data' => json_encode( $message ),
+ 'timestamp' => time(),
+ 'verified' => 0,
+ );
+ $logId = _queue2civicrm_log( $log );
+
+ $pendingDbEntry = false;
+ // If more information is available, find it from the pending
database
+ // FIXME: replace completion_message_id with a boolean flag
+ if ( isset( $message['completion_message_id'] ) ) {
+ $pendingDbEntry = $this->updateFromPendingDb( $message
);
+ if ( !$pendingDbEntry ) {
+ // If the contribution has already been
imported, this check will
+ // throw an exception that says to drop it
entirely, not re-queue.
+ wmf_civicrm_check_for_duplicates(
+ $message['gateway'],
$message['gateway_txn_id']
+ );
+ // Otherwise, throw an exception that tells the
queue consumer to
+ // requeue the incomplete message with a delay.
+ $errorMessage = "Message
{$message['gateway']}-{$message['gateway_txn_id']} " .
+ "indicates a pending DB entry with
order ID {$message['order_id']}, " .
+ "but none was found. Requeueing.";
+ throw new WmfException( 'MISSING_PREDECESSOR',
$errorMessage );
+ }
+ }
+
+ $contribution = wmf_civicrm_contribution_message_import(
$message );
+
+ // construct an array of useful info to invocations of
queue2civicrm_import
+ $contribution_info = array(
+ 'contribution_id' => $contribution['id'],
+ 'contact_id' => $contribution['contact_id'],
+ 'msg' => $message,
+ );
+
+ // update the log if things went well
+ if ( $logId ) {
+ $log[ 'cid' ] = $logId;
+ $log[ 'verified' ] = 1;
+ $log[ 'timestamp' ] = time();
+ _queue2civicrm_log( $log );
+ }
+
+ // Fire a hook handler that I'm pretty sure isn't used (FIXME)
+ module_invoke_all( 'queue2civicrm_import', $contribution_info );
+
+ // keep count of the transactions
+ Queue2civicrmTrxnCounter::instance()->increment(
$message['gateway'] );
+
+ // Delete message from pending db once the rest has completed
successfully
+ if ( $pendingDbEntry ) {
+ PendingDatabase::get()->deleteMessage( $pendingDbEntry
);
+ }
+ }
+
+ /**
+ * Fill in some missing information from the pending database
+ * @param array $msg sparse donation message, usually from IPN listener
+ * @return array|null message from database, or null if not found
+ */
+ protected function updateFromPendingDb( &$msg ) {
+ $gateway = $msg['gateway'];
+ $orderId = $msg['order_id'];
+
+ $pendingDbData =
PendingDatabase::get()->fetchMessageByGatewayOrderId(
+ $gateway,
+ $orderId
+ );
+
+ // Sparse messages should have no keys at all for the missing
info,
+ // rather than blanks or junk data. And $msg should always have
newer
+ // info than the pending db.
+ if ( $pendingDbData ) {
+ $msg = $msg + $pendingDbData;
+ // $data has a pending_id key for ease of deletion,
+ // but $msg doesn't need it
+ unset( $msg['pending_id'] );
+ }
+ return $pendingDbData;
+ }
+}
diff --git a/sites/all/modules/queue2civicrm/queue2civicrm.info
b/sites/all/modules/queue2civicrm/queue2civicrm.info
index 8df0403..6461fd7 100644
--- a/sites/all/modules/queue2civicrm/queue2civicrm.info
+++ b/sites/all/modules/queue2civicrm/queue2civicrm.info
@@ -6,6 +6,7 @@
dependencies[] = wmf_civicrm
package = queue2civicrm
files[] = Queue2civicrmTrxnCounter.php
+files[] = DonationQueueConsumer.php
files[] = Stomp.php
files[] = tests/includes/Message.php
files[] = tests/includes/MessageSource.php
diff --git a/sites/all/modules/queue2civicrm/queue2civicrm.module
b/sites/all/modules/queue2civicrm/queue2civicrm.module
index 7decd29..e36778b 100644
--- a/sites/all/modules/queue2civicrm/queue2civicrm.module
+++ b/sites/all/modules/queue2civicrm/queue2civicrm.module
@@ -1,7 +1,7 @@
<?php
+use queue2civicrm\DonationQueueConsumer;
use SmashPig\Core\Configuration;
use SmashPig\Core\Context;
-use SmashPig\Core\DataStores\PendingDatabase;
// include common functions
require_once( drupal_get_path( 'module', 'queue2civicrm' ) .
'/queue2civicrm_common.inc' );
@@ -107,6 +107,7 @@
'#default_value' => queue2civicrm_stomp_url(),
);
+ // TODO: Remove when done mirroring from audits to ActiveMQ
$form['queue2civicrm_subscription'] = array(
'#type' => 'textfield',
'#title' => t('Subscription path'),
@@ -186,15 +187,15 @@
return;
}
- $processed = queue2civicrm_stomp()->dequeue_loop(
- variable_get( 'queue2civicrm_subscription', '/queue/donations' ),
- variable_get( 'queue2civicrm_batch', 0 ),
- variable_get( 'queue2civicrm_batch_time', 0 ),
- 'queue2civicrm_import'
+ $consumer = new DonationQueueConsumer(
+ 'donations',
+ variable_get( 'queue2civicrm_batch_time', 0 ),
+ variable_get( 'queue2civicrm_batch', 0 )
);
+ $processed = $consumer->dequeueMessages();
/**
- * this may some day supercede the process counts handled above...
+ * this may some day supersede the process counts handled above...
*
* Note that this might be a little whack. At least, it feels a little
sloppy.
* The tmax/dmax fields should probably be configurable
@@ -222,111 +223,4 @@
else {
watchdog('queue2civicrm', 'No contributions processed.');
}
-}
-
-/**
- * Process one contribution from the queue to CiviCRM.
- *
- * @param Stomp_Frame|array $msg
- */
-function queue2civicrm_import( $msg ) {
- if ( is_object( $msg ) && property_exists( $msg, 'body' ) ) {
- $msg = $msg->body;
- }
-
- if ( is_string( $msg ) ) {
- // save the original message for logging
- $msg_orig = $msg;
-
- $msg = json_decode( $msg, true );
- } else {
- $msg_orig = json_encode( $msg );
- }
-
- /**
- * prepare data for logging
- */
- $log = array(
- 'gateway' => $msg[ 'gateway' ],
- 'gateway_txn_id' => $msg[ 'gateway_txn_id' ],
- 'data' => $msg_orig,
- 'timestamp' => time(),
- 'verified' => 0,
- );
- $cid = _queue2civicrm_log( $log );
-
- $dbEntry = false;
- // If more information is available, find it from the pending database
- // FIXME: replace completion_message_id with a boolean flag
- if ( isset( $msg['completion_message_id'] ) ) {
- $dbEntry = queue2civicrm_update_from_pending_db( $msg );
- if ( !$dbEntry ) {
- // If the contribution has already been imported, this check will
- // throw an exception that says to drop it entirely, not re-queue.
- wmf_civicrm_check_for_duplicates(
- $msg['gateway'], $msg['gateway_txn_id']
- );
-
- // Otherwise, throw an exception that tells the queue consumer to
- // requeue the incomplete message with a delay.
- $errorMessage = "Message
{$msg['gateway']}-{$msg['gateway_txn_id']} " .
- "indicates a pending DB entry with order ID
{$msg['order_id']}, " .
- "but none was found. Requeueing.";
- throw new WmfException( 'MISSING_PREDECESSOR', $errorMessage );
- }
- }
-
- $contribution = wmf_civicrm_contribution_message_import($msg);
-
- // construct an array of useful info to invocations of queue2civicrm_import
- $contribution_info = array(
- 'contribution_id' => $contribution['id'],
- 'contact_id' => $contribution['contact_id'],
- 'msg' => $msg,
- );
-
- // update the log if things went well
- if ( $cid ) {
- $log[ 'cid' ] = $cid;
- $log[ 'verified' ] = 1;
- $log[ 'timestamp' ] = time();
- _queue2civicrm_log( $log );
- }
-
- // Send thank you email, other post-import things
- module_invoke_all( 'queue2civicrm_import', $contribution_info );
-
- // keep count of the transactions
- Queue2civicrmTrxnCounter::instance()->increment( $msg['gateway'] );
-
- // Delete message from pending db once the rest has completed successfully
- if ( $dbEntry ) {
- PendingDatabase::get()->deleteMessage( $dbEntry );
- }
-}
-
-/**
- * Fill in some missing information from the pending database
- * @param array $msg sparse donation message, usually from IPN listener
- * @return array|null message from database, or null if not found
- */
-function queue2civicrm_update_from_pending_db( &$msg ) {
- $gateway = $msg['gateway'];
- $orderId = $msg['order_id'];
-
- $data = PendingDatabase::get()->fetchMessageByGatewayOrderId(
- $gateway,
- $orderId
- );
-
- // Sparse messages should have no keys at all for the missing info,
- // rather than blanks or junk data. And $msg should always have newer
- // info than the pending db.
- if ( $data ) {
- $msg = $msg + $data;
- // $data has a pending_id key for ease of deletion,
- // but $msg doesn't need it
- unset( $msg['pending_id'] );
- }
- return $data;
}
diff --git a/sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php
b/sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php
deleted file mode 100644
index cd845fe..0000000
--- a/sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php
+++ /dev/null
@@ -1,271 +0,0 @@
-<?php
-
-class QueueConsumer {
- protected $queue_name = 'civiCRM_test';
- protected $url = 'tcp://localhost:61613';
-
- function __construct() {
- $this->recip_email = variable_get('wmf_test_settings_email',
'');
-
- variable_set( 'queue2civicrm_subscription',
"/queue/{$this->queue_name}" );
- variable_set( 'queue2civicrm_url', $this->url );
- variable_set( 'queue2civicrm_failmail', $this->recip_email );
- }
-
- function tearDown(){
- parent::tearDown();
- }
-
- //determine that we are in fact able to read and write to activeMQ
- function testStompPushPop() {
- $this->emptyQueue();
- //queue2civicrm_insertmq_form_submit($form, &$form_state)
$form_state['values'] appears to be where all the $key=>$value form pairs live.
- ////Just fake it out. :p queue2civicrm_generate_message() will do
nicely.
- $message = Message::generateRandom();
- //I think we want gateway_txn_id and contribution_tracking_id to match
much the same way we did before.
- $message['gateway_txn_id'] = "civiTest";
- $message['contribution_tracking_id'] = $message['gateway_txn_id'];
- $message['queue'] = variable_get('queue2civicrm_subscription',
'/queue/oopsie');
- $message = array('values' => $message);
-
- $ret = queue2civicrm_insertmq_form_submit(array(), $message);
- $message_return = $this->getItemFromQueue();
- $this->assertTrue(is_object($message_return), "No message was
returned");
- $body = json_decode($message_return->body, true);
- foreach($message['values'] as $key=>$value){
- $this->assertTrue($body[$key] == $value, $body[$key] . " !=
$value");
- }
- }
-
- function testConnect(){
- $this->assertDrushLogEmpty(true);
- variable_set('queue2civicrm_url', 'tcp://bananas:123');
- $con = wmf_common_stomp_connection(true);
- $this->assertTrue($con === false, "Connection did not fail
appropriately.");
- //check for the drush errors...
- $this->assertDrushLogEmpty(false);
- $this->assertCheckDrushLog('STOMP_BAD_CONNECTION', true, "Appropriate
Drush error was not thrown.");
-
- //put everything back to normaltestCurrencyConversion
- $this->assertDeleteDrushLog();
- variable_set('queue2civicrm_url', 'tcp://localhost:61613'); //@fixme:
This should be grabbing from an ini or something.
- $con = wmf_common_stomp_connection(true);
-
- $this->assertTrue($con !== false, "Connection failed, and should have
worked the second time 'round.");
- }
-
- function testRequiredFields(){
- $this->assertDeleteDrushLog();
-
- //Should be required:
- //first, last, email, amount, currency, payment type, gateway
transaction ID
- $required = array(
- 'email' => $this->recip_email,
- 'gross' => '7.77',
- 'original_currency' => 'USD',
- 'gateway' => 'something',
- 'gateway_txn_id' => '11235' . time()
- );
- queue2civicrm_import( $required );
- $this->assertDrushLogEmpty(true);
-
- foreach ($required as $key=>$value){
- $msg = $required;
- unset($msg[$key]);
- queue2civicrm_import( $msg );
- $this->assertDrushLogEmpty(false);
- $this->assertCheckDrushLog('CIVI_REQ_FIELD', true, "Missing
required $key does not trigger an error.");
- $this->assertDeleteDrushLog();
- }
-
- $test_name = array(
- 'first_name' => 'Testy',
- 'middle_name' => 'T.',
- 'last_name' => 'Testaberger',
- 'gross' => '8.88',
- 'gateway_txn_id' => '12358' . time()
- );
-
- $msg = array_merge($required, $test_name);
- queue2civicrm_import( $msg );
- $this->assertDrushLogEmpty(true);
-
- }
-
- function testCurrencyConversion(){
- $test_currency_conversion = array(
- 'email' => $this->recip_email,
- 'gross' => '7.77',
- 'original_currency' => 'EUR',
- 'gateway' => 'something',
- 'gateway_txn_id' => '11235',
- 'contribution_tracking_id' => '' //don't actually need these in
the DB, as we're just testing the currency conversions.
- );
- $msg = wmf_civicrm_verify_message_and_stage($test_currency_conversion);
- $this->assertTrue($test_currency_conversion['gross'] ==
$msg['original_gross'], "Original Gross in converted message does not match
actual original gross.");
- // commenting out below assertion - not a foolproof assertion
~awjrichards
- //$this->assertTrue($test_currency_conversion['gross'] !=
$msg['gross'], "Gross is identical: No conversion was done (unless " .
$test_currency_conversion['original_currency'] . " = USD for a minute");
-
- $test_currency_conversion['original_currency'] = 'USD';
- $msg = wmf_civicrm_verify_message_and_stage($test_currency_conversion);
- $this->assertTrue($test_currency_conversion['gross'] ==
$msg['original_gross'], "Original Gross in converted message does not match
actual original gross.");
- $this->assertTrue($test_currency_conversion['gross'] == $msg['gross'],
"USD to USD Gross is not identical!");
- }
-
- function testGetTopError(){
- $this->assertDeleteDrushLog();
- $error = _queue2civicrm_get_top_new_drush_error();
- //should return false
- $this->assertFalse($error, "There are no drush errors to return, but
we got '$error'");
-
- //now throw three errors, and make sure the most severe is returned.
- drush_set_error("IMPORT_TAG", "Test Error Message #1");
- drush_set_error("CIVI_CONFIG", "Test Error Message #2");
- drush_set_error("IMPORT_CONTACT", "Test Error Message #3");
- $error = _queue2civicrm_get_top_new_drush_error();
-
- //looking for the CIVI_CONFIG error
- $this->assertTrue($error['err_code'] === 'CIVI_CONFIG', "New top error
should be CIVI_CONFIG; returned " . $error['err_code']);
- $this->assertTrue($error['err_text'] === "Messages:\n Test Error
Message #2", "Expected message not returned: " . $error['err_text']);
-
- //now stack some slightly less important errors and see if we get
exactly the new ones.
- drush_set_error("IMPORT_CONTACT", "Test Error Message #4");
- drush_set_error("IMPORT_CONTACT", "Test Error Message #5");
- drush_set_error("IMPORT_CONTACT", "Test Error Message #6");
- $error = _queue2civicrm_get_top_new_drush_error();
-
- $this->assertTrue($error['err_code'] === 'IMPORT_CONTACT', "New top
error should be IMPORT_CONTACT; returned " . $error['err_code']);
- $this->assertTrue($error['err_text'] === "Messages:\n Test Error
Message #4\n Test Error Message #5\n Test Error Message #6", "Expected
message not returned: " . $error['err_text']);
-
- queue2civicrm_failmail($error, "This is a test message!", true);
- queue2civicrm_failmail($error, "This is another test message!", false);
- }
-
- function testBatchProcess(){
- //clear and add test messages to the testing queue.
- $this->emptyQueue();
-
- $messages_in = array();
- for ($i=0; $i<10; ++$i){
- $message = Message::generateRandom();
- unset($message['contribution_tracking_id']);
- $message['gateway'] = 'CiviTest' . $i;
- $message['gateway_txn_id'] = time();
- $message['queue'] = variable_get('queue2civicrm_subscription',
'/queue/oopsie');
- //create some havoc
- if($i == 3){
- unset($message['email']); //this should throw a nice error and
email and things.
- }
- $messages_in[] = $message;
- $message = array('values' => $message);
- $ret = queue2civicrm_insertmq_form_submit(array(), $message);
- }
-
- $this->assertDeleteDrushLog();
-
- queue2civicrm_batch_process();
-
- //check the final drush log for all the relevant entries
- $this->assertDrushLogEmpty(false);
- $this->assertCheckDrushLog('CIVI_REQ_FIELD', true, "There should be an
error regarding the missing email address.");
-
- }
-
- function getItemFromQueue(){
- $con = wmf_common_stomp_connection();
- $this->assertTrue(is_object($con), "Could not establish stomp
connection");
- $subscription_queue = variable_get('queue2civicrm_subscription',
'/queue/test');
- if ($con) {
- $con->subscribe($subscription_queue, array('ack' => 'client'));
-
- $msg = $con->readFrame();
-
- // Skip processing if no message to process.
- if ($msg !== FALSE) {
- watchdog('queue2civicrm', 'Read frame:<pre>' .
check_plain(print_r($msg, TRUE)) . '</pre>');
- set_time_limit(60);
- try {
- $con->ack($msg);
- return $msg;
- }
- catch (Exception $e) {
- watchdog('queue2civicrm', 'Could not process frame from queue.',
array(), WATCHDOG_ERROR);
- }
- }
- else {
- watchdog('queue2civicrm', 'Nothing to process.');
- }
- $con->unsubscribe( $subscription_queue );
- }
- return FALSE;
- }
-
- function emptyQueue(){
- while (is_object($this->getItemFromQueue())){
- //uh. Yeah. That. Weirdest while loop EVAR.
- }
- }
-
- function assertDeleteDrushLog(){
- $error_log =& drush_get_context('DRUSH_ERROR_LOG', array());
- $error_log = array(); //gwa ha ha ha
- $error = drush_get_error_log();
- $this->assertTrue(empty($error), "Drush error log should now be empty"
. print_r($error, true));
- }
-
- function assertCheckDrushLog($drush_error_type, $exists,
$assertFailMessage){
- $error = drush_get_error_log();
- $this->assertTrue(array_key_exists($drush_error_type, $error) ===
$exists, $assertFailMessage . "\nLooking for $drush_error_type\n" .
print_r($error, true));
- }
-
- function assertDrushLogEmpty($state){
- $error = drush_get_error_log();
- $message = "Drush log should " . (($state)?"":"not ") . "be empty\n" .
print_r($error, true);
- $this->assertTrue(empty($error) === $state, $message);
- }
-
- function assertEmailIsSet(){
- if ($this->recip_email == ''){
- $this->fail("Recipient email for testing is not configured. Please
configure this value in the wmf_test_settings module.");
- return false;
- } else {
- return true;
- }
- }
-
- /**
- * Test methods in Queue2civicrmTrxnCounter and associated wrapper
functions
- */
- function testQueue2CivicrmTrxnCounter() {
- $trxn_counter = Queue2civicrmTrxnCounter::instance();
- $trxn_counter->foo = 'bar';
- $this->assertIdentical( $trxn_counter,
Queue2civicrmTrxnCounter::instance(),
- 'Queue2civicrmTrxnCounter::instance() not returning identical
objects.');
-
- // make sure adding and fetching counts work
- Queue2civicrmTrxnCounter::instance()->increment( 'lions' );
- $lions_count = $trxn_counter->get_count_total( 'lions' );
- $this->assertEqual( $lions_count, 1, 'Gateway count test failed,
expected 1, got ' . $lions_count );
- Queue2civicrmTrxnCounter::instance()->increment( 'lions', 3 );
- $lions_count = $trxn_counter->get_count_total( 'lions' );
- $this->assertEqual( $lions_count, 4, 'Gateway count test failed,
expected 4, got ' . $lions_count );
- $overall_count = $trxn_counter->get_count_total();
- $this->assertEqual( $overall_count, 4, 'Overall gateway count test
failed. Expected 4, got ' . $overall_count );
-
- // make sure that our overall counts are right and that we didn't get a
count for 'foo' gateway
- Queue2civicrmTrxnCounter::instance()->increment( 'bears' );
- Queue2civicrmTrxnCounter::instance()->increment( 'foo' );
- $this->assertFalse( in_array( 'foo', array_keys(
$trxn_counter->get_trxn_counts())), 'Was able to set an invalid gateway.' );
- $overall_count = $trxn_counter->get_count_total();
- $this->assertEqual( $overall_count, 5, 'Overall gateway count test
failed. Expected 5, got ' . $overall_count );
-
- // make sure gateways are properly being set.
- $allGateways = 'lions, bears, foo';
- $gateways = implode( ", ", array_keys(
$trxn_counter->get_trxn_counts()));
- $this->assertEqual( $allGateways, $gateways,
- 'Gateways are not properly being set in Queue2civicrmTrxnCounter.
Expected "' . $allGateways . '", got "' . $gateways . '".' );
- }
-
-}
-
-?>
diff --git
a/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
b/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
index e94c571..2078ef1 100644
--- a/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
+++ b/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
@@ -1,5 +1,6 @@
<?php
+use queue2civicrm\DonationQueueConsumer;
use SmashPig\Core\Context;
use SmashPig\Core\DataStores\PendingDatabase;
use SmashPig\Tests\SmashPigDatabaseTestConfiguration;
@@ -14,11 +15,29 @@
*/
protected $pendingDb;
- public function setUp() {
+ /**
+ * @var DonationQueueConsumer
+ */
+ protected $queueConsumer;
+
+ public function setUp() {
parent::setUp();
- Context::initWithLogger(
SmashPigDatabaseTestConfiguration::instance() );
+ $config = SmashPigDatabaseTestConfiguration::instance();
+ // FIXME: Use all-purpose SmashPig test config when ready
+ $config->override( array(
+ 'data-store' => array(
+ 'donations' => array(
+ 'class' => 'PHPQueue\Backend\PDO',
+ 'constructor-parameters' => array(
array(
+ 'connection_string' =>
'sqlite::memory:'
+ ) )
+ )
+ )
+ ) );
+ Context::initWithLogger( $config );
$this->pendingDb = PendingDatabase::get();
$this->pendingDb->createTable();
+ $this->queueConsumer = new DonationQueueConsumer( 'donations' );
}
/**
@@ -31,8 +50,8 @@
exchange_rate_cache_set( 'USD', $message->get( 'date' ), 1 );
exchange_rate_cache_set( $message->get( 'currency' ), $message->get(
'date' ), 3 );
- queue2civicrm_import( $message );
- queue2civicrm_import( $message2 );
+ $this->queueConsumer->processMessage( $message->getBody() );
+ $this->queueConsumer->processMessage( $message2->getBody() );
$contributions = wmf_civicrm_get_contributions_from_gateway_id(
$message->getGateway(), $message->getGatewayTxnId() );
$this->assertEquals( 1, count( $contributions ) );
@@ -53,7 +72,7 @@
exchange_rate_cache_set( 'USD', $message->get( 'date' ), 1 );
exchange_rate_cache_set( $message->get( 'currency' ), $message->get(
'date' ), 3 );
- queue2civicrm_import( $message );
+ $this->queueConsumer->processMessage( $message->getBody() );
$contributions = wmf_civicrm_get_contributions_from_gateway_id(
$message->getGateway(), $message->getGatewayTxnId() );
$contribution = civicrm_api3('Contribution', 'getsingle', array(
@@ -76,7 +95,7 @@
exchange_rate_cache_set('USD', $message->get('date'), 1);
exchange_rate_cache_set($message->get('currency'),
$message->get('date'), 3);
- queue2civicrm_import($message);
+ $this->queueConsumer->processMessage( $message->getBody() );
$contributions =
wmf_civicrm_get_contributions_from_gateway_id($message->getGateway(),
$message->getGatewayTxnId());
$contribution = civicrm_api3('Contribution', 'getsingle', array(
@@ -99,7 +118,7 @@
exchange_rate_cache_set('USD', $message->get('date'), 1);
exchange_rate_cache_set($message->get('currency'), $message->get('date'),
3);
- queue2civicrm_import($message);
+ $this->queueConsumer->processMessage( $message->getBody() );
$contributions =
wmf_civicrm_get_contributions_from_gateway_id($message->getGateway(),
$message->getGatewayTxnId());
$contribution = civicrm_api3('Contribution', 'getsingle', array(
@@ -226,7 +245,7 @@
exchange_rate_cache_set( 'USD', $donation_message->get('date'), 1 );
exchange_rate_cache_set( $donation_message->get('currency'),
$donation_message->get('date'), 3 );
- queue2civicrm_import( $donation_message );
+ $this->queueConsumer->processMessage( $donation_message->getBody() );
$contributions = wmf_civicrm_get_contributions_from_gateway_id(
$donation_message->getGateway(), $donation_message->getGatewayTxnId() );
$this->assertEquals( 1, count( $contributions ) );
@@ -249,7 +268,7 @@
* Test refunding a mismatched amount.
*
* Note that we were checking against an exception - but it turned out the
exception
- * could be thrown in this fn queue2civicrm_import if the exchange rate
does not
+ * could be thrown in this fn $this->queueConsumer->processMessage if the
exchange rate does not
* exist - which is not what we are testing for.
*/
public function testRefundMismatched() {
@@ -266,7 +285,7 @@
'gross_currency' => $donation_message->get( 'original_currency' ),
) );
- queue2civicrm_import( $donation_message );
+ $this->queueConsumer->processMessage( $donation_message->getBody() );
$contributions = wmf_civicrm_get_contributions_from_gateway_id(
$donation_message->getGateway(), $donation_message->getGatewayTxnId() );
$this->assertEquals( 1, count( $contributions ) );
@@ -280,6 +299,8 @@
/**
* Process a donation message with some info from pending db
* @dataProvider getSparseMessages
+ * @param TransactionMessage $message
+ * @param array $pendingMessage
*/
public function testDonationSparseMessages( $message, $pendingMessage )
{
$pendingMessage['order_id'] = $message->get( 'order_id' );
@@ -291,7 +312,7 @@
exchange_rate_cache_set( 'USD', $message->get( 'date' ), 1 );
exchange_rate_cache_set( $message->get( 'currency' ),
$message->get( 'date' ), 3 );
- queue2civicrm_import( $message );
+ $this->queueConsumer->processMessage( $message->getBody() );
$contributions = wmf_civicrm_get_contributions_from_gateway_id(
$message->getGateway(), $message->getGatewayTxnId() );
$contribution = civicrm_api3('Contribution', 'getsingle', array(
diff --git a/sites/all/modules/wmf_audit/wmf_audit.module
b/sites/all/modules/wmf_audit/wmf_audit.module
index 4891b4c..288401c 100644
--- a/sites/all/modules/wmf_audit/wmf_audit.module
+++ b/sites/all/modules/wmf_audit/wmf_audit.module
@@ -437,7 +437,7 @@
wmf_common_set_message_source($body, 'audit',
wmf_audit_runtime_options('submod_prefix') . ' Recon Auditor');
$configKeys = array(
- 'main' => 'data-store/verified-new',
+ 'main' => 'data-store/donations',
'negative' => 'data-store/refund-new',
'recurring' => 'data-store/recurring-new',
);
--
To view, visit https://gerrit.wikimedia.org/r/308800
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iae39859d0a00a22b8b0388bda525f78bab9f37bf
Gerrit-PatchSet: 8
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits