Ejegg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/276222
Change subject: WIP catch errors in adapter constructors
......................................................................
WIP catch errors in adapter constructors
Think I still need to call parent SpecialPage constructor before
displaying the fail page.
Bug: T129376
Change-Id: If5fe161d80105a27cdf0350240371d204fa7c201
---
M adyen_gateway/adyen_gateway.body.php
M adyen_gateway/adyen_resultswitcher.body.php
M amazon_gateway/amazon_gateway.body.php
M astropay_gateway/astropay_gateway.body.php
M astropay_gateway/astropay_resultswitcher.body.php
M gateway_common/GatewayPage.php
M globalcollect_gateway/globalcollect_gateway.body.php
M globalcollect_gateway/globalcollect_resultswitcher.body.php
M paypal_gateway/paypal_gateway.body.php
M tests/includes/TestingGatewayPage.php
M worldpay_gateway/worldpay_gateway.body.php
M worldpay_gateway/worldpay_resultswitcher.body.php
12 files changed, 41 insertions(+), 68 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/22/276222/1
diff --git a/adyen_gateway/adyen_gateway.body.php
b/adyen_gateway/adyen_gateway.body.php
index 20c721d..8d8e15c 100644
--- a/adyen_gateway/adyen_gateway.body.php
+++ b/adyen_gateway/adyen_gateway.body.php
@@ -22,13 +22,7 @@
*/
class AdyenGateway extends GatewayPage {
- /**
- * Constructor - set up the new special page
- */
- public function __construct() {
- $this->adapter = new AdyenAdapter();
- parent::__construct(); //the next layer up will know who we are.
- }
+ protected $adapterClass = 'AdyenAdapter';
/**
* TODO: Finish Adyen error handling
diff --git a/adyen_gateway/adyen_resultswitcher.body.php
b/adyen_gateway/adyen_resultswitcher.body.php
index 8cf1f91..f789bbd 100644
--- a/adyen_gateway/adyen_resultswitcher.body.php
+++ b/adyen_gateway/adyen_resultswitcher.body.php
@@ -2,10 +2,7 @@
class AdyenGatewayResult extends GatewayPage {
- public function __construct() {
- $this->adapter = new AdyenAdapter();
- parent::__construct();
- }
+ protected $adapterClass = 'AdyenAdapter';
protected function handleRequest() {
$this->handleResultRequest();
diff --git a/amazon_gateway/amazon_gateway.body.php
b/amazon_gateway/amazon_gateway.body.php
index 41f13d1..75f60ed 100644
--- a/amazon_gateway/amazon_gateway.body.php
+++ b/amazon_gateway/amazon_gateway.body.php
@@ -17,13 +17,8 @@
*/
class AmazonGateway extends GatewayPage {
- /**
- * Constructor - set up the new special page
- */
- public function __construct() {
- $this->adapter = new AmazonAdapter();
- parent::__construct(); //the next layer up will know who we are.
- }
+
+ protected $adapterClass = 'AmazonAdapter';
/**
* Show the special page
diff --git a/astropay_gateway/astropay_gateway.body.php
b/astropay_gateway/astropay_gateway.body.php
index c3a2bb4..0203106 100644
--- a/astropay_gateway/astropay_gateway.body.php
+++ b/astropay_gateway/astropay_gateway.body.php
@@ -22,13 +22,7 @@
*/
class AstropayGateway extends GatewayPage {
- /**
- * Constructor - set up the new special page
- */
- public function __construct() {
- $this->adapter = new AstropayAdapter();
- parent::__construct(); //the next layer up will know who we are.
- }
+ protected $adapterClass = 'AstropayAdapter';
protected function handleRequest() {
$this->getOutput()->addModules(
'ext.donationinterface.astropay.scripts' );
diff --git a/astropay_gateway/astropay_resultswitcher.body.php
b/astropay_gateway/astropay_resultswitcher.body.php
index 967f720..d7cb9c7 100644
--- a/astropay_gateway/astropay_resultswitcher.body.php
+++ b/astropay_gateway/astropay_resultswitcher.body.php
@@ -2,10 +2,7 @@
class AstropayGatewayResult extends GatewayPage {
- public function __construct() {
- $this->adapter = new AstropayAdapter();
- parent::__construct();
- }
+ protected $adapterClass = 'AstropayAdapter';
protected function handleRequest() {
$this->adapter->setCurrentTransaction( 'ProcessReturn' );
diff --git a/gateway_common/GatewayPage.php b/gateway_common/GatewayPage.php
index 9202486..9d8dfff 100644
--- a/gateway_common/GatewayPage.php
+++ b/gateway_common/GatewayPage.php
@@ -25,6 +25,10 @@
*
*/
abstract class GatewayPage extends UnlistedSpecialPage {
+
+ // Derived classes should override this
+ protected $adapterClass;
+
/**
* An array of form errors
* @var array $errors
@@ -47,11 +51,23 @@
* Constructor
*/
public function __construct() {
- $this->logger = DonationLoggerFactory::getLogger(
$this->adapter );
- $this->getOutput()->addModules(
'donationInterface.skinOverride' );
-
- $me = get_called_class();
- parent::__construct( $me );
+ try {
+ $this->adapter = new $this->adapterClass;
+ $this->logger = DonationLoggerFactory::getLogger(
$this->adapter );
+ $this->getOutput()->addModules(
'donationInterface.skinOverride' );
+
+ $me = get_called_class();
+ parent::__construct( $me );
+ } catch ( Exception $ex ) {
+ if ( !$this->logger ) {
+ $this->logger =
DonationLoggerFactory::getLogger();
+ }
+ $this->logger->error(
+ "Exception in GatewayPage constructor with
adapter class {$this->adapterClass}",
+ array( $ex )
+ );
+ $this->displayFailPage();
+ }
}
/**
@@ -139,8 +155,11 @@
public function displayFailPage() {
$output = $this->getOutput();
- $page = ResultPages::getFailPage( $this->adapter );
-
+ if ( $this->adapter ) {
+ $page = ResultPages::getFailPage( $this->adapter );
+ } else {
+ $page = ResultPages::getFailPage( $this->adapterClass );
+ }
$log_message = "Redirecting to [{$page}]";
$this->logger->info( $log_message );
diff --git a/globalcollect_gateway/globalcollect_gateway.body.php
b/globalcollect_gateway/globalcollect_gateway.body.php
index ac2d6fe..5823ebb 100644
--- a/globalcollect_gateway/globalcollect_gateway.body.php
+++ b/globalcollect_gateway/globalcollect_gateway.body.php
@@ -21,13 +21,8 @@
*
*/
class GlobalCollectGateway extends GatewayPage {
- /**
- * Constructor - set up the new special page
- */
- public function __construct() {
- $this->adapter = new GlobalCollectAdapter();
- parent::__construct(); //the next layer up will know who we are.
- }
+
+ protected $adapterClass = 'GlobalCollectAdapter';
/**
* Show the special page
diff --git a/globalcollect_gateway/globalcollect_resultswitcher.body.php
b/globalcollect_gateway/globalcollect_resultswitcher.body.php
index ad84991..c72903a 100644
--- a/globalcollect_gateway/globalcollect_resultswitcher.body.php
+++ b/globalcollect_gateway/globalcollect_resultswitcher.body.php
@@ -23,13 +23,7 @@
protected $qs_oid = null;
- /**
- * Constructor - set up the new special page
- */
- public function __construct() {
- $this->adapter = new GlobalCollectAdapter();
- parent::__construct(); //the next layer up will know who we
are.
- }
+ protected $adapterClass = 'GlobalCollectAdapter';
/**
* Show the special page
diff --git a/paypal_gateway/paypal_gateway.body.php
b/paypal_gateway/paypal_gateway.body.php
index 77b7764..0436c5e 100644
--- a/paypal_gateway/paypal_gateway.body.php
+++ b/paypal_gateway/paypal_gateway.body.php
@@ -18,13 +18,7 @@
class PaypalGateway extends GatewayPage {
- /**
- * Constructor - set up the new special page
- */
- public function __construct() {
- $this->adapter = new PaypalAdapter();
- parent::__construct(); // the next layer up will know who we
are.
- }
+ protected $adapterClass = 'PaypalAdapter';
/**
* Show the special page
diff --git a/tests/includes/TestingGatewayPage.php
b/tests/includes/TestingGatewayPage.php
index 94b7ba5..73e33d4 100644
--- a/tests/includes/TestingGatewayPage.php
+++ b/tests/includes/TestingGatewayPage.php
@@ -1,6 +1,9 @@
<?php
class TestingGatewayPage extends GatewayPage {
+
+ protected $adapterClass = TESTS_ADAPTER_DEFAULT;
+
public function __construct() {
$this->logger = DonationLoggerFactory::getLogger();
//nothing!
diff --git a/worldpay_gateway/worldpay_gateway.body.php
b/worldpay_gateway/worldpay_gateway.body.php
index bc336c8..1de552d 100644
--- a/worldpay_gateway/worldpay_gateway.body.php
+++ b/worldpay_gateway/worldpay_gateway.body.php
@@ -22,13 +22,7 @@
*/
class WorldpayGateway extends GatewayPage {
- /**
- * Constructor - set up the new special page
- */
- public function __construct() {
- $this->adapter = new WorldpayAdapter();
- parent::__construct();
- }
+ protected $adapterClass = 'WorldpayAdapter';
/**
* Show the special page
diff --git a/worldpay_gateway/worldpay_resultswitcher.body.php
b/worldpay_gateway/worldpay_resultswitcher.body.php
index a37ec75..2a6ee32 100644
--- a/worldpay_gateway/worldpay_resultswitcher.body.php
+++ b/worldpay_gateway/worldpay_resultswitcher.body.php
@@ -2,10 +2,7 @@
class WorldpayGatewayResult extends GatewayPage {
- public function __construct() {
- $this->adapter = new WorldpayAdapter();
- parent::__construct();
- }
+ protected $adapterClass = 'WorldpayAdapter';
protected function handleRequest() {
// Break out of the iframe, signal to skip this next time, and
reload.
--
To view, visit https://gerrit.wikimedia.org/r/276222
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If5fe161d80105a27cdf0350240371d204fa7c201
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits