Ejegg has uploaded a new change for review. https://gerrit.wikimedia.org/r/192382
Change subject: Revert "Add push and pop fns to DonationLoggerContext" ...................................................................... Revert "Add push and pop fns to DonationLoggerContext" Static logging calls = not awesome This reverts commit 36e3ddbae060395c90e6ced092027115c719014f. Bug: T86266 Change-Id: Ie7b71c99a870af4d9734ccf807ee82935bd54f1d --- M gateway_common/DonationLoggerContext.php M globalcollect_gateway/scripts/orphan_adapter.php M globalcollect_gateway/scripts/orphans.php 3 files changed, 37 insertions(+), 47 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/82/192382/1 diff --git a/gateway_common/DonationLoggerContext.php b/gateway_common/DonationLoggerContext.php index 40f0555..2296091 100644 --- a/gateway_common/DonationLoggerContext.php +++ b/gateway_common/DonationLoggerContext.php @@ -48,10 +48,10 @@ static protected $settingsStack; /** - * Settings added by the current instance - * @var array + * The key of the current instance's config in $settingsStack + * @var int */ - protected $localSettings = array(); + protected $localSettingsKey; /** * Initializes settingsStack and public properties with default values @@ -76,48 +76,16 @@ */ 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; - array_push( $this->localSettings, $config ); + $this->localSettingsKey = array_search( $config, self::$settingsStack, true ); 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(); + if ( isset( $this->localSettingsKey ) ) { + unset( self::$settingsStack[$this->localSettingsKey] ); + self::setCurrent(); } - 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 4ef802d..356e3f0 100644 --- a/globalcollect_gateway/scripts/orphan_adapter.php +++ b/globalcollect_gateway/scripts/orphan_adapter.php @@ -8,9 +8,6 @@ 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 ) { @@ -102,6 +99,31 @@ } } + /** + * 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() { $db = ContributionTrackingProcessor::contributionTrackingConnection(); diff --git a/globalcollect_gateway/scripts/orphans.php b/globalcollect_gateway/scripts/orphans.php index c879e62..c3bb793 100644 --- a/globalcollect_gateway/scripts/orphans.php +++ b/globalcollect_gateway/scripts/orphans.php @@ -88,7 +88,7 @@ sleep(2); //two seconds. } } - DonationLogger::log( 'Removed ' . $this->removed_message_count . ' messages and antimessages.' ); + $this->adapter->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"; - DonationLogger::log($final); + $this->adapter->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. - DonationLogger::log("Found $count antimessages."); + $this->adapter->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']){ - DonationLogger::log( $data['contribution_tracking_id'] . ": FINAL: " . $results['action'] ); + $this->adapter->log( $data['contribution_tracking_id'] . ": FINAL: " . $results['action'] ); $rectified = true; } else { - DonationLogger::log( $data['contribution_tracking_id'] . ": ERROR: " . $results['message'] ); + $this->adapter->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/192382 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie7b71c99a870af4d9734ccf807ee82935bd54f1d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: master Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits