r105611 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105610‎ | r105611 | r105612 >
Date:23:38, 8 December 2011
Author:khorn
Status:ok
Tags:
Comment:
Hopefully the last round of edits on the orphan stomp maintenance script.
Modified paths:
  • /trunk/extensions/DonationInterface/activemq_stomp/activemq_stomp.php (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php
@@ -1,15 +1,15 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) {
4 - exit( 1 );
5 -}
 3+//actually, as a maintenance script, this totally is a valid entry point.
 4+
65 //If you want to use this script, you will have to add the following line to LocalSettings.php:
76 //$wgAutoloadClasses['GlobalCollectOrphanAdapter'] = $IP . '/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php';
87
9 -//TODO: Something that is not specific to anybody's install, here.
10 -global $IP;
11 -if ( !isset($IP) ) {
12 - $IP = '../../../../';
 8+$IP = getenv( 'MW_INSTALL_PATH' );
 9+if ( $IP === false ) {
 10+ $IP = dirname( _FILE_ ) . '/../..';
1311 }
 12+
 13+//If you get errors on this next line, set (and export) your MW_INSTALL_PATH var.
1414 require_once( "$IP/maintenance/Maintenance.php" );
1515
1616 class GlobalCollectOrphanRectifier extends Maintenance {
@@ -20,7 +20,6 @@
2121 protected $target_execute_time = 30; //(seconds) - only used by the stomp option.
2222 protected $adapter;
2323
24 -
2524 function execute(){
2625 $func = 'parse_files';
2726 if ( !empty( $_SERVER['argv'][1] ) ){
@@ -49,7 +48,7 @@
5049 }
5150
5251 function orphan_stomp(){
53 -
 52+ echo "Orphan Stomp\n";
5453 $this->removed_message_count = 0;
5554 $this->now = time(); //time at start, thanks very much.
5655
@@ -99,8 +98,17 @@
10099 break;
101100 }
102101 }
103 - echo "\nDone! Final results: \n $am destroyed via antimessage \n $rec rectified orphans \n $err errored out\n";
 102+ $final = "\nDone! Final results: \n";
 103+ $final .= " $am destroyed via antimessage \n";
 104+ $final .= " $rec rectified orphans \n";
 105+ $final .= " $err errored out \n";
 106+ if ( isset( $this->adapter->orphanstats ) ){
 107+ foreach ( $this->adapter->orphanstats as $status => $count ) {
 108+ $final .= " Status $status = $count\n";
 109+ }
 110+ }
104111
 112+ echo $final;
105113 }
106114
107115 function keepGoing(){
@@ -118,20 +126,19 @@
119127 if ( $correlation_id ) {
120128 $bucket[$correlation_id] = "'$correlation_id'"; //avoiding duplicates.
121129 $this->handled_ids[$correlation_id] = 'antimessage';
122 - echo "Added $correlation_id to the ack bucket : Total bucket count = " . count( $bucket );
123130 }
124131 if ( count( $bucket ) && ( count( $bucket ) >= $count || $ackNow ) ){
125132 //ack now.
126 - echo 'Acking ' . count( $bucket ) . ' bucket messages.';
 133+ echo 'Acking ' . count( $bucket ) . " bucket messages.\n";
127134 $selector = 'JMSCorrelationID IN (' . implode( ", ", $bucket ) . ')';
128135 $ackMe = stompFetchMessages( 'cc-limbo', $selector, $count * 100 ); //This is outrageously high, but I just want to be reasonably sure we get all the matches.
129136 $retrieved_count = count( $ackMe );
130137 if ( $retrieved_count ){
131138 stompAckMessages( $ackMe );
132139 $this->removed_message_count += $retrieved_count;
133 - echo "Done acking $retrieved_count messages. ";
 140+ echo "Done acking $retrieved_count messages. \n";
134141 } else {
135 - echo "Oh noes! No messages to ack for some reason...";
 142+ echo "Oh noes! No messages retrieved for $selector...\n";
136143 }
137144 $bucket = array();
138145 }
@@ -149,7 +156,7 @@
150157 if (array_key_exists('correlation-id', $message->headers)) {
151158 $this->addStompCorrelationIDToAckBucket( $message->headers['correlation-id'] );
152159 } else {
153 - echo 'The STOMP message ' . $message->headers['message-id'] . ' has no correlation ID!';
 160+ echo 'The STOMP message ' . $message->headers['message-id'] . " has no correlation ID!\n";
154161 }
155162 }
156163 $antimessages = stompFetchMessages( 'cc-limbo', $selector, 1000 );
@@ -181,8 +188,10 @@
182189 $order_id = $order_id[1];
183190 $decoded['order_id'] = $order_id;
184191 $decoded['i_order_id'] = $order_id;
 192+ $decoded = unCreateQueueMessage($decoded);
 193+ $decoded['card_num'] = '';
185194 $orphans[$correlation_id] = $decoded;
186 - echo "\nFound an orphan! $correlation_id";
 195+ echo "Found an orphan! $correlation_id \n";
187196 }
188197 }
189198 }
@@ -200,7 +209,7 @@
201210 $this->order_ids[$id] = $id; //easier to unset this way.
202211 }
203212 $outstanding_count = count( $this->order_ids );
204 - echo "Order ID count: " . $outstanding_count . "\n";
 213+ echo "Order ID count: $outstanding_count \n";
205214
206215 $files = $this->getAllLogFileNames();
207216 $payments = array();
@@ -277,7 +286,7 @@
278287 * @return boolean True if the orphan has been rectified, false if not.
279288 */
280289 function rectifyOrphan( $data, $query_contribution_tracking = true ){
281 - echo "\nRectifying Orphan " . $data['order_id'];
 290+ echo 'Rectifying Orphan ' . $data['order_id'] . "\n";
282291 $rectified = false;
283292
284293 $this->adapter->loadDataAndReInit( $data, $query_contribution_tracking );
Index: trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
@@ -156,7 +156,7 @@
157157 $msg .= "$key = $val ";
158158 }
159159 $this->log( "$ctid: Found UTM Data. $msg" );
160 - echo $msg;
 160+ echo "$msg\n";
161161 return $data;
162162 }
163163 }
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
@@ -1123,8 +1123,9 @@
11241124 }
11251125 }
11261126 }
1127 -
 1127+ $gotCVV = false;
11281128 if ( count( $addme ) ){
 1129+ $gotCVV = true;
11291130 $this->addData( $addme );
11301131 $this->staged_data['order_id'] = $this->staged_data['i_order_id'];
11311132 $logmsg = $this->getData_Raw( 'contribution_tracking_id' ) . ': ';
@@ -1133,10 +1134,7 @@
11341135 self::log( $logmsg );
11351136 $this->runPreProcessHooks();
11361137 $status_result['action'] = $this->getValidationAction();
1137 - } else {
1138 - $problemflag = true; //nothing to be done.
1139 - $problemmessage = "Unable to retrieve orphan cvv/avs results (Communication problem?).";
1140 - }
 1138+ }
11411139 }
11421140
11431141 //we filtered
@@ -1152,6 +1150,20 @@
11531151 $order_status_results = $this->getTransactionWMFStatus();
11541152 $txn_data = $this->getTransactionData();
11551153 $original_status_code = isset( $txn_data['STATUSID']) ? $txn_data['STATUSID'] : 'NOT SET';
 1154+ if ( $is_orphan ){
 1155+ //save stats.
 1156+ if (!isset($this->orphanstats) || !isset( $this->orphanstats[$original_status_code] ) ){
 1157+ $this->orphanstats[$original_status_code] = 0;
 1158+ } else {
 1159+ $this->orphanstats[$original_status_code] += 1;
 1160+ }
 1161+
 1162+ if ( $original_status_code > 70 && !$gotCVV ){
 1163+ $problemflag = true;
 1164+ $problemmessage = "Unable to retrieve orphan cvv/avs results (Communication problem?).";
 1165+ }
 1166+
 1167+ }
11561168 if (!$order_status_results){
11571169 $problemflag = true;
11581170 $problemmessage = "We don't have a Transaction WMF Status after doing a GET_ORDERSTATUS.";
Index: trunk/extensions/DonationInterface/activemq_stomp/activemq_stomp.php
@@ -188,7 +188,7 @@
189189 */
190190 function createQueueMessage( $transaction ) {
191191 // specifically designed to match the CiviCRM API that will handle it
192 - // edit this array to include/ignore transaction data sent to the server
 192+ // edit this array to include/ignore transaction data sent to the server
193193 $message = array(
194194 'contribution_tracking_id' => $transaction['contribution_tracking_id'],
195195 'optout' => $transaction['optout'],
@@ -236,6 +236,42 @@
237237 return $message;
238238 }
239239
 240+
 241+function unCreateQueueMessage( $transaction ) {
 242+ // For now, this function assumes that we have a complete queue message.
 243+ // TODO: Something more robust and programmatic, as time allows. This whole file is just terrible.
 244+
 245+ $rekey = array(
 246+ 'first_name' => 'fname',
 247+ 'middle_name' => 'mname',
 248+ 'last_name' => 'lname',
 249+ 'street_address' => 'street',
 250+ 'state_province' => 'state',
 251+ 'postal_code' => 'zip',
 252+ 'first_name_2' => 'fname2',
 253+ 'last_name_2' => 'lname2',
 254+ 'street_address_2' => 'street2',
 255+ 'city_2' => 'city2',
 256+ 'state_province_2' => 'state2',
 257+ 'postal_code_2' => 'zip2',
 258+// 'currency' => 'currency_code',
 259+ 'original_currency' => 'currency_code',
 260+ 'original_gross' => 'amount',
 261+// 'gross' => 'amount',
 262+// 'net' => 'amount',
 263+ );
 264+
 265+ foreach ( $rekey as $stomp => $di ){
 266+ if ( isset( $transaction[$stomp] ) ){
 267+ $transaction[$di] = $transaction[$stomp];
 268+ unset($transaction[$stomp]);
 269+ };
 270+ }
 271+
 272+ return $transaction;
 273+}
 274+
 275+
240276 /**
241277 * Fetches all the messages in a queue that match the supplies selector.
242278 * Limiting to a completely arbitrary 50, just in case something goes amiss somewhere.

Follow-up revisions

RevisionCommit summaryAuthorDate
r105620MFT r104539, r105534, r105584, r105593, r105594, r105600, r105611awjrichards23:56, 8 December 2011

Status & tagging log