r103503 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103502‎ | r103503 | r103504 >
Date:20:23, 17 November 2011
Author:khorn
Status:ok
Tags:
Comment:
GlobalCollect command-line orphan rectifier: Cleaning up some weird-o formatting.
Modified paths:
  • /trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
@@ -1,18 +1,18 @@
22 <?php
33
44 class GlobalCollectOrphanAdapter extends GlobalCollectAdapter {
5 -
 5+
66 //Data we know to be good, that we always want to re-assert after a load or an addData.
77 //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( );
99
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 ) ) {
1414 $unstaged += $this->unstage_data( $val, false );
1515 } else {
16 - if (array_key_exists($key, $this->var_map)){
 16+ if ( array_key_exists( $key, $this->var_map ) ) {
1717 //run the unstage data functions.
1818 $unstaged[$this->var_map[$key]] = $val;
1919 //this would be EXTREMELY bad to put in the regular adapter.
@@ -22,36 +22,35 @@
2323 }
2424 }
2525 }
26 - if ($final){
27 - $this->stageData('response');
 26+ if ( $final ) {
 27+ $this->stageData( 'response' );
2828 }
29 - foreach ($unstaged as $key=>$val){
 29+ foreach ( $unstaged as $key => $val ) {
3030 $unstaged[$key] = $this->staged_data[$key];
3131 }
3232 return $unstaged;
3333 }
34 -
35 - public function loadDataAndReInit( $data ){
 34+
 35+ public function loadDataAndReInit( $data ) {
3636 $this->batch = true; //or the hooks will accumulate badness.
37 -
3837 //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+
4443 $this->hard_data['order_id'] = $data['order_id'];
4544 $this->hard_data['i_order_id'] = $data['order_id'];
46 -
 45+
4746 $this->dataObj = new DonationData( get_called_class(), false, $data );
4847
4948 $this->raw_data = $this->dataObj->getData();
50 -
 49+
5150 $this->hard_data = array_merge( $this->hard_data, $this->getUTMInfoFromDB() );
5251 $this->reAddHardData();
53 -
 52+
5453 $this->staged_data = $this->raw_data;
55 -
 54+
5655 $this->setPostDefaults();
5756 $this->defineTransactions();
5857 $this->defineErrorMap();
@@ -61,39 +60,39 @@
6261 $this->defineReturnValueMap();
6362
6463 $this->stageData();
65 -
 64+
6665 //have to do this again here.
6766 $this->reAddHardData();
6867 }
69 -
70 - public function addData($dataArray){
71 - parent::addData($dataArray);
 68+
 69+ public function addData( $dataArray ) {
 70+ parent::addData( $dataArray );
7271 $this->reAddHardData();
7372 }
74 -
75 - private function reAddHardData(){
 73+
 74+ private function reAddHardData() {
7675 //anywhere else, and this would constitute abuse of the system.
7776 //so don't do it.
78 - foreach ($this->hard_data as $key => $val){
 77+ foreach ( $this->hard_data as $key => $val ) {
7978 $this->raw_data[$key] = $val;
8079 $this->staged_data[$key] = $val;
8180 }
8281 }
83 -
84 - public function do_transaction($transaction){
85 - switch ($transaction){
 82+
 83+ public function do_transaction( $transaction ) {
 84+ switch ( $transaction ) {
8685 case 'SET_PAYMENT':
8786 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:
9089 // return "NOPE";
9190 // break;
9291 default:
93 - return parent::do_transaction($transaction);
 92+ return parent::do_transaction( $transaction );
9493 break;
9594 }
9695 }
97 -
 96+
9897 public static function log( $msg, $log_level = LOG_INFO, $nothing = null ) {
9998 $identifier = 'orphans:' . self::getIdentifier() . "_gateway_trxn";
10099
@@ -108,57 +107,57 @@
109108 syslog( $log_level, $msg );
110109 closelog();
111110 }
112 -
113 - public function getUTMInfoFromDB(){
114111
 112+ public function getUTMInfoFromDB() {
 113+
115114 $db = ContributionTrackingProcessor::contributionTrackingConnection();
116115
117116 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." );
119118 return null;
120119 }
121 -
122 - $ctid = $this->getData_Raw('contribution_tracking_id');
123 -
124 - $data = array();
125120
 121+ $ctid = $this->getData_Raw( 'contribution_tracking_id' );
 122+
 123+ $data = array( );
 124+
126125 // if contrib tracking id is not already set, we need to insert the data, otherwise update
127126 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 )
136136 );
137 - foreach ($res as $thing){
 137+ foreach ( $res as $thing ) {
138138 $data['utm_source'] = $thing->utm_source;
139139 $data['utm_campaign'] = $thing->utm_campaign;
140140 $data['utm_medium'] = $thing->utm_medium;
141141 $data['ts'] = $thing->ts;
142142 $msg = '';
143 - foreach ($data as $key => $val){
 143+ foreach ( $data as $key => $val ) {
144144 $msg .= "$key = $val ";
145145 }
146 - $this->log("$ctid: Found UTM Data. $msg");
 146+ $this->log( "$ctid: Found UTM Data. $msg" );
147147 echo $msg;
148148 return $data;
149149 }
150150 }
151 -
 151+
152152 //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." );
154154 return $data;
155155 }
156 -
157 -
 156+
158157 /**
159158 * Copying this here because it's the fastest way to bring in an actual timestamp.
160159 */
161160 protected function doStompTransaction() {
162 - if ( !$this->getGlobal( 'EnableStomp' ) ){
 161+ if ( !$this->getGlobal( 'EnableStomp' ) ) {
163162 return;
164163 }
165164 $this->debugarray[] = "Attempting Stomp Transaction!";
@@ -178,10 +177,10 @@
179178 $this->debugarray[] = "No Stomp Hook Found for WMF_Status $status";
180179 return;
181180 }
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.
186185 } else {
187186 $timestamp = time();
188187 }
@@ -198,8 +197,8 @@
199198 try {
200199 wfRunHooks( $hook, array( $transaction ) );
201200 } 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 );
203202 }
204203 }
205 -
 204+
206205 }
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r103847MFT r102338, r102681, r102685, r102810, r102828, r102829, r102832, r102836, r...khorn22:30, 21 November 2011
r103848MFT r102338, r102681, r102685, r102810, r102828, r102829, r102832, r102836, r...khorn22:31, 21 November 2011
r105502MFT r103501, r103503, r104648, r104791, r104933khorn00:45, 8 December 2011

Status & tagging log