r99280 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99279‎ | r99280 | r99281 >
Date:23:18, 7 October 2011
Author:khorn
Status:ok
Tags:fundraising 
Comment:
Cleaning up the $this->boss mess in DonationData, and in the process found something else we should be doing with the pre-process hooks.
r96644
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/gateway_common/DonationData.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/gateway_common/DonationData.php
@@ -14,6 +14,7 @@
1515 //TODO: Actually think about this bit.
1616 // ...and keep in mind we can re-populate if it's a test or whatever. (But that may not be a good idea either)
1717 $this->boss = $owning_class;
 18+ $this->gatewayID = $this->getGatewayIdentifier();
1819 $this->populateData( $test, $data );
1920 }
2021
@@ -275,21 +276,34 @@
276277 }
277278
278279 function log( $message, $log_level=LOG_INFO ) {
279 - if ( class_exists( $this->boss ) ) {
280 - $c = $this->boss;
 280+ $c = $this->getAdapterClass();
 281+ if ( $c && is_callable( array( $c, 'log' ) )){
281282 $c::log( $message, $log_level );
282283 }
283284 }
 285+
 286+ function getGatewayIdentifier() {
 287+ $c = $this->getAdapterClass();
 288+ if ( $c && is_callable( array( $c, 'getIdentifier' ) ) ){
 289+ return $c::getIdentifier();
 290+ } else {
 291+ return 'DonationData';
 292+ }
 293+ }
 294+
 295+ function getGatewayGlobal( $varname ) {
 296+ $c = $this->getAdapterClass();
 297+ if ( $c && is_callable( array( $c, 'getGlobal' ) ) ){
 298+ return $c::getGlobal( $varname );
 299+ } else {
 300+ return false;
 301+ }
 302+ }
284303
285304 function setGateway() {
286305 //TODO: Hum. If we have some other gateway in the form data, should we go crazy here? (Probably)
287 - if ( class_exists( $this->boss ) ) {
288 - $c = $this->boss;
289 - if ( is_callable( array( $c, 'getIdentifier' ) ) ) {
290 - $gateway = $c::getIdentifier();
291 - $this->setVal( 'gateway', $gateway );
292 - }
293 - }
 306+ $gateway = $this->gatewayID;
 307+ $this->setVal( 'gateway', $gateway );
294308 }
295309
296310 function doCacheStuff() {
@@ -304,14 +318,11 @@
305319
306320 // if we have squid caching enabled, set the maxage
307321 global $wgUseSquid, $wgOut;
308 - if ( class_exists( $this->boss ) ) {
309 - $g = $this->boss; //the 'g' is for "Gateway"!
310 - $maxAge = $g::getGlobal( 'SMaxAge' );
 322+ $maxAge = $this->getGatewayGlobal( 'SMaxAge' );
311323
312 - if ( $wgUseSquid ) {
313 - self::log( $this->getAnnoyingOrderIDLogLinePrefix() . ' Setting s-max-age: ' . $maxAge, LOG_DEBUG );
314 - $wgOut->setSquidMaxage( $maxAge );
315 - }
 324+ if ( $wgUseSquid && ( $maxAge !== false ) ) {
 325+ self::log( $this->getAnnoyingOrderIDLogLinePrefix() . ' Setting s-max-age: ' . $maxAge, LOG_DEBUG );
 326+ $wgOut->setSquidMaxage( $maxAge );
316327 }
317328 } else {
318329 $this->cache = false; //TODO: Kill this one in the face, too. (see above)
@@ -341,12 +352,7 @@
342353 // make sure we have a session open for tracking a CSRF-prevention token
343354 self::ensureSession();
344355
345 - if ( class_exists( $this->boss ) ) {
346 - $g = $this->boss;
347 - $gateway_ident = $g::getIdentifier();
348 - } else {
349 - $gateway_ident = 'DonationData';
350 - }
 356+ $gateway_ident = $this->gatewayID;
351357
352358 if ( !isset( $_SESSION[$gateway_ident . 'EditToken'] ) ) {
353359 // generate unsalted token to place in the session
@@ -395,12 +401,8 @@
396402 * Unset the payflow edit token from a user's session
397403 */
398404 function unsetEditToken() {
399 - if ( class_exists( $this->boss ) ) {
400 - $g = $this->boss;
401 - $gateway_ident = $g::getIdentifier();
402 - } else {
403 - $gateway_ident = "DonationData";
404 - }
 405+ $gateway_ident = $this->gatewayID;
 406+
405407 if ( isset( $_SESSION ) && isset( $_SESSION[$gateway_ident . 'EditToken'] ) ){
406408 unset( $_SESSION[$gateway_ident . 'EditToken'] );
407409 }
@@ -425,10 +427,8 @@
426428 static $match = null;
427429
428430 if ( $match === null ) {
429 - if ( class_exists( $this->boss ) ) {
430 - $g = $this->boss;
431 - $salt = $g::getGlobal( 'Salt' );
432 - } else {
 431+ $salt = $this->getGatewayGlobal( 'Salt' );
 432+ if ( $salt === false ){
433433 $salt = 'gotToBeInAUnitTest';
434434 }
435435
@@ -713,6 +713,14 @@
714714 }
715715 }
716716 }
 717+
 718+ function getAdapterClass(){
 719+ if ( class_exists( $this->boss ) ) {
 720+ return $this->boss;
 721+ } else {
 722+ return false;
 723+ }
 724+ }
717725
718726 }
719727
Index: branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -1147,6 +1147,11 @@
11481148
11491149 function runPreProcess() {
11501150 if ( $this->transaction_option( 'do_validation' ) ) {
 1151+ if ( !isset( $wgHooks['GatewayValidate'] ) ) {
 1152+ //if there ARE no validate hooks, we're okay.
 1153+ $this->action = 'process';
 1154+ return;
 1155+ }
11511156 // allow any external validators to have their way with the data
11521157 self::log( $this->getData( 'order_id' ) . " Preparing to query MaxMind" );
11531158 wfRunHooks( 'GatewayValidate', array( &$this ) );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96644Added more unit tests to DonationInterface.khorn02:47, 9 September 2011

Status & tagging log