Index: trunk/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,35 @@ |
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 ) { |
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 | | - |
| 49 | + |
51 | 50 | $this->hard_data = array_merge( $this->hard_data, $this->getUTMInfoFromDB() ); |
52 | 51 | $this->reAddHardData(); |
53 | | - |
| 52 | + |
54 | 53 | $this->staged_data = $this->raw_data; |
55 | | - |
| 54 | + |
56 | 55 | $this->setPostDefaults(); |
57 | 56 | $this->defineTransactions(); |
58 | 57 | $this->defineErrorMap(); |
— | — | @@ -61,39 +60,39 @@ |
62 | 61 | $this->defineReturnValueMap(); |
63 | 62 | |
64 | 63 | $this->stageData(); |
65 | | - |
| 64 | + |
66 | 65 | //have to do this again here. |
67 | 66 | $this->reAddHardData(); |
68 | 67 | } |
69 | | - |
70 | | - public function addData($dataArray){ |
71 | | - parent::addData($dataArray); |
| 68 | + |
| 69 | + public function addData( $dataArray ) { |
| 70 | + parent::addData( $dataArray ); |
72 | 71 | $this->reAddHardData(); |
73 | 72 | } |
74 | | - |
75 | | - private function reAddHardData(){ |
| 73 | + |
| 74 | + private function reAddHardData() { |
76 | 75 | //anywhere else, and this would constitute abuse of the system. |
77 | 76 | //so don't do it. |
78 | | - foreach ($this->hard_data as $key => $val){ |
| 77 | + foreach ( $this->hard_data as $key => $val ) { |
79 | 78 | $this->raw_data[$key] = $val; |
80 | 79 | $this->staged_data[$key] = $val; |
81 | 80 | } |
82 | 81 | } |
83 | | - |
84 | | - public function do_transaction($transaction){ |
85 | | - switch ($transaction){ |
| 82 | + |
| 83 | + public function do_transaction( $transaction ) { |
| 84 | + switch ( $transaction ) { |
86 | 85 | case 'SET_PAYMENT': |
87 | 86 | 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: |
| 87 | + self::log( $this->getData_Raw( 'contribution_tracking_id' ) . ": CVV: " . $this->getData_Raw( 'cvv_result' ) . ": AVS: " . $this->getData_Raw( 'avs_result' ) ); |
| 88 | + //and then go on, unless you're testing, in which case: |
90 | 89 | // return "NOPE"; |
91 | 90 | // break; |
92 | 91 | default: |
93 | | - return parent::do_transaction($transaction); |
| 92 | + return parent::do_transaction( $transaction ); |
94 | 93 | break; |
95 | 94 | } |
96 | 95 | } |
97 | | - |
| 96 | + |
98 | 97 | public static function log( $msg, $log_level = LOG_INFO, $nothing = null ) { |
99 | 98 | $identifier = 'orphans:' . self::getIdentifier() . "_gateway_trxn"; |
100 | 99 | |
— | — | @@ -108,57 +107,57 @@ |
109 | 108 | syslog( $log_level, $msg ); |
110 | 109 | closelog(); |
111 | 110 | } |
112 | | - |
113 | | - public function getUTMInfoFromDB(){ |
114 | 111 | |
| 112 | + public function getUTMInfoFromDB() { |
| 113 | + |
115 | 114 | $db = ContributionTrackingProcessor::contributionTrackingConnection(); |
116 | 115 | |
117 | 116 | if ( !$db ) { |
118 | | - die("There is something terribly wrong with your Contribution Tracking database. fixit."); |
| 117 | + die( "There is something terribly wrong with your Contribution Tracking database. fixit." ); |
119 | 118 | return null; |
120 | 119 | } |
121 | | - |
122 | | - $ctid = $this->getData_Raw('contribution_tracking_id'); |
123 | | - |
124 | | - $data = array(); |
125 | 120 | |
| 121 | + $ctid = $this->getData_Raw( 'contribution_tracking_id' ); |
| 122 | + |
| 123 | + $data = array( ); |
| 124 | + |
126 | 125 | // if contrib tracking id is not already set, we need to insert the data, otherwise update |
127 | 126 | 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) |
| 127 | + $res = $db->select( |
| 128 | + 'contribution_tracking', |
| 129 | + array( |
| 130 | + 'utm_source', |
| 131 | + 'utm_campaign', |
| 132 | + 'utm_medium', |
| 133 | + 'ts' |
| 134 | + ), |
| 135 | + array( 'id' => $ctid ) |
136 | 136 | ); |
137 | | - foreach ($res as $thing){ |
| 137 | + foreach ( $res as $thing ) { |
138 | 138 | $data['utm_source'] = $thing->utm_source; |
139 | 139 | $data['utm_campaign'] = $thing->utm_campaign; |
140 | 140 | $data['utm_medium'] = $thing->utm_medium; |
141 | 141 | $data['ts'] = $thing->ts; |
142 | 142 | $msg = ''; |
143 | | - foreach ($data as $key => $val){ |
| 143 | + foreach ( $data as $key => $val ) { |
144 | 144 | $msg .= "$key = $val "; |
145 | 145 | } |
146 | | - $this->log("$ctid: Found UTM Data. $msg"); |
| 146 | + $this->log( "$ctid: Found UTM Data. $msg" ); |
147 | 147 | echo $msg; |
148 | 148 | return $data; |
149 | 149 | } |
150 | 150 | } |
151 | | - |
| 151 | + |
152 | 152 | //if we got here, we can't find anything else... |
153 | | - $this->log("$ctid: FAILED to find UTM Source value. Using default."); |
| 153 | + $this->log( "$ctid: FAILED to find UTM Source value. Using default." ); |
154 | 154 | return $data; |
155 | 155 | } |
156 | | - |
157 | | - |
| 156 | + |
158 | 157 | /** |
159 | 158 | * Copying this here because it's the fastest way to bring in an actual timestamp. |
160 | 159 | */ |
161 | 160 | protected function doStompTransaction() { |
162 | | - if ( !$this->getGlobal( 'EnableStomp' ) ){ |
| 161 | + if ( !$this->getGlobal( 'EnableStomp' ) ) { |
163 | 162 | return; |
164 | 163 | } |
165 | 164 | $this->debugarray[] = "Attempting Stomp Transaction!"; |
— | — | @@ -178,10 +177,10 @@ |
179 | 178 | $this->debugarray[] = "No Stomp Hook Found for WMF_Status $status"; |
180 | 179 | return; |
181 | 180 | } |
182 | | - |
183 | | - |
184 | | - if (!is_null($this->getData_Raw('ts'))){ |
185 | | - $timestamp = strtotime($this->getData_Raw('ts')); //I hate that this works. |
| 181 | + |
| 182 | + |
| 183 | + if ( !is_null( $this->getData_Raw( 'ts' ) ) ) { |
| 184 | + $timestamp = strtotime( $this->getData_Raw( 'ts' ) ); //I hate that this works. |
186 | 185 | } else { |
187 | 186 | $timestamp = time(); |
188 | 187 | } |
— | — | @@ -198,8 +197,8 @@ |
199 | 198 | try { |
200 | 199 | wfRunHooks( $hook, array( $transaction ) ); |
201 | 200 | } catch ( Exception $e ) { |
202 | | - self::log( "STOMP ERROR. Could not add message. " . $e->getMessage() , LOG_CRIT ); |
| 201 | + self::log( "STOMP ERROR. Could not add message. " . $e->getMessage(), LOG_CRIT ); |
203 | 202 | } |
204 | 203 | } |
205 | | - |
| 204 | + |
206 | 205 | } |
\ No newline at end of file |