r103288 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103287‎ | r103288 | r103289 >
Date:02:18, 16 November 2011
Author:khorn
Status:resolved (Comments)
Tags:
Comment:
GlobalCollect command-line orphan rectifier: Very near completion. (Intentional die while in dev, so nobody does anything silly)
Ran into a problem where not all syslog output is the same: Had to do some special handling for escaped newlines if they are present.
Added a data re-loader to the GC Orphan adapter class, and overloaded addData so it won't doggedly normalize the order_ids on us. Also, the script is now looping on all hits, up to the max count.
Modified paths:
  • /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/orphanlogs (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php
@@ -29,29 +29,19 @@
3030
3131 $files = $this->getAllLogFileNames();
3232 foreach ($files as $file){
33 - $file_array = file($file, FILE_SKIP_EMPTY_LINES);
 33+ $file_array = $this->getLogfileLines( $file );
3434 $payments = $this->findTransactionLines($file_array);
3535 if (count($payments) === 0){
3636 $this->killfiles[] = $file;
 37+ echo print_r($this->killfiles, true);
3738 }
3839 }
3940
4041 $data = array(
41 - 'wheeee' => 'yes'
42 -// 'order_id' => '1052864192',
43 -// 'i_order_id' => '1052864192',
44 -// 'city' => '',
45 -// 'state' => '',
46 -// 'zip' => '',
47 -// 'country' => 'US',
48 -// 'email' => '',
49 -// 'card_num' => '',
50 -
 42+ 'wheeee' => 'yes'
5143 );
5244
53 - $class_name = 'GlobalCollectOrphanAdapter';
54 -
55 - $adapter = new $class_name(array('external_data' => $data));
 45+ $adapter = new GlobalCollectOrphanAdapter(array('external_data' => $data));
5646 $adapter->setCurrentTransaction('INSERT_ORDERWITHPAYMENT');
5747 $var_map = $adapter->defineVarMap();
5848
@@ -62,23 +52,34 @@
6353 $parsed = $adapter->getResponseData($xml);
6454 $payments[$key]['parsed'] = $parsed;
6555 $payments[$key]['unstaged'] = $adapter->unstage_data($parsed);
66 - $payments[$key]['unstaged']['contribution_tracking_id'] = $payments['contribution_tracking_id'];
 56+ $payments[$key]['unstaged']['contribution_tracking_id'] = $payments[$key]['contribution_tracking_id'];
6757 $payments[$key]['unstaged']['i_order_id'] = $payments[$key]['unstaged']['order_id'];
68 - }
69 - //setCurrentTransaction
70 - //then load the XML into a DomDocument, and run getResponseData.
 58+ $payments[$key]['unstaged']['card_num'] = '';
 59+ }
7160
72 - echo print_r($payments, true);
 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.
 69+ // ADDITIONAL: log out what you did here, to... somewhere.
 70+ // Preferably *before* you rewrite the Order ID file.
7371
74 - //careful after this bit.
75 - die();
76 -
77 -
78 -
7972 //we may need to unset some hooks out here. Like... recaptcha. Makes no sense.
80 - $adapter = new GlobalCollectAdapter(array('external_data' => $data));
8173 error_log("\n\n\n");
82 - $results = $adapter->do_transaction('Confirm_CreditCard');
 74+ foreach($payments as $payment_data){
 75+ $adapter->loadDataAndReInit($payment_data['unstaged']);
 76+ $results = $adapter->do_transaction('Confirm_CreditCard');
 77+ if ($results['status'] == true){
 78+ echo "\nWe were supposed to " . $results['action'] . "\n";
 79+ } else {
 80+ echo "\nProblem Happened! \n";
 81+ }
 82+ echo $results['message'] . "\n";
 83+ }
8384
8485
8586 //$this->rewriteOrderIds();
@@ -89,7 +90,7 @@
9091 $files = array();
9192 if ($handle = opendir(dirname(__FILE__) . '/orphanlogs/')){
9293 while ( ($file = readdir($handle)) !== false ){
93 - if (trim($file, '.') != '' && $file != 'order_ids.txt'){
 94+ if (trim($file, '.') != '' && $file != 'order_ids.txt' && $file != '.svn'){
9495 $files[] = dirname(__FILE__) . '/orphanlogs/' . $file;
9596 }
9697 }
@@ -120,7 +121,6 @@
121122 $pos2 = strpos($line_data, '</ORDERID>');
122123 if ($pos2 > $pos1){
123124 $tmp = substr($line_data, $pos1, $pos2-$pos1);
124 - echo "$tmp\n";
125125 if (isset($this->order_ids[$tmp])){
126126 $orders[$tmp] = trim($line_data);
127127 unset($this->order_ids[$tmp]);
@@ -164,6 +164,43 @@
165165 fclose($file);
166166 }
167167
 168+ function getLogfileLines( $file ){
 169+ $array = array(); //surprise!
 170+ $array = file($file, FILE_SKIP_EMPTY_LINES);
 171+ //now, check about 50 lines to make sure we're not seeing any of that #012, #015 crap.
 172+ $checkcount = 50;
 173+ if (count($array) < $checkcount){
 174+ $checkcount = count($array);
 175+ }
 176+ $convert = false;
 177+ for ($i=0; $i<$checkcount; ++$i){
 178+ if( strpos($array[$i], '#012') || strpos($array[$i], '#015') ){
 179+ $convert = true;
 180+ break;
 181+ }
 182+ }
 183+ if ($convert) {
 184+ $array2 = array();
 185+ foreach ($array as $line){
 186+ if (strpos($line, '#012')){
 187+ $line = str_replace('#012', "\n", $line);
 188+ }
 189+ if (strpos($line, '#015') ){
 190+ $line = str_replace('#015', "\r", $line);
 191+ }
 192+ $array2[] = $line;
 193+ }
 194+ $newfile = implode("\n", $array2);
 195+
 196+ $handle = fopen($file, 'w');
 197+ fwrite($handle, $newfile);
 198+ fclose($handle);
 199+ $array = file($file, FILE_SKIP_EMPTY_LINES);
 200+ }
 201+
 202+ return $array;
 203+ }
 204+
168205 }
169206
170207 $maintClass = "GlobalCollectOrphanRectifier";
Property changes on: trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphanlogs
___________________________________________________________________
Modified: svn:ignore
171208 - order_ids.txt
2011-11-11:17:59:48-globalcollect
172209 + globalcollect.2
globalcollect.1
globalcollect
globalcollect.6
globalcollect.5
globalcollect.4
2011-11-11:17:59:48-globalcollect
order_ids.txt
globalcollect.3
globalcollect.7
Index: trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
@@ -25,4 +25,37 @@
2626 }
2727 return $unstaged;
2828 }
 29+
 30+ public function loadDataAndReInit( $data ){
 31+
 32+ $this->dataObj = new DonationData( get_called_class(), false, $data );
 33+
 34+ $this->raw_data = $this->dataObj->getData();
 35+
 36+ //this would be VERY BAD anywhere else.
 37+ $this->raw_data['order_id'] = $this->raw_data['i_order_id'];
 38+ $this->staged_data = $this->raw_data;
 39+
 40+ $this->transaction_results = array();
 41+
 42+ $this->setPostDefaults();
 43+ $this->defineTransactions();
 44+ $this->defineErrorMap();
 45+ $this->defineVarMap();
 46+ $this->defineDataConstraints();
 47+ $this->defineAccountInfo();
 48+ $this->defineReturnValueMap();
 49+
 50+ $this->stageData();
 51+ }
 52+
 53+ public function addData($dataArray){
 54+ $order_id = $this->raw_data['i_order_id'];
 55+ parent::addData($dataArray);
 56+ $this->raw_data['order_id'] = $order_id;
 57+ $this->raw_data['i_order_id'] = $order_id;
 58+ $this->staged_data['order_id'] = $order_id;
 59+ $this->staged_data['i_order_id'] = $order_id;
 60+ }
 61+
2962 }
\ No newline at end of file
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
@@ -1090,7 +1090,7 @@
10911091 break;
10921092 }
10931093 }
1094 -
 1094+
10951095 //if we got here with no problemflag,
10961096 //confirm or cancel the payment based on $cancelflag
10971097 if ( !$problemflag ){
@@ -1268,7 +1268,9 @@
12691269 break;
12701270 case 'GET_ORDERSTATUS':
12711271 $data = $this->xmlChildrenToArray( $response, 'STATUS' );
1272 - $this->setTransactionWMFStatus( $this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', $data['STATUSID'] ) );
 1272+ if (isset($data['STATUSID'])){
 1273+ $this->setTransactionWMFStatus( $this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', $data['STATUSID'] ) );
 1274+ }
12731275 $data['ORDER'] = $this->xmlChildrenToArray( $response, 'ORDER' );
12741276 break;
12751277 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r103506GlobalCollect command-line orphan rectifier: addressing r103288 fixme.khorn20:35, 17 November 2011
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

Comments

#Comment by Kaldari (talk | contribs)   20:11, 17 November 2011
+			if ($results['status'] == true){

This should either be:
if ( $results['status'] ) {
...or...
if ( $results['status'] === true ) {

#Comment by Khorn (WMF) (talk | contribs)   20:38, 17 November 2011

Fixed in r103506.

Status & tagging log