Index: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php |
— | — | @@ -13,42 +13,193 @@ |
14 | 14 | |
15 | 15 | protected $killfiles = array(); |
16 | 16 | protected $order_ids = array(); |
17 | | - protected $max_per_execute = 3; |
| 17 | + protected $max_per_execute = 500; //only really used if you're going by-file. |
| 18 | + protected $target_execute_time = 30; //(seconds) - only used by the stomp option. |
| 19 | + protected $adapter; |
18 | 20 | |
19 | 21 | |
20 | 22 | function execute(){ |
| 23 | + $func = 'parse_files'; |
| 24 | + if ( !empty( $_SERVER['argv'][1] ) ){ |
| 25 | + if ( $_SERVER['argv'][1] === 'stomp' ){ |
| 26 | + $func = 'orphan_stomp'; |
| 27 | + if ( !empty( $_SERVER['argv'][2] ) && is_numeric( $_SERVER['argv'][2] ) ){ |
| 28 | + $this->target_execute_time = $_SERVER['argv'][2]; |
| 29 | + } |
| 30 | + } elseif ( is_numeric( $_SERVER['argv'][1] ) ){ |
| 31 | + $this->max_per_execute = $_SERVER['argv'][1]; |
| 32 | + } |
| 33 | + } |
21 | 34 | |
22 | | - $order_ids = file('orphanlogs/order_ids.txt', FILE_SKIP_EMPTY_LINES); |
23 | | - foreach ($order_ids as $key=>$val){ |
24 | | - $order_ids[$key] = trim($val); |
| 35 | + $data = array( |
| 36 | + 'wheeee' => 'yes' |
| 37 | + ); |
| 38 | + $this->adapter = new GlobalCollectOrphanAdapter(array('external_data' => $data)); |
| 39 | + |
| 40 | + //Now, actually do the processing. |
| 41 | + if ( method_exists( $this, $func ) ) { |
| 42 | + $this->{$func}(); |
| 43 | + } else { |
| 44 | + echo "There's no $func in Orphan Rectifying!\n"; |
| 45 | + die(); |
25 | 46 | } |
26 | | - foreach ($order_ids as $id){ |
| 47 | + } |
| 48 | + |
| 49 | + function orphan_stomp(){ |
| 50 | + |
| 51 | + $this->removed_message_count = 0; |
| 52 | + $this->now = time(); //time at start, thanks very much. |
| 53 | + |
| 54 | + //I want to be clear on the problem I hope to prevent with this. |
| 55 | + //Say, for instance, we pull a legit orphan, and for whatever reason, can't completely rectify it. |
| 56 | + //Then, we go back and pull more... and that same one is in the list again. We should stop after one try per message per execute. |
| 57 | + //We should also be smart enough to not process things we believe we just deleted. |
| 58 | + $this->handled_ids = array(); |
| 59 | + |
| 60 | + //first, we need to... clean up the limbo queue. |
| 61 | + $this->handleStompAntiMessages(); |
| 62 | + $this->adapter->log( 'Removed ' . $this->removed_message_count . ' messages and antimessages.' ); |
| 63 | + |
| 64 | + //Pull a batch of CC orphans, keeping in mind that Things May Have Happened in the small slice of time since we handled the antimessages. |
| 65 | + $orphans = $this->getStompOrphans(); |
| 66 | + while ( count( $orphans ) && $this->keepGoing() ){ |
| 67 | + //..do stuff. |
| 68 | + foreach ( $orphans as $correlation_id => $orphan ) { |
| 69 | + //process |
| 70 | + if ( $this->rectifyOrphan( $orphan ) ){ |
| 71 | + $this->addStompCorrelationIDToAckBucket( $correlation_id ); |
| 72 | + $this->handled_ids[$correlation_id] = 'rectified'; |
| 73 | + } else { |
| 74 | + $this->handled_ids[$correlation_id] = 'error'; |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + $this->addStompCorrelationIDToAckBucket( false, true ); //this just acks everything that's waiting for it. |
| 80 | + |
| 81 | + //TODO: Make stats squirt out all over the place. |
| 82 | + $am = 0; |
| 83 | + $rec = 0; |
| 84 | + $err = 0; |
| 85 | + foreach( $this->handled_ids as $id=>$whathappened ){ |
| 86 | + switch ( $whathappened ){ |
| 87 | + case 'antimessage' : |
| 88 | + $am += 1; |
| 89 | + break; |
| 90 | + case 'rectified' : |
| 91 | + $rec += 1; |
| 92 | + break; |
| 93 | + case 'error' : |
| 94 | + $err += 1; |
| 95 | + break; |
| 96 | + } |
| 97 | + } |
| 98 | + echo "\nDone! Final results: \n $am destroyed via antimessage \n $rec rectified orphans \n $err errored out\n"; |
| 99 | + |
| 100 | + } |
| 101 | + |
| 102 | + function keepGoing(){ |
| 103 | + $elapsed = time() - $this->now; |
| 104 | + if ( $elapsed < $this->target_execute_time ){ |
| 105 | + return true; |
| 106 | + } else { |
| 107 | + return false; |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + function addStompCorrelationIDToAckBucket( $correlation_id, $ackNow = false ){ |
| 112 | + static $bucket = array(); |
| 113 | + $count = 50; //sure. Why not? |
| 114 | + if ( $correlation_id ) { |
| 115 | + $bucket[$correlation_id] = "'$correlation_id'"; //avoiding duplicates. |
| 116 | + $this->handled_ids[$correlation_id] = 'antimessage'; |
| 117 | + } |
| 118 | + if ( count( $bucket ) && ( count( $bucket ) >= $count || $ackNow ) ){ |
| 119 | + //ack now. |
| 120 | + $selector = 'JMSCorrelationID IN (' . implode( ", ", $bucket ) . ')'; |
| 121 | + $ackMe = stompFetchMessages( 'cc-limbo', $selector, $count * 100 ); //This is outrageously high, but I just want to be reasonably sure we get all the matches. |
| 122 | + $retrieved_count = count( $ackMe ); |
| 123 | + if ( $retrieved_count ){ |
| 124 | + stompAckMessages( $ackMe ); |
| 125 | + $this->removed_message_count += $retrieved_count; |
| 126 | + } |
| 127 | + $bucket = array(); |
| 128 | + } |
| 129 | + |
| 130 | + } |
| 131 | + |
| 132 | + function handleStompAntiMessages(){ |
| 133 | + $selector = "antimessage = 'true'"; |
| 134 | + $antimessages = stompFetchMessages( 'cc-limbo', $selector, 1000 ); |
| 135 | + $count = 0; |
| 136 | + while ( count( $antimessages ) ){ //if there's an antimessage, we can ack 'em all right now. |
| 137 | + $count += count( $antimessages ); |
| 138 | + foreach ( $antimessages as $message ){ |
| 139 | + //add the correlation ID to the ack bucket. |
| 140 | + if (array_key_exists('correlation-id', $message->headers)) { |
| 141 | + $this->addStompCorrelationIDToAckBucket( $message->headers['correlation-id'] ); |
| 142 | + } else { |
| 143 | + echo 'The STOMP message ' . $message->headers['message-id'] . ' has no correlation ID!'; |
| 144 | + } |
| 145 | + } |
| 146 | + $antimessages = stompFetchMessages( 'cc-limbo', $selector, 1000 ); |
| 147 | + } |
| 148 | + $this->addStompCorrelationIDToAckBucket( false, true ); //this just acks everything that's waiting for it. |
| 149 | + $this->adapter->log("Found $count antimessages."); |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * Returns an array of **at most** 300 decoded orphans that we don't think we've rectified yet. |
| 154 | + * @return array keys are the correlation_id, and the values are the decoded stomp message body. |
| 155 | + */ |
| 156 | + function getStompOrphans(){ |
| 157 | + $time_buffer = 60*20; //20 minutes? Sure. Why not? |
| 158 | + $selector = "payment_method = 'cc'"; |
| 159 | + $messages = stompFetchMessages( 'cc-limbo', $selector, 300 ); |
| 160 | + $orphans = array(); |
| 161 | + foreach ( $messages as $message ){ |
| 162 | + if ( !array_key_exists('antimessage', $message->headers ) |
| 163 | + && !array_key_exists( $message->headers['correlation-id'], $this->handled_ids ) ) { |
| 164 | + //check the timestamp to see if it's old enough. |
| 165 | + $decoded = json_decode($message->body, true); |
| 166 | + if ( array_key_exists( 'date', $decoded ) ){ |
| 167 | + $elapsed = $this->now - $decoded['date']; |
| 168 | + if ( $elapsed > $time_buffer ){ |
| 169 | + //we got ourselves an orphan! |
| 170 | + $orphans[$message->headers['antimessage']] = $decoded; |
| 171 | + } |
| 172 | + } |
| 173 | + } |
| 174 | + } |
| 175 | + return $orphans; |
| 176 | + } |
| 177 | + |
| 178 | + function parse_files(){ |
| 179 | + //all the old stuff goes here. |
| 180 | + $order_ids = file( 'orphanlogs/order_ids.txt', FILE_SKIP_EMPTY_LINES ); |
| 181 | + foreach ( $order_ids as $key=>$val ){ |
| 182 | + $order_ids[$key] = trim( $val ); |
| 183 | + } |
| 184 | + foreach ( $order_ids as $id ){ |
27 | 185 | $this->order_ids[$id] = $id; //easier to unset this way. |
28 | 186 | } |
29 | | - $outstanding_count = count($this->order_ids); |
| 187 | + $outstanding_count = count( $this->order_ids ); |
30 | 188 | echo "Order ID count: " . $outstanding_count . "\n"; |
31 | 189 | |
32 | 190 | $files = $this->getAllLogFileNames(); |
33 | 191 | $payments = array(); |
34 | | - foreach ($files as $file){ |
35 | | - if (count($payments) < $this->max_per_execute){ |
| 192 | + foreach ( $files as $file ){ |
| 193 | + if ( count( $payments ) < $this->max_per_execute ){ |
36 | 194 | $file_array = $this->getLogfileLines( $file ); |
37 | | - $payments = array_merge($this->findTransactionLines($file_array), $payments); |
38 | | - if (count($payments) === 0){ |
| 195 | + $payments = array_merge( $this->findTransactionLines( $file_array ), $payments ); |
| 196 | + if ( count( $payments ) === 0 ){ |
39 | 197 | $this->killfiles[] = $file; |
40 | | - echo print_r($this->killfiles, true); |
| 198 | + echo print_r( $this->killfiles, true ); |
41 | 199 | } |
42 | 200 | } |
43 | | - } |
| 201 | + } |
44 | 202 | |
45 | | - $data = array( |
46 | | - 'wheeee' => 'yes' |
47 | | - ); |
48 | | - |
49 | | - $adapter = new GlobalCollectOrphanAdapter(array('external_data' => $data)); |
50 | | - $adapter->setCurrentTransaction('INSERT_ORDERWITHPAYMENT'); |
51 | | - $var_map = $adapter->defineVarMap(); |
52 | | - |
| 203 | + $this->adapter->setCurrentTransaction('INSERT_ORDERWITHPAYMENT'); |
53 | 204 | $xml = new DomDocument; |
54 | 205 | |
55 | 206 | //fields that have generated notices if they're not there. |
— | — | @@ -69,12 +220,11 @@ |
70 | 221 | 'zip2', |
71 | 222 | ); |
72 | 223 | |
73 | | - |
74 | 224 | foreach ($payments as $key => $payment_data){ |
75 | 225 | $xml->loadXML($payment_data['xml']); |
76 | | - $parsed = $adapter->getResponseData($xml); |
| 226 | + $parsed = $this->adapter->getResponseData($xml); |
77 | 227 | $payments[$key]['parsed'] = $parsed; |
78 | | - $payments[$key]['unstaged'] = $adapter->unstage_data($parsed); |
| 228 | + $payments[$key]['unstaged'] = $this->adapter->unstage_data($parsed); |
79 | 229 | $payments[$key]['unstaged']['contribution_tracking_id'] = $payments[$key]['contribution_tracking_id']; |
80 | 230 | $payments[$key]['unstaged']['i_order_id'] = $payments[$key]['unstaged']['order_id']; |
81 | 231 | foreach ($additional_fields as $val){ |
— | — | @@ -92,18 +242,9 @@ |
93 | 243 | foreach($payments as $payment_data){ |
94 | 244 | if ($i < $this->max_per_execute){ |
95 | 245 | ++$i; |
96 | | - $adapter->loadDataAndReInit($payment_data['unstaged']); |
97 | | - $results = $adapter->do_transaction('Confirm_CreditCard'); |
98 | | - if ($results['status']){ |
99 | | - $adapter->log( $payment_data['unstaged']['contribution_tracking_id'] . ": FINAL: " . $results['action']); |
100 | | - unset($this->order_ids[$payment_data['unstaged']['order_id']]); |
101 | | - } else { |
102 | | - $adapter->log( $payment_data['unstaged']['contribution_tracking_id'] . ": ERROR: " . $results['message']); |
103 | | - if (strpos($results['message'], "GET_ORDERSTATUS reports that the payment is already complete.")){ |
104 | | - unset($this->order_ids[$payment_data['unstaged']['order_id']]); |
105 | | - } |
| 246 | + if ( $this->rectifyOrphan( $payment_data['unstaged'] ) ) { |
| 247 | + unset( $this->order_ids[$payment_data['unstaged']['order_id']] ); |
106 | 248 | } |
107 | | - echo $results['message'] . "\n"; |
108 | 249 | } |
109 | 250 | } |
110 | 251 | |
— | — | @@ -112,6 +253,32 @@ |
113 | 254 | } |
114 | 255 | } |
115 | 256 | |
| 257 | + /** |
| 258 | + * Uses the Orphan Adapter to rectify a single orphan. Returns a boolean letting the caller know if |
| 259 | + * the orphan has been fully rectified or not. |
| 260 | + * @param array $data Some set of orphan data. |
| 261 | + * @param boolean $query_contribution_tracking A flag specifying if we should query the contribution_tracking table or not. |
| 262 | + * @return boolean True if the orphan has been rectified, false if not. |
| 263 | + */ |
| 264 | + function rectifyOrphan( $data, $query_contribution_tracking = true ){ |
| 265 | + $rectified = false; |
| 266 | + |
| 267 | + $this->adapter->loadDataAndReInit( $data, $query_contribution_tracking ); |
| 268 | + $results = $this->adapter->do_transaction( 'Confirm_CreditCard' ); |
| 269 | + if ($results['status']){ |
| 270 | + $this->adapter->log( $data['contribution_tracking_id'] . ": FINAL: " . $results['action'] ); |
| 271 | + $rectified = true; |
| 272 | + } else { |
| 273 | + $this->adapter->log( $data['contribution_tracking_id'] . ": ERROR: " . $results['message'] ); |
| 274 | + if ( strpos( $results['message'], "GET_ORDERSTATUS reports that the payment is already complete." ) ){ |
| 275 | + $rectified = true; |
| 276 | + } |
| 277 | + } |
| 278 | + echo $results['message'] . "\n"; |
| 279 | + |
| 280 | + return $rectified; |
| 281 | + } |
| 282 | + |
116 | 283 | function getAllLogFileNames(){ |
117 | 284 | $files = array(); |
118 | 285 | if ($handle = opendir(dirname(__FILE__) . '/orphanlogs/')){ |
Property changes on: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
119 | 286 | Merged /trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php:r75657-77440,77442-79147,79149-79286,79288-79296,79298-79299,79301-79303,79305-86440,90286,92825,96120-96121,96125,97945-99042,99045-99408,99503,99555,99568,99570-101026,101056,101060,101063-101064,101071-101074,101076,101099,101109,101112,101163,101180,101192,101200,101205,101207,101217,101230,101232,101236,101335,101382,101399,101441,101501-101504,101512,101541,101547,101549,101553-101555,101557,101559,101561,101563,101576,101578-101579,101631,101633,101638,101669,101676,101679,101689,101700,101706,101719,101740,101747,101757,101764,101778-101779,101781,101785-101789,101798,101823,101826,101837,101846,101852,101870-101872,101878,101882,101890,101892,101910,101917,101929,101947,101949-101951,101955-101960,101962,101964-101966,101996,102003,102011-102012,102030,102032-102033,102047,102050-102052,102054,102056,102058,102065,102076,102081,102085-102087,102118,102120,102123-102127,102130,102134,102140,102147,102151-102152,102155-102156,102186,102188-102242,102252,102258-102261,102263,102267,102269,102307-102309,102313,102318,102332,102338,102341-102342,102345,102364,102419,102424-102425,102445,102463,102467-102468,102470,102476,102479-102480,102549-102550,102576-102581,102590,102594,102596,102611,102639,102664,102681-102682,102685,102689,102698,102700-102703,102707,102711-102712,102714,102729,102733,102736,102740,102752,102763,102805,102807,102809-102810,102812,102819-102824,102826,102828-102833,102835-102836,102841,102872,102878,102915,102921-102923,102926-102928,102932,102936,102938,102942-102943,102946,102953,102960-102961,103009,103023-103024,103026-103027,103032,103036-103038,103040,103044,103050,103058,103067,103077,103080,103130,103219,103223,103229,103235,103237-103239,103243-103247,103253,103255,103259,103261-103262,103264,103275,103278,103284,103289-103291,103325,103371,103397,103399,103401,103411,103413,103421,103434-103435,103481,103500-103501,103503,103515,103519,103537,103541,103548,103591,103607-103608,103633,103680,103775,103784,103837,103839,103863,103866,104065,104194,104210,104243,104298,104362,104485,104587,104611,104648,104791,104933 |
120 | 287 | Merged /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php:r99568 |
Index: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php |
— | — | @@ -1,18 +1,18 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class GlobalCollectOrphanAdapter extends GlobalCollectAdapter { |
5 | | - |
| 5 | + |
6 | 6 | //Data we know to be good, that we always want to re-assert after a load or an addData. |
7 | 7 | //so far: order_id, i_order_id, and the utm data we pull from contribution tracking. |
8 | | - protected $hard_data = array(); |
| 8 | + protected $hard_data = array( ); |
9 | 9 | |
10 | | - public function unstage_data( $data = array(), $final = true ){ |
11 | | - $unstaged = array(); |
12 | | - foreach ( $data as $key=>$val ){ |
13 | | - if (is_array($val)){ |
| 10 | + public function unstage_data( $data = array( ), $final = true ) { |
| 11 | + $unstaged = array( ); |
| 12 | + foreach ( $data as $key => $val ) { |
| 13 | + if ( is_array( $val ) ) { |
14 | 14 | $unstaged += $this->unstage_data( $val, false ); |
15 | 15 | } else { |
16 | | - if (array_key_exists($key, $this->var_map)){ |
| 16 | + if ( array_key_exists( $key, $this->var_map ) ) { |
17 | 17 | //run the unstage data functions. |
18 | 18 | $unstaged[$this->var_map[$key]] = $val; |
19 | 19 | //this would be EXTREMELY bad to put in the regular adapter. |
— | — | @@ -22,36 +22,47 @@ |
23 | 23 | } |
24 | 24 | } |
25 | 25 | } |
26 | | - if ($final){ |
27 | | - $this->stageData('response'); |
| 26 | + if ( $final ) { |
| 27 | + $this->stageData( 'response' ); |
28 | 28 | } |
29 | | - foreach ($unstaged as $key=>$val){ |
| 29 | + foreach ( $unstaged as $key => $val ) { |
30 | 30 | $unstaged[$key] = $this->staged_data[$key]; |
31 | 31 | } |
32 | 32 | return $unstaged; |
33 | 33 | } |
34 | | - |
35 | | - public function loadDataAndReInit( $data ){ |
| 34 | + |
| 35 | + public function loadDataAndReInit( $data, $useDB = true ) { |
36 | 36 | $this->batch = true; //or the hooks will accumulate badness. |
37 | | - |
38 | 37 | //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 | | - |
| 38 | + $this->hard_data = array( ); |
| 39 | + $this->transaction_results = array( ); |
| 40 | + $this->raw_data = array( ); |
| 41 | + $this->staged_data = array( ); |
| 42 | + |
44 | 43 | $this->hard_data['order_id'] = $data['order_id']; |
45 | 44 | $this->hard_data['i_order_id'] = $data['order_id']; |
46 | | - |
| 45 | + |
47 | 46 | $this->dataObj = new DonationData( get_called_class(), false, $data ); |
48 | 47 | |
49 | 48 | $this->raw_data = $this->dataObj->getData(); |
50 | | - |
51 | | - $this->hard_data = array_merge( $this->hard_data, $this->getUTMInfoFromDB() ); |
| 49 | + |
| 50 | + if ( $useDB ){ |
| 51 | + $this->hard_data = array_merge( $this->hard_data, $this->getUTMInfoFromDB() ); |
| 52 | + } else { |
| 53 | + $utm_keys = array( |
| 54 | + 'utm_source', |
| 55 | + 'utm_campaign', |
| 56 | + 'utm_medium', |
| 57 | + 'date' |
| 58 | + ); |
| 59 | + foreach($utm_keys as $key){ |
| 60 | + $this->hard_data[$key] = $data[$key]; |
| 61 | + } |
| 62 | + } |
52 | 63 | $this->reAddHardData(); |
53 | | - |
| 64 | + |
54 | 65 | $this->staged_data = $this->raw_data; |
55 | | - |
| 66 | + |
56 | 67 | $this->setPostDefaults(); |
57 | 68 | $this->defineTransactions(); |
58 | 69 | $this->defineErrorMap(); |
— | — | @@ -61,39 +72,40 @@ |
62 | 73 | $this->defineReturnValueMap(); |
63 | 74 | |
64 | 75 | $this->stageData(); |
65 | | - |
| 76 | + |
66 | 77 | //have to do this again here. |
67 | 78 | $this->reAddHardData(); |
68 | 79 | } |
69 | | - |
70 | | - public function addData($dataArray){ |
71 | | - parent::addData($dataArray); |
| 80 | + |
| 81 | + public function addData( $dataArray ) { |
| 82 | + parent::addData( $dataArray ); |
72 | 83 | $this->reAddHardData(); |
73 | 84 | } |
74 | | - |
75 | | - private function reAddHardData(){ |
| 85 | + |
| 86 | + private function reAddHardData() { |
76 | 87 | //anywhere else, and this would constitute abuse of the system. |
77 | 88 | //so don't do it. |
78 | | - foreach ($this->hard_data as $key => $val){ |
| 89 | + foreach ( $this->hard_data as $key => $val ) { |
79 | 90 | $this->raw_data[$key] = $val; |
80 | 91 | $this->staged_data[$key] = $val; |
81 | 92 | } |
82 | 93 | } |
83 | | - |
84 | | - public function do_transaction($transaction){ |
85 | | - switch ($transaction){ |
| 94 | + |
| 95 | + public function do_transaction( $transaction ) { |
| 96 | + switch ( $transaction ) { |
86 | 97 | case 'SET_PAYMENT': |
87 | 98 | case 'CANCEL_PAYMENT': |
88 | | - self::log($this->getData_Raw('contribution_tracking_id') . ": CVV: " . $this->getData_Raw('cvv_result') . ": AVS: " . $this->getData_Raw('avs_result')); |
89 | | - //and then go on, unless you're testing, in which case: |
| 99 | + self::log( $this->getData_Raw( 'contribution_tracking_id' ) . ": CVV: " . $this->getData_Raw( 'cvv_result' ) . ": AVS: " . $this->getData_Raw( 'avs_result' ) ); |
| 100 | + //and then go on, unless you're testing, in which case: |
90 | 101 | // return "NOPE"; |
91 | 102 | // break; |
92 | 103 | default: |
93 | | - return parent::do_transaction($transaction); |
| 104 | + $ret = parent::do_transaction( $transaction ); |
| 105 | + return $ret; |
94 | 106 | break; |
95 | 107 | } |
96 | 108 | } |
97 | | - |
| 109 | + |
98 | 110 | public static function log( $msg, $log_level = LOG_INFO, $nothing = null ) { |
99 | 111 | $identifier = 'orphans:' . self::getIdentifier() . "_gateway_trxn"; |
100 | 112 | |
— | — | @@ -108,57 +120,57 @@ |
109 | 121 | syslog( $log_level, $msg ); |
110 | 122 | closelog(); |
111 | 123 | } |
112 | | - |
113 | | - public function getUTMInfoFromDB(){ |
114 | 124 | |
| 125 | + public function getUTMInfoFromDB() { |
| 126 | + |
115 | 127 | $db = ContributionTrackingProcessor::contributionTrackingConnection(); |
116 | 128 | |
117 | 129 | if ( !$db ) { |
118 | | - die("There is something terribly wrong with your Contribution Tracking database. fixit."); |
| 130 | + die( "There is something terribly wrong with your Contribution Tracking database. fixit." ); |
119 | 131 | return null; |
120 | 132 | } |
121 | | - |
122 | | - $ctid = $this->getData_Raw('contribution_tracking_id'); |
123 | | - |
124 | | - $data = array(); |
125 | 133 | |
| 134 | + $ctid = $this->getData_Raw( 'contribution_tracking_id' ); |
| 135 | + |
| 136 | + $data = array( ); |
| 137 | + |
126 | 138 | // if contrib tracking id is not already set, we need to insert the data, otherwise update |
127 | 139 | if ( $ctid ) { |
128 | | - $res = $db->select( 'contribution_tracking', |
129 | | - array( |
130 | | - 'utm_source', |
131 | | - 'utm_campaign', |
132 | | - 'utm_medium', |
133 | | - 'ts' |
134 | | - ), |
135 | | - array('id' => $ctid) |
| 140 | + $res = $db->select( |
| 141 | + 'contribution_tracking', |
| 142 | + array( |
| 143 | + 'utm_source', |
| 144 | + 'utm_campaign', |
| 145 | + 'utm_medium', |
| 146 | + 'ts' |
| 147 | + ), |
| 148 | + array( 'id' => $ctid ) |
136 | 149 | ); |
137 | | - foreach ($res as $thing){ |
| 150 | + foreach ( $res as $thing ) { |
138 | 151 | $data['utm_source'] = $thing->utm_source; |
139 | 152 | $data['utm_campaign'] = $thing->utm_campaign; |
140 | 153 | $data['utm_medium'] = $thing->utm_medium; |
141 | 154 | $data['ts'] = $thing->ts; |
142 | 155 | $msg = ''; |
143 | | - foreach ($data as $key => $val){ |
| 156 | + foreach ( $data as $key => $val ) { |
144 | 157 | $msg .= "$key = $val "; |
145 | 158 | } |
146 | | - $this->log("$ctid: Found UTM Data. $msg"); |
| 159 | + $this->log( "$ctid: Found UTM Data. $msg" ); |
147 | 160 | echo $msg; |
148 | 161 | return $data; |
149 | 162 | } |
150 | 163 | } |
151 | | - |
| 164 | + |
152 | 165 | //if we got here, we can't find anything else... |
153 | | - $this->log("$ctid: FAILED to find UTM Source value. Using default."); |
| 166 | + $this->log( "$ctid: FAILED to find UTM Source value. Using default." ); |
154 | 167 | return $data; |
155 | 168 | } |
156 | | - |
157 | | - |
| 169 | + |
158 | 170 | /** |
159 | 171 | * Copying this here because it's the fastest way to bring in an actual timestamp. |
160 | 172 | */ |
161 | 173 | protected function doStompTransaction() { |
162 | | - if ( !$this->getGlobal( 'EnableStomp' ) ){ |
| 174 | + if ( !$this->getGlobal( 'EnableStomp' ) ) { |
163 | 175 | return; |
164 | 176 | } |
165 | 177 | $this->debugarray[] = "Attempting Stomp Transaction!"; |
— | — | @@ -178,12 +190,15 @@ |
179 | 191 | $this->debugarray[] = "No Stomp Hook Found for WMF_Status $status"; |
180 | 192 | return; |
181 | 193 | } |
182 | | - |
183 | | - |
184 | | - if (!is_null($this->getData_Raw('ts'))){ |
185 | | - $timestamp = strtotime($this->getData_Raw('ts')); //I hate that this works. |
| 194 | + |
| 195 | + if ( !is_null( $this->getData_Raw( 'date' ) ) ) { |
| 196 | + $timestamp = $this->getData_Raw( 'date' ); |
186 | 197 | } else { |
187 | | - $timestamp = time(); |
| 198 | + if ( !is_null( $this->getData_Raw( 'ts' ) ) ) { |
| 199 | + $timestamp = strtotime( $this->getData_Raw( 'ts' ) ); //I hate that this works. |
| 200 | + } else { |
| 201 | + $timestamp = time(); |
| 202 | + } |
188 | 203 | } |
189 | 204 | |
190 | 205 | // send the thing. |
— | — | @@ -198,8 +213,8 @@ |
199 | 214 | try { |
200 | 215 | wfRunHooks( $hook, array( $transaction ) ); |
201 | 216 | } catch ( Exception $e ) { |
202 | | - self::log( "STOMP ERROR. Could not add message. " . $e->getMessage() , LOG_CRIT ); |
| 217 | + self::log( "STOMP ERROR. Could not add message. " . $e->getMessage(), LOG_CRIT ); |
203 | 218 | } |
204 | 219 | } |
205 | | - |
| 220 | + |
206 | 221 | } |
\ No newline at end of file |
Property changes on: branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
207 | 222 | Merged /trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php:r75657-77440,77442-79147,79149-79286,79288-79296,79298-79299,79301-79303,79305-86440,90286,92825,96120-96121,96125,97945-99042,99045-99408,99503,99555,99568,99570-101026,101056,101060,101063-101064,101071-101074,101076,101099,101109,101112,101163,101180,101192,101200,101205,101207,101217,101230,101232,101236,101335,101382,101399,101441,101501-101504,101512,101541,101547,101549,101553-101555,101557,101559,101561,101563,101576,101578-101579,101631,101633,101638,101669,101676,101679,101689,101700,101706,101719,101740,101747,101757,101764,101778-101779,101781,101785-101789,101798,101823,101826,101837,101846,101852,101870-101872,101878,101882,101890,101892,101910,101917,101929,101947,101949-101951,101955-101960,101962,101964-101966,101996,102003,102011-102012,102030,102032-102033,102047,102050-102052,102054,102056,102058,102065,102076,102081,102085-102087,102118,102120,102123-102127,102130,102134,102140,102147,102151-102152,102155-102156,102186,102188-102242,102252,102258-102261,102263,102267,102269,102307-102309,102313,102318,102332,102338,102341-102342,102345,102364,102419,102424-102425,102445,102463,102467-102468,102470,102476,102479-102480,102549-102550,102576-102581,102590,102594,102596,102611,102639,102664,102681-102682,102685,102689,102698,102700-102703,102707,102711-102712,102714,102729,102733,102736,102740,102752,102763,102805,102807,102809-102810,102812,102819-102824,102826,102828-102833,102835-102836,102841,102872,102878,102915,102921-102923,102926-102928,102932,102936,102938,102942-102943,102946,102953,102960-102961,103009,103023-103024,103026-103027,103032,103036-103038,103040,103044,103050,103058,103067,103077,103080,103130,103219,103223,103229,103235,103237-103239,103243-103247,103253,103255,103259,103261-103262,103264,103275,103278,103284,103289-103291,103325,103371,103397,103399,103401,103411,103413,103421,103434-103435,103481,103500,103503,103515,103519,103537,103541,103548,103591,103607-103608,103633,103680,103775,103784,103837,103839,103863,103866,104065,104194,104210,104243,104298,104362,104485,104587,104611,104648,104791 |
208 | 223 | Merged /branches/fundraising/deployment/payments_1.17/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php:r99568 |