r103385 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103384‎ | r103385 | r103386 >
Date:21:19, 16 November 2011
Author:khorn
Status:ok
Tags:
Comment:
GlobalCollect command-line orphan rectifier: As near as I can tell, the first pass is finished.
Fixes this round: Adds a way for us to be able to tell if an adapter is expecting to be able to do batch processing or not. If it is, the fraud hooks will re-init themselves every time they are called, so fraud scores don't accumulate over multiple transactions.
Overloads do_transaction in the orphan adapter, so we can do some special logging for orphans, and have a convenient place to damage the communication just prior to finalizing the transaction.
Will now only remove order ids from the search list on completion if they were finalized.
Modified paths:
  • /trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/filters/functions/functions.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_common/gateway.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/extras/custom_filters/custom_filters.body.php
@@ -41,7 +41,6 @@
4242 $this->risk_score = 0;
4343 if ( $this->risk_score > 100 )
4444 $this->risk_score = 100;
45 -// error_log("Risk score: " . $this->risk_score );
4645 foreach ( $this->action_ranges as $action => $range ) {
4746 if ( $this->risk_score >= $range[0] && $this->risk_score <= $range[1] ) {
4847 return $action;
@@ -73,7 +72,7 @@
7473 }
7574
7675 static function singleton( &$gateway_adapter ) {
77 - if ( !self::$instance ) {
 76+ if ( !self::$instance || $gateway_adapter->isBatchProcessor() ) {
7877 self::$instance = new self( $gateway_adapter );
7978 }
8079 return self::$instance;
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php
@@ -56,7 +56,7 @@
5757 }
5858
5959 static function singleton( &$gateway_adapter, &$custom_filter_object ) {
60 - if ( !self::$instance ) {
 60+ if ( !self::$instance || $gateway_adapter->isBatchProcessor() ) {
6161 self::$instance = new self( $gateway_adapter, $custom_filter_object );
6262 }
6363 return self::$instance;
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php
@@ -37,7 +37,7 @@
3838 }
3939
4040 static function singleton( &$gateway_adapter ) {
41 - if ( !self::$instance ) {
 41+ if ( !self::$instance || $gateway_adapter->isBatchProcessor() ) {
4242 self::$instance = new self( $gateway_adapter );
4343 }
4444 return self::$instance;
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/functions/functions.body.php
@@ -54,7 +54,7 @@
5555 }
5656
5757 static function singleton( &$gateway_adapter, &$custom_filter_object ) {
58 - if ( !self::$instance ) {
 58+ if ( !self::$instance || $gateway_adapter->isBatchProcessor() ) {
5959 self::$instance = new self( $gateway_adapter, $custom_filter_object );
6060 }
6161 return self::$instance;
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php
@@ -56,7 +56,7 @@
5757 }
5858
5959 static function singleton( &$gateway_adapter, &$custom_filter_object ) {
60 - if ( !self::$instance ) {
 60+ if ( !self::$instance || $gateway_adapter->isBatchProcessor() ) {
6161 self::$instance = new self( $gateway_adapter, $custom_filter_object );
6262 }
6363 return self::$instance;
Index: trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php
@@ -25,7 +25,8 @@
2626 foreach ($order_ids as $id){
2727 $this->order_ids[$id] = $id; //easier to unset this way.
2828 }
29 - echo "Order ID count: " . count($this->order_ids) . "\n";
 29+ $outstanding_count = count($this->order_ids);
 30+ echo "Order ID count: " . $outstanding_count . "\n";
3031
3132 $files = $this->getAllLogFileNames();
3233 foreach ($files as $file){
@@ -56,34 +57,26 @@
5758 $payments[$key]['unstaged']['i_order_id'] = $payments[$key]['unstaged']['order_id'];
5859 $payments[$key]['unstaged']['card_num'] = '';
5960 }
60 -
61 - //foreach dealie we have data for... do it.
62 - //probably damage the constructor, and do all the regular business on a data load.
63 - die(); //Not actually letting this work for another round or so.
64 - //Note to Self:
65 - //Before you actually get rid of that die there and fire this thing off, make sure that:
66 - // * Your STOMP server is pointing to the real STOMP server
67 - // ...and the same with the queues.
68 - // * Your AVS/CVV rules make The Sense.
 61+
6962 // ADDITIONAL: log out what you did here, to... somewhere.
7063 // Preferably *before* you rewrite the Order ID file.
7164
7265 //we may need to unset some hooks out here. Like... recaptcha. Makes no sense.
73 - error_log("\n\n\n");
7466 foreach($payments as $payment_data){
7567 $adapter->loadDataAndReInit($payment_data['unstaged']);
7668 $results = $adapter->do_transaction('Confirm_CreditCard');
7769 if ($results['status'] == true){
78 - echo "\nWe were supposed to " . $results['action'] . "\n";
 70+ $adapter->log( $payment_data['unstaged']['contribution_tracking_id'] . ": FINAL: " . $results['action']);
 71+ unset($this->order_ids[$payments[$key]['unstaged']['order_id']]);
7972 } else {
80 - echo "\nProblem Happened! \n";
 73+ $adapter->log( $payment_data['unstaged']['contribution_tracking_id'] . ": ERROR: " . $results['message']);
8174 }
8275 echo $results['message'] . "\n";
8376 }
8477
85 -
86 - //$this->rewriteOrderIds();
87 - //and don't forget to kill the logs we don't care about anymore.
 78+ if ($outstanding_count != count($this->order_ids)){
 79+ $this->rewriteOrderIds();
 80+ }
8881 }
8982
9083 function getAllLogFileNames(){
@@ -113,6 +106,7 @@
114107 }
115108 }
116109
 110+ $order_ids = $this->order_ids;
117111 foreach ($lines as $line_no=>$line_data){
118112 if (count($orders) >= $this->max_per_execute){
119113 continue;
@@ -121,9 +115,9 @@
122116 $pos2 = strpos($line_data, '</ORDERID>');
123117 if ($pos2 > $pos1){
124118 $tmp = substr($line_data, $pos1, $pos2-$pos1);
125 - if (isset($this->order_ids[$tmp])){
 119+ if (isset($order_ids[$tmp])){
126120 $orders[$tmp] = trim($line_data);
127 - unset($this->order_ids[$tmp]);
 121+ unset($order_ids[$tmp]);
128122 }
129123 }
130124 }
Index: trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
@@ -1,6 +1,7 @@
22 <?php
33
44 class GlobalCollectOrphanAdapter extends GlobalCollectAdapter {
 5+
56 public function unstage_data( $data = array(), $final = true ){
67 $unstaged = array();
78 foreach ( $data as $key=>$val ){
@@ -27,7 +28,8 @@
2829 }
2930
3031 public function loadDataAndReInit( $data ){
31 -
 32+ $this->batch = true; //or the hooks will accumulate badness.
 33+
3234 $this->dataObj = new DonationData( get_called_class(), false, $data );
3335
3436 $this->raw_data = $this->dataObj->getData();
@@ -58,4 +60,33 @@
5961 $this->staged_data['i_order_id'] = $order_id;
6062 }
6163
 64+ public function do_transaction($transaction){
 65+ switch ($transaction){
 66+ case 'SET_PAYMENT':
 67+ case 'CANCEL_PAYMENT':
 68+ self::log($this->getData_Raw('contribution_tracking_id') . ": CVV: " . $this->getData_Raw('cvv_result') . ": AVS: " . $this->getData_Raw('avs_result'));
 69+ //and then go on, unless you're testing, in which case:
 70+ //return "NOPE";
 71+ //break;
 72+ default:
 73+ return parent::do_transaction($transaction);
 74+ break;
 75+ }
 76+ }
 77+
 78+ public static function log( $msg, $log_level = LOG_INFO, $nothing = null ) {
 79+ $identifier = 'orphans:' . self::getIdentifier() . "_gateway_trxn";
 80+
 81+ // if we're not using the syslog facility, use wfDebugLog
 82+ if ( !self::getGlobal( 'UseSyslog' ) ) {
 83+ wfDebugLog( $identifier, $msg );
 84+ return;
 85+ }
 86+
 87+ // otherwise, use syslogging
 88+ openlog( $identifier, LOG_ODELAY, LOG_SYSLOG );
 89+ syslog( $log_level, $msg );
 90+ closelog();
 91+ }
 92+
6293 }
\ No newline at end of file
Index: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -173,6 +173,7 @@
174174 protected $current_transaction;
175175 protected $action;
176176 public $debugarray;
 177+ protected $batch = false;
177178
178179 //ALL OF THESE need to be redefined in the children. Much voodoo depends on the accuracy of these constants.
179180 const GATEWAY_NAME = 'Donation Gateway';
@@ -1989,5 +1990,18 @@
19901991 public function hasDonorDataInSession( $key = false, $value= '' ){
19911992 return $this->dataObj->hasDonorDataInSession( $key, $value );
19921993 }
 1994+
 1995+ /**
 1996+ * Lets the outside world (particularly hooks that accumulate points scores)
 1997+ * know if we are a batch processor.
 1998+ * @return type
 1999+ */
 2000+ public function isBatchProcessor(){
 2001+ if (!property_exists($this, 'batch')){
 2002+ return false;
 2003+ } else {
 2004+ return $this->batch;
 2005+ }
 2006+ }
19932007
19942008 }
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r103512MFT r103506, r103501, r103499, r103491, r103416, r103385, r103288, r103246, r...khorn21:54, 17 November 2011
r103513MFT r103506, r103501, r103499, r103491, r103416, r103385, r103288, r103246, r...khorn21:57, 17 November 2011

Status & tagging log