r101837 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101836‎ | r101837 | r101838 >
Date:17:39, 3 November 2011
Author:khorn
Status:ok
Tags:
Comment:
Fixes up the new addData function in the adapter, to handle things like re-calculated fields in the DD object, and restaging data if we ever have to as a result of certain keys changing.
r101787
Modified paths:
  • /trunk/extensions/DonationInterface/gateway_common/DonationData.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -277,6 +277,23 @@
278278 */
279279 public function addData( $dataArray ) {
280280 $this->dataObj->addData( $dataArray );
 281+
 282+ $calculated_fields = $this->dataObj->getCalculatedFields();
 283+ $data_fields = array_keys( $dataArray );
 284+ $data_fields = array_merge( $data_fields, $calculated_fields );
 285+
 286+ foreach ( $data_fields as $value){
 287+ $this->refreshGatewayValueFromSource( $value );
 288+ }
 289+
 290+ //and now check to see if you have to re-stage.
 291+ //I'd fire off individual staging functions by value, but that's a
 292+ //really bad idea, as multiple staged vars could be used in any staging
 293+ //function, to calculate any other staged var.
 294+ $changed_staged_vars = array_intersect( $this->staged_vars, $data_fields );
 295+ if ( count( $changed_staged_vars ) ) {
 296+ $this->stageData();
 297+ }
281298 }
282299
283300 /**
@@ -1313,24 +1330,15 @@
13141331 }
13151332
13161333 function getPaypalRedirectURL() {
1317 - $utm_source = $this->getData( 'utm_source' );
 1334+ $currency = $this->getData( 'currency' );
13181335
13191336 // update the utm source to set the payment instrument to pp rather than cc
13201337 $data['payment_method'] = 'pp';
1321 - $data['currency_code'] = isset( $data['currency'] ) ? $data['currency'] : 'USD';
 1338+ $data['currency_code'] = ( !is_null( $currency ) ) ? $currency : 'USD';
13221339
1323 - // Add our response vars to the data object.
1324 - $this->dataObj->addData( $data ); //addData will, among other things, rebuild the utm_[stuff].
1325 - // refresh our data
1326 - foreach ( $data as $key => $value){
1327 - $this->refreshGatewayValueFromSource( $key );
1328 - }
1329 - //TODO: Make an array of calculated fields in DonationData...
1330 - //in other words: Fields that will get recalculated on a normalizeAndSanitize()...
1331 - //so we don't have to _know_ to do this, when we add data.
1332 - //In fact, put that in addData, and restage anything that's either the explicit key,
1333 - //or any of the calculated keys.
1334 - $this->refreshGatewayValueFromSource( 'utm_source' ); //calculated field!
 1340+ // Add our response vars to the data object, and restage if necessary.
 1341+ $this->addData( $data );
 1342+
13351343 //update contribution tracking
13361344 $this->dataObj->updateContributionTracking( true );
13371345
Index: trunk/extensions/DonationInterface/gateway_common/DonationData.php
@@ -245,7 +245,33 @@
246246 unset( $this->normalized[$key] );
247247 }
248248 }
 249+
 250+ /**
 251+ * Returns an array of all the fields that get re-calculated during a
 252+ * normalizeAndSanitize.
 253+ * This will most likely be used on the outside when in the process of
 254+ * adding data.
 255+ * @return array An array of values matching all recauculated fields.
 256+ */
 257+ function getCalculatedFields() {
 258+ $fields = array(
 259+ 'utm_source',
 260+ 'amount',
 261+ 'order_id',
 262+ 'i_order_id',
 263+ 'gateway',
 264+ 'optout',
 265+ 'anonymous',
 266+ 'language',
 267+ 'contribution_tracking_id', //sort of...
 268+ );
 269+ return $fields;
 270+ }
249271
 272+ /**
 273+ * Normalizes and Sanitizes the current set of data, just after it's been
 274+ * pulled (or re-pulled) from a source.
 275+ */
250276 function normalizeAndSanitize() {
251277 if ( !empty( $this->normalized ) ) {
252278 $this->setUtmSource();

Follow-up revisions

RevisionCommit summaryAuthorDate
r102236MFT r90286, r100671, r100837, r100950, r101060, r101063, r101064, r101073, r1......khorn03:06, 7 November 2011
r102237MFT r90286, r100671, r100837, r100950, r101060, r101063, r101064, r101073, r1......khorn03:07, 7 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101787way smarter way to handle the failure messages from GlobalCollectkaldari04:36, 3 November 2011

Status & tagging log