jenkins-bot has submitted this change and it was merged.

Change subject: Move refund queue consumer off ActiveMQ
......................................................................


Move refund queue consumer off ActiveMQ

Switch to the new queue.

Bug: T145234
Change-Id: I0417025205199e7def08c292da6f04d32c4d6c4c
---
A sites/all/modules/queue2civicrm/refund/RefundQueueConsumer.php
M sites/all/modules/queue2civicrm/refund/wmf_refund_qc.info
M sites/all/modules/queue2civicrm/refund/wmf_refund_qc.module
M sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
4 files changed, 77 insertions(+), 59 deletions(-)

Approvals:
  Awight: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/sites/all/modules/queue2civicrm/refund/RefundQueueConsumer.php 
b/sites/all/modules/queue2civicrm/refund/RefundQueueConsumer.php
new file mode 100644
index 0000000..1840b3e
--- /dev/null
+++ b/sites/all/modules/queue2civicrm/refund/RefundQueueConsumer.php
@@ -0,0 +1,49 @@
+<?php  namespace queue2civicrm\refund;
+
+use wmf_common\TransactionalWmfQueueConsumer;
+use WmfException;
+
+class RefundQueueConsumer extends TransactionalWmfQueueConsumer{
+
+       public function processMessage( $message ) {
+
+               // Sanity checking :)
+               $required_fields = array( "gateway_parent_id", 
"gross_currency", "gross", "date", "gateway",
+                                                                 "type",
+               );
+               foreach( $required_fields as $field_name ) {
+                       if ( !array_key_exists( $field_name, $message ) ) {
+                               $error = "Required field '$field_name' not 
present! Dropping message on floor.";
+                               throw new WmfException( 'CIVI_REQ_FIELD', 
$error );
+                       }
+               }
+
+               $gateway = strtoupper($message[ 'gateway' ]);
+               $parentTxn = $message['gateway_parent_id'];
+               $refundTxn = isset( $message[ 'gateway_refund_id' ] ) ? 
$message[ 'gateway_refund_id' ] : null;
+
+               if ( $message[ 'gross' ] < 0 ) {
+                       $message[ 'gross' ] = abs( $message[ 'gross' ] );
+               }
+
+               if ( $contributions = 
wmf_civicrm_get_contributions_from_gateway_id( $gateway, $parentTxn ) ) {
+                       // Perform the refund!
+                       try {
+                               wmf_civicrm_mark_refund( $contributions[0][ 
'id' ], $message[ 'type' ], true, $message[ 'date' ],
+                                       $refundTxn,
+                                       $message[ 'gross_currency' ],
+                                       $message[ 'gross' ]
+                               );
+
+                               watchdog( 'refund', "$refundTxn: Successfully 
marked as refunded", NULL, WATCHDOG_INFO );
+                       } catch (Exception $ex) {
+                               watchdog( 'refund', "$refundTxn: Could not 
refund due to internal error: " . $ex->getMessage(), NULL, WATCHDOG_ERROR );
+                               throw $ex;
+                       }
+               } else {
+                       watchdog( 'refund', "$refundTxn: Contribution not found 
for this transaction!", NULL, WATCHDOG_ERROR );
+                       throw new WmfException( 'MISSING_PREDECESSOR', "Parent 
not found: $gateway $parentTxn" );
+               }
+       }
+
+}
\ No newline at end of file
diff --git a/sites/all/modules/queue2civicrm/refund/wmf_refund_qc.info 
b/sites/all/modules/queue2civicrm/refund/wmf_refund_qc.info
index 76afea9..af08581 100644
--- a/sites/all/modules/queue2civicrm/refund/wmf_refund_qc.info
+++ b/sites/all/modules/queue2civicrm/refund/wmf_refund_qc.info
@@ -5,3 +5,4 @@
 configure = admin/config/queue2civicrm/refund_qc
 dependencies[] = queue2civicrm
 dependencies[] = civicrm
+files[] = RefundQueueConsumer.php
diff --git a/sites/all/modules/queue2civicrm/refund/wmf_refund_qc.module 
b/sites/all/modules/queue2civicrm/refund/wmf_refund_qc.module
index 24d0953..6cf30b7 100644
--- a/sites/all/modules/queue2civicrm/refund/wmf_refund_qc.module
+++ b/sites/all/modules/queue2civicrm/refund/wmf_refund_qc.module
@@ -1,5 +1,6 @@
 <?php
 
+use queue2civicrm\refund\RefundQueueConsumer;
 /**
  * Implements hook_menu
  */
@@ -93,13 +94,14 @@
 
   watchdog('refund', 'Executing: refund_batch_process');
 
-  $q = queue2civicrm_stomp();
-  $processed = $q->dequeue_loop(
-    variable_get('refund_queue', '/queue/refund'),
-    variable_get('refund_batch', 0),
-    variable_get('refund_batch_time', 0),
-    'refund_import'
-  );
+       $consumer = new RefundQueueConsumer (
+               'refund-new', // TODO: kill all the -new suffixes
+               variable_get('refund_batch_time', 0),
+               variable_get('refund_batch', 0)
+
+       );
+
+       $processed = $consumer->dequeueMessages();
 
   if ($processed > 0) {
     watchdog('refund', 'Successfully processed ' . $processed . ' refund(s).');
@@ -109,51 +111,3 @@
   }
 }
 
-/**
- * @param StompFrame|array $msg
- */
-function refund_import($msg) {
-  if ( is_array( $msg ) ) {
-      $body = $msg;
-  } elseif ( property_exists( $msg, 'body' ) ) {
-      $body = json_decode( $msg->body, TRUE );
-  }
-
-  // Sanity checking :)
-  $required_fields = array( "gateway_parent_id", "gross_currency", "gross", 
"date", "gateway",
-    "type",
-  );
-  foreach( $required_fields as $field_name ) {
-    if ( !array_key_exists( $field_name, $body ) ) {
-      $error = "Required field '$field_name' not present! Dropping message on 
floor.";
-      throw new WmfException( 'CIVI_REQ_FIELD', $error );
-    }
-  }
-
-  $gateway = strtoupper($body['gateway']);
-  $parentTxn = $body['gateway_parent_id'];
-  $refundTxn = isset( $body['gateway_refund_id'] ) ? 
$body['gateway_refund_id'] : null;
-
-  if ( $body['gross'] < 0 ) {
-    $body['gross'] = abs( $body['gross'] );
-  }
-
-  if ( $contributions = wmf_civicrm_get_contributions_from_gateway_id( 
$gateway, $parentTxn ) ) {
-    // Perform the refund!
-    try {
-      wmf_civicrm_mark_refund( $contributions[0]['id'], $body['type'], true, 
$body['date'],
-        $refundTxn,
-        $body['gross_currency'],
-        $body['gross']
-      );
-
-      watchdog('refund', "$refundTxn: Successfully marked as refunded", NULL, 
WATCHDOG_INFO);
-    } catch (Exception $ex) {
-      watchdog('refund', "$refundTxn: Could not refund due to internal error: 
" . $ex->getMessage(), NULL, WATCHDOG_ERROR);
-      throw $ex;
-    }
-  } else {
-    watchdog( 'refund', "$refundTxn: Contribution not found for this 
transaction!", NULL, WATCHDOG_ERROR );
-    throw new WmfException( 'MISSING_PREDECESSOR', "Parent not found: $gateway 
$parentTxn" );
-  }
-}
diff --git 
a/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php 
b/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
index 2078ef1..fb60d25 100644
--- a/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
+++ b/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php
@@ -1,6 +1,7 @@
 <?php
 
 use queue2civicrm\DonationQueueConsumer;
+use queue2civicrm\refund\RefundQueueConsumer;
 use SmashPig\Core\Context;
 use SmashPig\Core\DataStores\PendingDatabase;
 use SmashPig\Tests\SmashPigDatabaseTestConfiguration;
@@ -20,6 +21,12 @@
         */
        protected $queueConsumer;
 
+       /**
+        * @var RefundQueueConsumer
+        */
+       protected $refundConsumer;
+
+
        public function setUp() {
                parent::setUp();
                $config = SmashPigDatabaseTestConfiguration::instance();
@@ -28,16 +35,23 @@
                        'data-store' => array(
                                'donations' => array(
                                        'class' => 'PHPQueue\Backend\PDO',
+                       'constructor-parameters' => array( array(
+                                               'connection_string' => 
'sqlite::memory:'
+                                       ) )
+                               ),
+                               'refund-new' => 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' );
+               $this->refundConsumer = new RefundQueueConsumer( 'refund-new' );
        }
 
        /**
@@ -249,7 +263,7 @@
         $contributions = wmf_civicrm_get_contributions_from_gateway_id( 
$donation_message->getGateway(), $donation_message->getGatewayTxnId() );
         $this->assertEquals( 1, count( $contributions ) );
 
-        refund_import( $refund_message );
+               $this->refundConsumer->processMessage( 
$refund_message->getBody() );
         $contributions = wmf_civicrm_get_contributions_from_gateway_id( 
$refund_message->getGateway(), $refund_message->getGatewayTxnId() );
         $this->assertEquals( 1, count( $contributions ) );
     }
@@ -261,7 +275,7 @@
     public function testRefundNoPredecessor() {
         $refund_message = new RefundMessage();
 
-        refund_import( $refund_message );
+               $this->refundConsumer->processMessage( 
$refund_message->getBody() );
     }
 
     /**
@@ -289,7 +303,7 @@
         $contributions = wmf_civicrm_get_contributions_from_gateway_id( 
$donation_message->getGateway(), $donation_message->getGatewayTxnId() );
         $this->assertEquals( 1, count( $contributions ) );
 
-        refund_import( $refund_message );
+               $this->refundConsumer->processMessage( 
$refund_message->getBody() );
         $contributions = $this->callAPISuccess('Contribution', 'get', 
array('contact_id' => $contributions[0]['contact_id'], 'sequential' => 1));
         $this->assertEquals(2, count($contributions['values']));
         $this->assertEquals('Chargeback', 
CRM_Contribute_PseudoConstant::contributionStatus($contributions['values'][0]['contribution_status_id']));

-- 
To view, visit https://gerrit.wikimedia.org/r/309603
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0417025205199e7def08c292da6f04d32c4d6c4c
Gerrit-PatchSet: 11
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: XenoRyet <dkozlow...@wikimedia.org>
Gerrit-Reviewer: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org>
Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org>
Gerrit-Reviewer: XenoRyet <dkozlow...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to