jenkins-bot has submitted this change and it was merged.
Change subject: Add push and pop fns to DonationLoggerContext
......................................................................
Add push and pop fns to DonationLoggerContext
This way, child classes can selectively override parts of the
parent class's log context. Demonstrated in this commit with the
GlobalCollect orphan adapter.
Bug: T86266
Change-Id: I3fa9b5e503c41240955db1c64bd05d2b6402e480
---
M gateway_common/DonationLoggerContext.php
M globalcollect_gateway/scripts/orphan_adapter.php
M globalcollect_gateway/scripts/orphans.php
3 files changed, 48 insertions(+), 38 deletions(-)
Approvals:
Awight: Looks good to me, approved
jenkins-bot: Verified
diff --git a/gateway_common/DonationLoggerContext.php
b/gateway_common/DonationLoggerContext.php
index 2296091..40f0555 100644
--- a/gateway_common/DonationLoggerContext.php
+++ b/gateway_common/DonationLoggerContext.php
@@ -48,10 +48,10 @@
static protected $settingsStack;
/**
- * The key of the current instance's config in $settingsStack
- * @var int
+ * Settings added by the current instance
+ * @var array
*/
- protected $localSettingsKey;
+ protected $localSettings = array();
/**
* Initializes settingsStack and public properties with default values
@@ -76,16 +76,48 @@
*/
public function __construct( $config ) {
self::initialize();
+ $this->pushSettings( $config );
+ }
+
+ /**
+ * Allows a class that already has a context instance to selectively
+ * override certain properties
+ * @param array $config
+ * @see __construct
+ */
+ public function pushSettings( $config ) {
self::$settingsStack[] = $config;
- $this->localSettingsKey = array_search( $config,
self::$settingsStack, true );
+ array_push( $this->localSettings, $config );
self::setCurrent();
}
- public function __destruct() {
- if ( isset( $this->localSettingsKey ) ) {
- unset( self::$settingsStack[$this->localSettingsKey] );
- self::setCurrent();
+ /**
+ * Undo the last pushSettings. If you call it too many times, it'll
even
+ * undo the settings you used to construct this instance. But that's
wierd.
+ * @return array The settings you just removed
+ */
+ public function popSettings() {
+ if ( !$this->localSettings ) {
+ throw new MWException( 'Bad programmer! You called
popSettings at least one too many times!' );
}
+ $config = $this->popInternal();
+ self::setCurrent();
+ return $config;
+ }
+
+ public function __destruct() {
+ while ( $this->localSettings ) {
+ $this->popInternal();
+ }
+ self::setCurrent();
+ }
+
+ protected function popInternal() {
+ $config = array_pop( $this->localSettings );
+ // strict search to find same array instance
+ $index = array_search( $config, self::$settingsStack, true );
+ unset( self::$settingsStack[$index] );
+ return $config;
}
/**
diff --git a/globalcollect_gateway/scripts/orphan_adapter.php
b/globalcollect_gateway/scripts/orphan_adapter.php
index 356e3f0..4ef802d 100644
--- a/globalcollect_gateway/scripts/orphan_adapter.php
+++ b/globalcollect_gateway/scripts/orphan_adapter.php
@@ -8,6 +8,9 @@
public function __construct() {
$this->batch = true; //always batch if we're using this object.
parent::__construct( $options = array ( ) );
+ $this->loggerContext->pushSettings( array(
+ 'identifier' => 'orphans:' . self::getIdentifier() .
"_gateway_trxn"
+ ) );
}
public function unstage_data( $data = array( ), $final = true ) {
@@ -97,31 +100,6 @@
$this->unstaged_data[$key] = $val;
$this->staged_data[$key] = $val;
}
- }
-
- /**
- * Unfortunate, but we have to overload this here, or change the way we
- * build that identifier.
- * @param string $msg
- * @param type $log_level
- * @param type $nothing
- * @return type
- */
- public function log( $msg, $log_level = LOG_INFO, $nothing = null ) {
- $identifier = 'orphans:' . self::getIdentifier() .
"_gateway_trxn";
-
- $msg = $this->getLogMessagePrefix() . $msg;
-
- // if we're not using the syslog facility, use wfDebugLog
- if ( !self::getGlobal( 'UseSyslog' ) ) {
- WmfFramework::debugLog( $identifier, $msg );
- return;
- }
-
- // otherwise, use syslogging
- openlog( $identifier, LOG_ODELAY, LOG_SYSLOG );
- syslog( $log_level, $msg );
- closelog();
}
public function getUTMInfoFromDB() {
diff --git a/globalcollect_gateway/scripts/orphans.php
b/globalcollect_gateway/scripts/orphans.php
index c3bb793..c879e62 100644
--- a/globalcollect_gateway/scripts/orphans.php
+++ b/globalcollect_gateway/scripts/orphans.php
@@ -88,7 +88,7 @@
sleep(2); //two seconds.
}
}
- $this->adapter->log( 'Removed ' . $this->removed_message_count
. ' messages and antimessages.' );
+ DonationLogger::log( 'Removed ' . $this->removed_message_count
. ' messages and antimessages.' );
if ( $this->keepGoing() ){
//Pull a batch of CC orphans, keeping in mind that
Things May Have Happened in the small slice of time since we handled the
antimessages.
@@ -149,7 +149,7 @@
}
}
$final .= "\n Approximately " . $this->getProcessElapsed() . "
seconds to execute.\n";
- $this->adapter->log($final);
+ DonationLogger::log($final);
echo $final;
}
@@ -217,7 +217,7 @@
$antimessages = stompFetchMessages( 'cc-limbo',
$selector, 1000 );
}
$this->addStompCorrelationIDToAckBucket( false, true ); //this
just acks everything that's waiting for it.
- $this->adapter->log("Found $count antimessages.");
+ DonationLogger::log("Found $count antimessages.");
return $count;
}
@@ -355,10 +355,10 @@
$this->adapter->loadDataAndReInit( $data,
$query_contribution_tracking );
$results = $this->adapter->do_transaction( 'Confirm_CreditCard'
);
if ($results['status']){
- $this->adapter->log( $data['contribution_tracking_id']
. ": FINAL: " . $results['action'] );
+ DonationLogger::log( $data['contribution_tracking_id']
. ": FINAL: " . $results['action'] );
$rectified = true;
} else {
- $this->adapter->log( $data['contribution_tracking_id']
. ": ERROR: " . $results['message'] );
+ DonationLogger::log( $data['contribution_tracking_id']
. ": ERROR: " . $results['message'] );
if ( strpos( $results['message'], "GET_ORDERSTATUS
reports that the payment is already complete." ) === 0 ){
$rectified = true;
}
--
To view, visit https://gerrit.wikimedia.org/r/190134
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3fa9b5e503c41240955db1c64bd05d2b6402e480
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits