Ejegg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312442

Change subject: Stop mirroring to stomp from audit processors
......................................................................

Stop mirroring to stomp from audit processors

Not sure if those try/catch blocks are right in the GC processor

Change-Id: I9f15d622558edd87dc9d74b1dcebd576f66cea08
---
M sites/all/modules/globalcollect_audit/globalcollect_audit.module
M sites/all/modules/wmf_audit/wmf_audit.module
2 files changed, 51 insertions(+), 99 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/42/312442/1

diff --git a/sites/all/modules/globalcollect_audit/globalcollect_audit.module 
b/sites/all/modules/globalcollect_audit/globalcollect_audit.module
index 21bfea6..2cb3143 100644
--- a/sites/all/modules/globalcollect_audit/globalcollect_audit.module
+++ b/sites/all/modules/globalcollect_audit/globalcollect_audit.module
@@ -1,6 +1,7 @@
 <?php
 use SmashPig\Core\Configuration;
 use SmashPig\Core\ConfigurationKeyException;
+use SmashPig\Core\SmashPigException;
 
 define( 'GC_AUDIT_WR1_PARSER_DIR', '/usr/local/src/Wr1Parser/' );
 define( 'GC_AUDIT_WR1_FILES_DIR', '/usr/local/src/Wr1_files/' );
@@ -68,7 +69,7 @@
   );
   $form['globalcollect_audit_test_mode']  = array(
     '#type' => 'checkbox',
-    '#title' => t( 'When this box is checked, no stomp messages will be sent.' 
),
+    '#title' => t( 'When this box is checked, no queue messages will be sent.' 
),
     '#required' => FALSE,
     '#default_value' => variable_get( 'globalcollect_audit_test_mode', 
GC_AUDIT_TEST_MODE ),
   );
@@ -334,7 +335,7 @@
                        }
 
                        //This isn't going to work unless you're connecting to 
a database that has the row you're looking for. 
-                       $missing_txn_message = 
globalcollect_audit_format_data_for_stomp( $data, $logdata['donor_data'], 
$logdata['contribution_id'] );
+                       $missing_txn_message = 
globalcollect_audit_format_data_for_queue( $data, $logdata['donor_data'], 
$logdata['contribution_id'] );
                        if ( is_null( $missing_txn_message ) ){
                                //log this out in a list of troubled 
transactions. 
                                $info = array(
@@ -352,14 +353,14 @@
                                $local_found_ids[] = $order_id;
                                globalcollect_audit_echo('!');
                        } else {
-                               if ( globalcollect_audit_send_queue_message( 
'donations', $missing_txn_message ) ){
-                                       watchdog('globalcollect_audit', 
__FUNCTION__ . ': Message sent to stomp successfully: ' . print_r( 
$missing_txn_message, true ), array(), WATCHDOG_INFO);
+                               try {
+                                       globalcollect_audit_send_queue_message( 
'donations', $missing_txn_message );
+                                       watchdog('globalcollect_audit', 
__FUNCTION__ . ': Message sent to queue successfully: ' . print_r( 
$missing_txn_message, true ), array(), WATCHDOG_INFO);
                                        $local_found_ids[] = $order_id;
                                        globalcollect_audit_echo('!');
-                               } else {
-                                       $wd_message = __FUNCTION__ . ': Sending 
message to stomp failed: ' . print_r( $missing_txn_message, true );
-                                       $drush_message = "Failed sending STOMP 
message to queue.";
-                                       globalcollect_audit_log_error( 
$wd_message, "STOMP_BAD_SEND", $drush_message );
+                               } catch( SmashPigException $ex ) {
+                                       $wd_message = __FUNCTION__ . ': Sending 
message to queue failed: ' . print_r( $missing_txn_message, true );
+                                       globalcollect_audit_log_error( 
$wd_message, "QUEUE_BAD_SEND", $ex->getMessage() );
                                        return;
                                }
                        }
@@ -388,21 +389,21 @@
        if ( $make_missing && count( $missing ) ){
                //make all the remaining missing transactions with data 
defaults. 
                foreach ( $missing as $order_id => $data ) {
-                       $missing_txn_message = 
globalcollect_audit_format_data_for_stomp( $data );
+                       $missing_txn_message = 
globalcollect_audit_format_data_for_queue( $data );
                        
                        //but then we have to send the transaction...
                        if ( $test_mode ){
                                $local_built_ids[] = $order_id;
                                globalcollect_audit_echo('!');
                        } else {
-                               if ( globalcollect_audit_send_queue_message( 
'donations', $missing_txn_message ) ){
-                                       watchdog('globalcollect_audit', 
__FUNCTION__ . ': Message sent to stomp successfully: ' . print_r( 
$missing_txn_message, true ), array(), WATCHDOG_INFO);
+                               try{
+                                       globalcollect_audit_send_queue_message( 
'donations', $missing_txn_message );
+                                       watchdog('globalcollect_audit', 
__FUNCTION__ . ': Message sent to queue successfully: ' . print_r( 
$missing_txn_message, true ), array(), WATCHDOG_INFO);
                                        $local_built_ids[] = $order_id;
                                        globalcollect_audit_echo('!');
-                               } else {
-                                       $wd_message = __FUNCTION__ . ': Sending 
message to stomp failed: ' . print_r( $missing_txn_message, true );
-                                       $drush_message = "Failed sending STOMP 
message to queue.";
-                                       globalcollect_audit_log_error( 
$wd_message, "STOMP_BAD_SEND", $drush_message );
+                               } catch( SmashPigException $ex ) {
+                                       $wd_message = __FUNCTION__ . ': Sending 
message to queue failed: ' . print_r( $missing_txn_message, true );
+                                       globalcollect_audit_log_error( 
$wd_message, "QUEUE_BAD_SEND", $ex->getMessage() );
                                        return;
                                }
                        }
@@ -511,7 +512,7 @@
 }
 
 
-function globalcollect_audit_format_data_for_stomp( $wr1, $donor_data = null, 
$contribution_tracking_id = null ){
+function globalcollect_audit_format_data_for_queue( $wr1, $donor_data = null, 
$contribution_tracking_id = null ){
        $fake_db = variable_get( 'globalcollect_audit_fake_db', 
GC_AUDIT_FAKE_DB );
        $make_missing = variable_get( 'globalcollect_audit_make_missing', false 
);
        //you should probably make sure the data between the two sources match 
up before we do anything else
@@ -627,7 +628,7 @@
        }
        
        //start it off with the stuff that's always there...
-       $stomp_data = array(
+       $queue_data = array(
                'contribution_tracking_id' => $contribution_tracking_id,
                'gateway' => 'globalcollect',
                'gross' => $unstaged_amount,
@@ -635,20 +636,20 @@
        );
        
        if ( $payment_submethod ){
-               $stomp_data['payment_submethod'] = $payment_submethod;
+               $queue_data['payment_submethod'] = $payment_submethod;
        }
        
        if( $recurring ){
-               $stomp_data['recurring'] = 1;
+               $queue_data['recurring'] = 1;
        }
        
        if ( $make_missing ){
-               $stomp_data['audit_hole'] = true;
+               $queue_data['audit_hole'] = true;
        }
        
        
        //now, we have three sources for this mess: $wr1, $donor_data, and 
$contribution_tracking. Map 'em.
-       $stomp_field_map = array(
+       $queue_field_map = array(
                'optout' => array( 'contribution_tracking', 'optout' ),
                'anonymous' => array( 'contribution_tracking', 'anonymous' ),
                'comment' => array( 'contribution_tracking', 'note' ), //I 
think.
@@ -673,21 +674,21 @@
                'date' => array( 'contribution_tracking', 'ts' ), 
//double-check how the dates work
        );
        
-       foreach ( $stomp_field_map as $key => $location ){
+       foreach ( $queue_field_map as $key => $location ){
                if( is_array( $location ) ){
                        $source = $location[0];
                        $source_key = $location[1];
                        if ( is_array( ${$source} ) && array_key_exists( 
$source_key, ${$source} ) ){
-                               $stomp_data[$key] = ${$source}[$source_key];
+                               $queue_data[$key] = ${$source}[$source_key];
                        } else {
-                               $stomp_data[$key] = '';
+                               $queue_data[$key] = '';
                        }
                } else {
-                       $stomp_data[$location] = '';
+                       $queue_data[$location] = '';
                }
        }
        
-       return $stomp_data;
+       return $queue_data;
 
 
 }
@@ -763,7 +764,7 @@
 
        $return = array(
                //don't care about the actual values here: They're not saved 
downstream. 
-               //It's just so we can eyeball where the stomp message came 
from, really.
+               //It's just so we can eyeball where the queue message came 
from, really.
                'utm_source' => 'gc_wr1',
                'utm_medium' => 'gc_wr1',
                'utm_campaign' => 'gc_wr1',
@@ -1058,18 +1059,18 @@
 }
 
 /**
- * Tries to intelligently select the next most likely log to knock off the 
- * majority of the remaining missing transactions, which drastically cuts down 
- * on runtime. 
+ * Tries to intelligently select the next most likely log to knock off the
+ * majority of the remaining missing transactions, which drastically cuts down
+ * on runtime.
  * @staticvar array $tried The dates we have tried
- * @staticvar string $available The groomed files that are currently available 
- * in the logs directory. 
+ * @staticvar string $available The groomed files that are currently available
+ * in the logs directory.
  * @param array $missing Parsed missing transaction data form the wr1 files
- * @param array $counts Array of log data we have found, indexed by the actual 
+ * @return string
+ * @internal param array $counts Array of log data we have found, indexed by 
the actual
  * date it was initiated (logdate - 1)
- * @return type 
  */
-function globalcollect_audit_get_next_log( $missing, $counts ){
+function globalcollect_audit_get_next_log( $missing ){
        static $tried = array();
        static $available = null;
        if ( is_null( $available ) ){
@@ -1392,9 +1393,9 @@
 
 /**
  * Logs the errors we get in a consistent way
- * @param type $watchdog_message
- * @param type $drush_code
- * @param type $drush_message 
+ * @param string $watchdog_message
+ * @param string $drush_code
+ * @param string $drush_message
  */
 function globalcollect_audit_log_error( $watchdog_message, $drush_code, 
$drush_message = null ){
        global $gc_audit_errors;
@@ -2009,34 +2010,20 @@
 }
 
 function globalcollect_audit_send_queue_message( $queueId, $body ) {
-    static $q;
-
-    if ( !$q ) {
-        $q = new Queue( queue2civicrm_stomp_url() );
-    }
 
     // FIXME: register the queue mapping somewhere sane
     if ( $queueId === 'donations' ) {
-        $queuePath = variable_get( 'queue2civicrm_subscription', 
'/queue/donations' );
                $configKey = 'data-store/donations';
     } elseif ( $queueId === 'refund' ) {
-        $queuePath = variable_get( 'refund_queue', '/queue/refund' );
                $configKey = 'data-store/refund-new';
     } else {
         throw new Exception( "What kind of a queue is this??: {$queueId}" );
     }
 
-    $headers = array();
-    wmf_common_set_message_source( $headers, 'audit', 'GlobalCollect WR1 
Auditor' );
        wmf_common_set_message_source( $body, 'audit', 'GlobalCollect WR1 
Auditor' );
 
-       try {
-               $newQueue = Configuration::getDefaultConfig()->object( 
$configKey, true );
-               $newQueue->push( $body );
-       } catch ( ConfigurationKeyException $ex ) {
-               // do nothing
-       }
-    return $q->enqueue( json_encode( $body ), $headers, $queuePath );
+       $newQueue = Configuration::getDefaultConfig()->object( $configKey, true 
);
+       $newQueue->push( $body );
 }
 
 /**
diff --git a/sites/all/modules/wmf_audit/wmf_audit.module 
b/sites/all/modules/wmf_audit/wmf_audit.module
index 288401c..b6313c4 100644
--- a/sites/all/modules/wmf_audit/wmf_audit.module
+++ b/sites/all/modules/wmf_audit/wmf_audit.module
@@ -370,7 +370,7 @@
 
 /**
  * Sends a completed transaction to... somewhere.
- * The default is to send this thing to an appropriate stomp queue for its 
type.
+ * The default is to send this thing to an appropriate queue for its type.
  * Other possibilities are to echo the complete message (test mode).
  *
  * @param array $record An array representing the complete data we want to save
@@ -393,61 +393,26 @@
 
 /**
  * Send the message in $body to appropriate message queues.
- * @staticvar array $types Types of transaction we know about, that probably 
all
- * have different queues.
  * @param array $body An array representing the transaction we're trying to
  * send.
  * @param string $type The type of transaction. 'main'|'negative'|'recurring'.
  * @return boolean I think this one is always true, whether or not it worked.
- * Standard for the stomp libraries, but still lame.
  * @throws Exception
  */
 function wmf_audit_send_queue_message( $body, $type ) {
-  static $types = array();
+  $configKeys = array(
+    'main' => 'data-store/donations',
+    'negative' => 'data-store/refund-new', // FIXME: almost ready to do away 
with -new
+    'recurring' => 'data-store/recurring-new',
+  );
 
-  $q = queue2civicrm_stomp();
-
-  //@FIXME: This is actually more for the queue consumer modules, but: Make a
-  //goshdarn get function for each of these queue variables so I don't have to
-  //steal the variable_get line from the .module files. If we change that over
-  //there, this breaks.
-  if (empty($types)) {
-    $types = array(
-      'main' => variable_get('queue2civicrm_subscription', '/queue/donations'),
-      'negative' => variable_get('refund_queue', '/queue/refund_test'),
-      'recurring' => variable_get('recurring_subscription', 
'/queue/donations_recurring'),
-    );
-  }
-
-  if (!array_key_exists($type, $types)) {
+  if (!array_key_exists($type, $configKeys)) {
     throw new Exception(__FUNCTION__ . ": Unhandled message type '$type'");
   }
 
-  $headers = array(
-    'gateway' => $body['gateway'],
-  );
-
-  if ($type != 'negative') {
-    $headers['correlation-id'] = $body['gateway'] . '-' . 
$body['gateway_txn_id'];
-    $headers['php-message-class'] = 
'SmashPig\CrmLink\Messages\DonationInterfaceMessage';
-    $headers['payment_method'] = $body['payment_method'];
-  }
-
-  wmf_common_set_message_source($headers, 'audit', 
wmf_audit_runtime_options('submod_prefix') . ' Recon Auditor');
   wmf_common_set_message_source($body, 'audit', 
wmf_audit_runtime_options('submod_prefix') . ' Recon Auditor');
-
-  $configKeys = array(
-    'main' => 'data-store/donations',
-    'negative' => 'data-store/refund-new',
-    'recurring' => 'data-store/recurring-new',
+  $newQueue = Configuration::getDefaultConfig()->object(
+    $configKeys[$type]
   );
-  try{
-    $newQueue = Configuration::getDefaultConfig()->object(
-      $configKeys[$type]
-    );
-    $newQueue->push( $body );
-  } catch ( ConfigurationKeyException $ex ) {
-    // do nothing
-  }
-  return $q->enqueue(json_encode($body), $headers, $types[$type]);
+  $newQueue->push( $body );
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9f15d622558edd87dc9d74b1dcebd576f66cea08
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>

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

Reply via email to