https://www.mediawiki.org/wiki/Special:Code/MediaWiki/103385
Revision: 103385
Author: khorn
Date: 2011-11-16 21:19:56 +0000 (Wed, 16 Nov 2011)
Log Message:
-----------
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
trunk/extensions/DonationInterface/extras/custom_filters/filters/functions/functions.body.php
trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php
trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php
trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php
trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php
Modified:
trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php
===================================================================
---
trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php
2011-11-16 21:04:41 UTC (rev 103384)
+++
trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php
2011-11-16 21:19:56 UTC (rev 103385)
@@ -41,7 +41,6 @@
$this->risk_score = 0;
if ( $this->risk_score > 100 )
$this->risk_score = 100;
-// error_log("Risk score: " . $this->risk_score );
foreach ( $this->action_ranges as $action => $range ) {
if ( $this->risk_score >= $range[0] &&
$this->risk_score <= $range[1] ) {
return $action;
@@ -73,7 +72,7 @@
}
static function singleton( &$gateway_adapter ) {
- if ( !self::$instance ) {
+ if ( !self::$instance || $gateway_adapter->isBatchProcessor() )
{
self::$instance = new self( $gateway_adapter );
}
return self::$instance;
Modified:
trunk/extensions/DonationInterface/extras/custom_filters/filters/functions/functions.body.php
===================================================================
---
trunk/extensions/DonationInterface/extras/custom_filters/filters/functions/functions.body.php
2011-11-16 21:04:41 UTC (rev 103384)
+++
trunk/extensions/DonationInterface/extras/custom_filters/filters/functions/functions.body.php
2011-11-16 21:19:56 UTC (rev 103385)
@@ -54,7 +54,7 @@
}
static function singleton( &$gateway_adapter, &$custom_filter_object ) {
- if ( !self::$instance ) {
+ if ( !self::$instance || $gateway_adapter->isBatchProcessor() )
{
self::$instance = new self( $gateway_adapter,
$custom_filter_object );
}
return self::$instance;
Modified:
trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php
===================================================================
---
trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php
2011-11-16 21:04:41 UTC (rev 103384)
+++
trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php
2011-11-16 21:19:56 UTC (rev 103385)
@@ -37,7 +37,7 @@
}
static function singleton( &$gateway_adapter ) {
- if ( !self::$instance ) {
+ if ( !self::$instance || $gateway_adapter->isBatchProcessor() )
{
self::$instance = new self( $gateway_adapter );
}
return self::$instance;
Modified:
trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php
===================================================================
---
trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php
2011-11-16 21:04:41 UTC (rev 103384)
+++
trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php
2011-11-16 21:19:56 UTC (rev 103385)
@@ -56,7 +56,7 @@
}
static function singleton( &$gateway_adapter, &$custom_filter_object ) {
- if ( !self::$instance ) {
+ if ( !self::$instance || $gateway_adapter->isBatchProcessor() )
{
self::$instance = new self( $gateway_adapter,
$custom_filter_object );
}
return self::$instance;
Modified:
trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php
===================================================================
---
trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php
2011-11-16 21:04:41 UTC (rev 103384)
+++
trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php
2011-11-16 21:19:56 UTC (rev 103385)
@@ -56,7 +56,7 @@
}
static function singleton( &$gateway_adapter, &$custom_filter_object ) {
- if ( !self::$instance ) {
+ if ( !self::$instance || $gateway_adapter->isBatchProcessor() )
{
self::$instance = new self( $gateway_adapter,
$custom_filter_object );
}
return self::$instance;
Modified: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
===================================================================
--- trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
2011-11-16 21:04:41 UTC (rev 103384)
+++ trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
2011-11-16 21:19:56 UTC (rev 103385)
@@ -173,6 +173,7 @@
protected $current_transaction;
protected $action;
public $debugarray;
+ protected $batch = false;
//ALL OF THESE need to be redefined in the children. Much voodoo
depends on the accuracy of these constants.
const GATEWAY_NAME = 'Donation Gateway';
@@ -1989,5 +1990,18 @@
public function hasDonorDataInSession( $key = false, $value= '' ){
return $this->dataObj->hasDonorDataInSession( $key, $value );
}
+
+ /**
+ * Lets the outside world (particularly hooks that accumulate points
scores)
+ * know if we are a batch processor.
+ * @return type
+ */
+ public function isBatchProcessor(){
+ if (!property_exists($this, 'batch')){
+ return false;
+ } else {
+ return $this->batch;
+ }
+ }
}
\ No newline at end of file
Modified:
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
===================================================================
---
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
2011-11-16 21:04:41 UTC (rev 103384)
+++
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
2011-11-16 21:19:56 UTC (rev 103385)
@@ -1,6 +1,7 @@
<?php
class GlobalCollectOrphanAdapter extends GlobalCollectAdapter {
+
public function unstage_data( $data = array(), $final = true ){
$unstaged = array();
foreach ( $data as $key=>$val ){
@@ -27,7 +28,8 @@
}
public function loadDataAndReInit( $data ){
-
+ $this->batch = true; //or the hooks will accumulate badness.
+
$this->dataObj = new DonationData( get_called_class(), false,
$data );
$this->raw_data = $this->dataObj->getData();
@@ -58,4 +60,33 @@
$this->staged_data['i_order_id'] = $order_id;
}
+ public function do_transaction($transaction){
+ switch ($transaction){
+ case 'SET_PAYMENT':
+ case 'CANCEL_PAYMENT':
+
self::log($this->getData_Raw('contribution_tracking_id') . ": CVV: " .
$this->getData_Raw('cvv_result') . ": AVS: " .
$this->getData_Raw('avs_result'));
+ //and then go on, unless you're testing, in
which case:
+ //return "NOPE";
+ //break;
+ default:
+ return parent::do_transaction($transaction);
+ break;
+ }
+ }
+
+ public static function log( $msg, $log_level = LOG_INFO, $nothing =
null ) {
+ $identifier = 'orphans:' . self::getIdentifier() .
"_gateway_trxn";
+
+ // if we're not using the syslog facility, use wfDebugLog
+ if ( !self::getGlobal( 'UseSyslog' ) ) {
+ wfDebugLog( $identifier, $msg );
+ return;
+ }
+
+ // otherwise, use syslogging
+ openlog( $identifier, LOG_ODELAY, LOG_SYSLOG );
+ syslog( $log_level, $msg );
+ closelog();
+ }
+
}
\ No newline at end of file
Modified:
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php
===================================================================
---
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php
2011-11-16 21:04:41 UTC (rev 103384)
+++
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php
2011-11-16 21:19:56 UTC (rev 103385)
@@ -25,7 +25,8 @@
foreach ($order_ids as $id){
$this->order_ids[$id] = $id; //easier to unset this
way.
}
- echo "Order ID count: " . count($this->order_ids) . "\n";
+ $outstanding_count = count($this->order_ids);
+ echo "Order ID count: " . $outstanding_count . "\n";
$files = $this->getAllLogFileNames();
foreach ($files as $file){
@@ -56,34 +57,26 @@
$payments[$key]['unstaged']['i_order_id'] =
$payments[$key]['unstaged']['order_id'];
$payments[$key]['unstaged']['card_num'] = '';
}
-
- //foreach dealie we have data for... do it.
- //probably damage the constructor, and do all the regular
business on a data load.
- die(); //Not actually letting this work for another round or
so.
- //Note to Self:
- //Before you actually get rid of that die there and fire this
thing off, make sure that:
- // * Your STOMP server is pointing to the real STOMP server
- // ...and the same with the queues.
- // * Your AVS/CVV rules make The Sense.
+
// ADDITIONAL: log out what you did here, to... somewhere.
// Preferably *before* you rewrite the Order ID file.
//we may need to unset some hooks out here. Like... recaptcha.
Makes no sense.
- error_log("\n\n\n");
foreach($payments as $payment_data){
$adapter->loadDataAndReInit($payment_data['unstaged']);
$results =
$adapter->do_transaction('Confirm_CreditCard');
if ($results['status'] == true){
- echo "\nWe were supposed to " .
$results['action'] . "\n";
+ $adapter->log(
$payment_data['unstaged']['contribution_tracking_id'] . ": FINAL: " .
$results['action']);
+
unset($this->order_ids[$payments[$key]['unstaged']['order_id']]);
} else {
- echo "\nProblem Happened! \n";
+ $adapter->log(
$payment_data['unstaged']['contribution_tracking_id'] . ": ERROR: " .
$results['message']);
}
echo $results['message'] . "\n";
}
-
- //$this->rewriteOrderIds();
- //and don't forget to kill the logs we don't care about anymore.
+ if ($outstanding_count != count($this->order_ids)){
+ $this->rewriteOrderIds();
+ }
}
function getAllLogFileNames(){
@@ -113,6 +106,7 @@
}
}
+ $order_ids = $this->order_ids;
foreach ($lines as $line_no=>$line_data){
if (count($orders) >= $this->max_per_execute){
continue;
@@ -121,9 +115,9 @@
$pos2 = strpos($line_data, '</ORDERID>');
if ($pos2 > $pos1){
$tmp = substr($line_data, $pos1, $pos2-$pos1);
- if (isset($this->order_ids[$tmp])){
+ if (isset($order_ids[$tmp])){
$orders[$tmp] = trim($line_data);
- unset($this->order_ids[$tmp]);
+ unset($order_ids[$tmp]);
}
}
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs