Ejegg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/190134

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.

Change-Id: I3fa9b5e503c41240955db1c64bd05d2b6402e480
---
M gateway_common/DonationLoggerContext.php
M globalcollect_gateway/scripts/orphan_adapter.php
M globalcollect_gateway/scripts/orphans.php
3 files changed, 38 insertions(+), 37 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/34/190134/1

diff --git a/gateway_common/DonationLoggerContext.php 
b/gateway_common/DonationLoggerContext.php
index 2296091..4d0b333 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
+        * The keys of settings added by the current instance to $settingsStack
+        * @var array
         */
-       protected $localSettingsKey;
+       protected $localSettingsKeys = array();
 
        /**
         * Initializes settingsStack and public properties with default values
@@ -76,16 +76,39 @@
         */
        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->localSettingsKeys, 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.
+        */
+       public function popSettings() {
+               if ( !$this->localSettingsKeys ) {
+                       throw new MWException( 'Bad programmer!  You called 
popSettings at least one too many times!' );
+               }
+               $lastKey = array_pop( $this->localSettingsKeys );
+               unset( self::$settingsStack[$lastKey] );
                self::setCurrent();
        }
 
        public function __destruct() {
-               if ( isset( $this->localSettingsKey ) ) {
-                       unset( self::$settingsStack[$this->localSettingsKey] );
-                       self::setCurrent();
+               foreach ( $this->localSettingsKeys as $key ) {
+                       unset( self::$settingsStack[$key] );
                }
+               self::setCurrent();
        }
 
        /**
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: newchange
Gerrit-Change-Id: I3fa9b5e503c41240955db1c64bd05d2b6402e480
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

Reply via email to