r103416 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103415‎ | r103416 | r103417 >
Date:23:41, 16 November 2011
Author:khorn
Status:ok (Comments)
Tags:
Comment:
GlobalCollect command-line orphan rectifier: More small tweaks.
Aside from taking care of some more notices that popped up when sending stomp transactions, there is now a mechanism for looking up (and continually re-asserting) the utm_source, pulled from the contribution_tracking database.
Modified paths:
  • /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
@@ -13,7 +13,7 @@
1414
1515 protected $killfiles = array();
1616 protected $order_ids = array();
17 - protected $max_per_execute = 5;
 17+ protected $max_per_execute = 3;
1818
1919
2020 function execute(){
@@ -48,6 +48,25 @@
4949
5050 $xml = new DomDocument;
5151
 52+ //fields that have generated notices if they're not there.
 53+ $additional_fields = array(
 54+ 'card_num',
 55+ 'comment',
 56+ 'size',
 57+ 'utm_medium',
 58+ 'utm_campaign',
 59+ 'referrer',
 60+ 'mname',
 61+ 'fname2',
 62+ 'lname2',
 63+ 'street2',
 64+ 'city2',
 65+ 'state2',
 66+ 'country2',
 67+ 'zip2',
 68+ );
 69+
 70+
5271 foreach ($payments as $key => $payment_data){
5372 $xml->loadXML($payment_data['xml']);
5473 $parsed = $adapter->getResponseData($xml);
@@ -55,9 +74,13 @@
5675 $payments[$key]['unstaged'] = $adapter->unstage_data($parsed);
5776 $payments[$key]['unstaged']['contribution_tracking_id'] = $payments[$key]['contribution_tracking_id'];
5877 $payments[$key]['unstaged']['i_order_id'] = $payments[$key]['unstaged']['order_id'];
59 - $payments[$key]['unstaged']['card_num'] = '';
60 - }
61 -
 78+ foreach ($additional_fields as $val){
 79+ if (!array_key_exists($val, $payments[$key]['unstaged'])){
 80+ $payments[$key]['unstaged'][$val] = null;
 81+ }
 82+ }
 83+ }
 84+
6285 // ADDITIONAL: log out what you did here, to... somewhere.
6386 // Preferably *before* you rewrite the Order ID file.
6487
@@ -70,6 +93,9 @@
7194 unset($this->order_ids[$payments[$key]['unstaged']['order_id']]);
7295 } else {
7396 $adapter->log( $payment_data['unstaged']['contribution_tracking_id'] . ": ERROR: " . $results['message']);
 97+ if (strpos($results['message'], "GET_ORDERSTATUS reports that the payment is already complete.")){
 98+ unset($this->order_ids[$payments[$key]['unstaged']['order_id']]);
 99+ }
74100 }
75101 echo $results['message'] . "\n";
76102 }
Index: trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
@@ -1,6 +1,8 @@
22 <?php
33
44 class GlobalCollectOrphanAdapter extends GlobalCollectAdapter {
 5+
 6+ protected $utm_source;
57
68 public function unstage_data( $data = array(), $final = true ){
79 $unstaged = array();
@@ -49,6 +51,11 @@
5052 $this->defineReturnValueMap();
5153
5254 $this->stageData();
 55+
 56+ //have to do this here, or else.
 57+ $this->utm_source = $this->getUTMSourceFromDB();
 58+ $this->raw_data['utm_source'] = $this->utm_source;
 59+ $this->staged_data['utm_source'] = $this->utm_source;
5360 }
5461
5562 public function addData($dataArray){
@@ -58,6 +65,8 @@
5966 $this->raw_data['i_order_id'] = $order_id;
6067 $this->staged_data['order_id'] = $order_id;
6168 $this->staged_data['i_order_id'] = $order_id;
 69+ $this->raw_data['utm_source'] = $this->utm_source;
 70+ $this->staged_data['utm_source'] = $this->utm_source;
6271 }
6372
6473 public function do_transaction($transaction){
@@ -66,8 +75,8 @@
6776 case 'CANCEL_PAYMENT':
6877 self::log($this->getData_Raw('contribution_tracking_id') . ": CVV: " . $this->getData_Raw('cvv_result') . ": AVS: " . $this->getData_Raw('avs_result'));
6978 //and then go on, unless you're testing, in which case:
70 - //return "NOPE";
71 - //break;
 79+// return "NOPE";
 80+// break;
7281 default:
7382 return parent::do_transaction($transaction);
7483 break;
@@ -89,4 +98,35 @@
9099 closelog();
91100 }
92101
 102+ public function getUTMSourceFromDB(){
 103+
 104+ $db = ContributionTrackingProcessor::contributionTrackingConnection();
 105+
 106+ if ( !$db ) {
 107+ die("There is something terribly wrong with your Contribution Tracking database. fixit.");
 108+ return null;
 109+ }
 110+
 111+ $ctid = $this->getData_Raw('contribution_tracking_id');
 112+
 113+ // if contrib tracking id is not already set, we need to insert the data, otherwise update
 114+ if ( $ctid ) {
 115+ $res = $db->select( 'contribution_tracking',
 116+ array(
 117+ 'utm_source'
 118+ ),
 119+ array('id' => $ctid)
 120+ );
 121+ foreach ($res as $thing){
 122+ $this->log("$ctid: Found UTM Source value $thing->utm_source");
 123+ return $thing->utm_source;
 124+ }
 125+ }
 126+
 127+ //if we got here, we can't find anything else...
 128+ $this->log("$ctid: FAILED to find UTM Source value. Using default.");
 129+ return $this->getData_Raw('utm_source');
 130+
 131+ }
 132+
93133 }
\ 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

Comments

#Comment by Kaldari (talk | contribs)   20:21, 17 November 2011

Good except for some whitespace formatting problems.

Status & tagging log