Index: trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php |
— | — | @@ -90,11 +90,11 @@ |
91 | 91 | $results = $adapter->do_transaction('Confirm_CreditCard'); |
92 | 92 | if ($results['status'] == true){ |
93 | 93 | $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']]); |
95 | 95 | } else { |
96 | 96 | $adapter->log( $payment_data['unstaged']['contribution_tracking_id'] . ": ERROR: " . $results['message']); |
97 | 97 | 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']]); |
99 | 99 | } |
100 | 100 | } |
101 | 101 | echo $results['message'] . "\n"; |
Index: trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php |
— | — | @@ -2,7 +2,9 @@ |
3 | 3 | |
4 | 4 | class GlobalCollectOrphanAdapter extends GlobalCollectAdapter { |
5 | 5 | |
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(); |
7 | 9 | |
8 | 10 | public function unstage_data( $data = array(), $final = true ){ |
9 | 11 | $unstaged = array(); |
— | — | @@ -32,16 +34,24 @@ |
33 | 35 | public function loadDataAndReInit( $data ){ |
34 | 36 | $this->batch = true; //or the hooks will accumulate badness. |
35 | 37 | |
| 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 | + |
36 | 47 | $this->dataObj = new DonationData( get_called_class(), false, $data ); |
37 | 48 | |
38 | 49 | $this->raw_data = $this->dataObj->getData(); |
39 | 50 | |
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 | + |
42 | 54 | $this->staged_data = $this->raw_data; |
43 | 55 | |
44 | | - $this->transaction_results = array(); |
45 | | - |
46 | 56 | $this->setPostDefaults(); |
47 | 57 | $this->defineTransactions(); |
48 | 58 | $this->defineErrorMap(); |
— | — | @@ -52,23 +62,24 @@ |
53 | 63 | |
54 | 64 | $this->stageData(); |
55 | 65 | |
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(); |
60 | 68 | } |
61 | 69 | |
62 | 70 | public function addData($dataArray){ |
63 | | - $order_id = $this->raw_data['i_order_id']; |
64 | 71 | 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(); |
71 | 73 | } |
72 | 74 | |
| 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 | + |
73 | 84 | public function do_transaction($transaction){ |
74 | 85 | switch ($transaction){ |
75 | 86 | case 'SET_PAYMENT': |
— | — | @@ -98,7 +109,7 @@ |
99 | 110 | closelog(); |
100 | 111 | } |
101 | 112 | |
102 | | - public function getUTMSourceFromDB(){ |
| 113 | + public function getUTMInfoFromDB(){ |
103 | 114 | |
104 | 115 | $db = ContributionTrackingProcessor::contributionTrackingConnection(); |
105 | 116 | |
— | — | @@ -108,25 +119,87 @@ |
109 | 120 | } |
110 | 121 | |
111 | 122 | $ctid = $this->getData_Raw('contribution_tracking_id'); |
| 123 | + |
| 124 | + $data = array(); |
112 | 125 | |
113 | 126 | // if contrib tracking id is not already set, we need to insert the data, otherwise update |
114 | 127 | if ( $ctid ) { |
115 | 128 | $res = $db->select( 'contribution_tracking', |
116 | 129 | array( |
117 | | - 'utm_source' |
| 130 | + 'utm_source', |
| 131 | + 'utm_campaign', |
| 132 | + 'utm_medium', |
| 133 | + 'ts' |
118 | 134 | ), |
119 | 135 | array('id' => $ctid) |
120 | 136 | ); |
121 | 137 | 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; |
124 | 149 | } |
125 | 150 | } |
126 | 151 | |
127 | 152 | //if we got here, we can't find anything else... |
128 | 153 | $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 | + } |
130 | 182 | |
| 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 | + } |
131 | 204 | } |
132 | 205 | |
133 | 206 | } |
\ No newline at end of file |