r103491 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103490‎ | r103491 | r103492 >
Date:18:57, 17 November 2011
Author:khorn
Status:ok (Comments)
Tags:
Comment:
GlobalCollect command-line orphan rectifier: Adding in yet more data from the contribution_tracking table (including timestamp).
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
@@ -90,11 +90,11 @@
9191 $results = $adapter->do_transaction('Confirm_CreditCard');
9292 if ($results['status'] == true){
9393 $adapter->log( $payment_data['unstaged']['contribution_tracking_id'] . ": FINAL: " . $results['action']);
94 - unset($this->order_ids[$payments[$key]['unstaged']['order_id']]);
 94+ unset($this->order_ids[$payment_data['unstaged']['order_id']]);
9595 } else {
9696 $adapter->log( $payment_data['unstaged']['contribution_tracking_id'] . ": ERROR: " . $results['message']);
9797 if (strpos($results['message'], "GET_ORDERSTATUS reports that the payment is already complete.")){
98 - unset($this->order_ids[$payments[$key]['unstaged']['order_id']]);
 98+ unset($this->order_ids[$payment_data['unstaged']['order_id']]);
9999 }
100100 }
101101 echo $results['message'] . "\n";
Index: trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
@@ -2,7 +2,9 @@
33
44 class GlobalCollectOrphanAdapter extends GlobalCollectAdapter {
55
6 - protected $utm_source;
 6+ //Data we know to be good, that we always want to re-assert after a load or an addData.
 7+ //so far: order_id, i_order_id, and the utm data we pull from contribution tracking.
 8+ protected $hard_data = array();
79
810 public function unstage_data( $data = array(), $final = true ){
911 $unstaged = array();
@@ -32,16 +34,24 @@
3335 public function loadDataAndReInit( $data ){
3436 $this->batch = true; //or the hooks will accumulate badness.
3537
 38+ //re-init all these arrays, because this is a batch thing.
 39+ $this->hard_data = array();
 40+ $this->transaction_results = array();
 41+ $this->raw_data = array();
 42+ $this->staged_data = array();
 43+
 44+ $this->hard_data['order_id'] = $data['order_id'];
 45+ $this->hard_data['i_order_id'] = $data['order_id'];
 46+
3647 $this->dataObj = new DonationData( get_called_class(), false, $data );
3748
3849 $this->raw_data = $this->dataObj->getData();
3950
40 - //this would be VERY BAD anywhere else.
41 - $this->raw_data['order_id'] = $this->raw_data['i_order_id'];
 51+ $this->hard_data = array_merge( $this->hard_data, $this->getUTMInfoFromDB() );
 52+ $this->reAddHardData();
 53+
4254 $this->staged_data = $this->raw_data;
4355
44 - $this->transaction_results = array();
45 -
4656 $this->setPostDefaults();
4757 $this->defineTransactions();
4858 $this->defineErrorMap();
@@ -52,23 +62,24 @@
5363
5464 $this->stageData();
5565
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;
 66+ //have to do this again here.
 67+ $this->reAddHardData();
6068 }
6169
6270 public function addData($dataArray){
63 - $order_id = $this->raw_data['i_order_id'];
6471 parent::addData($dataArray);
65 - $this->raw_data['order_id'] = $order_id;
66 - $this->raw_data['i_order_id'] = $order_id;
67 - $this->staged_data['order_id'] = $order_id;
68 - $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;
 72+ $this->reAddHardData();
7173 }
7274
 75+ private function reAddHardData(){
 76+ //anywhere else, and this would constitute abuse of the system.
 77+ //so don't do it.
 78+ foreach ($this->hard_data as $key => $val){
 79+ $this->raw_data[$key] = $val;
 80+ $this->staged_data[$key] = $val;
 81+ }
 82+ }
 83+
7384 public function do_transaction($transaction){
7485 switch ($transaction){
7586 case 'SET_PAYMENT':
@@ -98,7 +109,7 @@
99110 closelog();
100111 }
101112
102 - public function getUTMSourceFromDB(){
 113+ public function getUTMInfoFromDB(){
103114
104115 $db = ContributionTrackingProcessor::contributionTrackingConnection();
105116
@@ -108,25 +119,87 @@
109120 }
110121
111122 $ctid = $this->getData_Raw('contribution_tracking_id');
 123+
 124+ $data = array();
112125
113126 // if contrib tracking id is not already set, we need to insert the data, otherwise update
114127 if ( $ctid ) {
115128 $res = $db->select( 'contribution_tracking',
116129 array(
117 - 'utm_source'
 130+ 'utm_source',
 131+ 'utm_campaign',
 132+ 'utm_medium',
 133+ 'ts'
118134 ),
119135 array('id' => $ctid)
120136 );
121137 foreach ($res as $thing){
122 - $this->log("$ctid: Found UTM Source value $thing->utm_source");
123 - return $thing->utm_source;
 138+ $data['utm_source'] = $thing->utm_source;
 139+ $data['utm_campaign'] = $thing->utm_campaign;
 140+ $data['utm_medium'] = $thing->utm_medium;
 141+ $data['ts'] = $thing->ts;
 142+ $msg = '';
 143+ foreach ($data as $key => $val){
 144+ $msg .= "$key = $val ";
 145+ }
 146+ $this->log("$ctid: Found UTM Data. $msg");
 147+ echo $msg;
 148+ return $data;
124149 }
125150 }
126151
127152 //if we got here, we can't find anything else...
128153 $this->log("$ctid: FAILED to find UTM Source value. Using default.");
129 - return $this->getData_Raw('utm_source');
 154+ return $data;
 155+ }
 156+
 157+
 158+ /**
 159+ * Copying this here because it's the fastest way to bring in an actual timestamp.
 160+ */
 161+ protected function doStompTransaction() {
 162+ if ( !$this->getGlobal( 'EnableStomp' ) ){
 163+ return;
 164+ }
 165+ $this->debugarray[] = "Attempting Stomp Transaction!";
 166+ $hook = '';
 167+
 168+ $status = $this->getTransactionWMFStatus();
 169+ switch ( $status ) {
 170+ case 'complete':
 171+ $hook = 'gwStomp';
 172+ break;
 173+ case 'pending':
 174+ case 'pending-poke':
 175+ $hook = 'gwPendingStomp';
 176+ break;
 177+ }
 178+ if ( $hook === '' ) {
 179+ $this->debugarray[] = "No Stomp Hook Found for WMF_Status $status";
 180+ return;
 181+ }
130182
 183+
 184+ if (!is_null($this->getData_Raw('ts'))){
 185+ $timestamp = strtotime($this->getData_Raw('ts')); //I hate that this works.
 186+ } else {
 187+ $timestamp = time();
 188+ }
 189+
 190+ // send the thing.
 191+ $transaction = array(
 192+ 'response' => $this->getTransactionMessage(),
 193+ 'date' => $timestamp,
 194+ 'gateway_txn_id' => $this->getTransactionGatewayTxnID(),
 195+ //'language' => '',
 196+ );
 197+ $transaction += $this->getData_Raw();
 198+
 199+ try {
 200+ wfRunHooks( $hook, array( $transaction ) );
 201+ } catch ( Exception $e ) {
 202+ self::log( "STOMP ERROR. Could not add message. " . $e->getMessage() , LOG_CRIT );
 203+ }
131204 }
132205
133206 }
\ 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:25, 17 November 2011
+                 'utm_source',
+				 'utm_campaign',
+				 'utm_medium',
+				 'ts'

Whitespace issue here. Otherwise looks good.

Status & tagging log