Awight has uploaded a new change for review.

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

Change subject: Consolidate slayer logging; general cleanups
......................................................................

Consolidate slayer logging; general cleanups

Wrap all echoing in a function that mirrors to console or cron, and to syslog.

Bug: T107851
Change-Id: I87ad394c637827562c162c1728cf2e0231ba0708
---
M DonationInterface.php
M globalcollect_gateway/globalcollect.adapter.php
R globalcollect_gateway/scripts/orphan.adapter.php
M globalcollect_gateway/scripts/orphans.php
4 files changed, 27 insertions(+), 18 deletions(-)


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

diff --git a/DonationInterface.php b/DonationInterface.php
index 7ee05f4..84348bd 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -74,7 +74,7 @@
 $wgAutoloadClasses['GlobalCollectGatewayResult'] = __DIR__ . 
'/globalcollect_gateway/globalcollect_resultswitcher.body.php';
 
 $wgAutoloadClasses['GlobalCollectAdapter'] = __DIR__ . 
'/globalcollect_gateway/globalcollect.adapter.php';
-$wgAutoloadClasses['GlobalCollectOrphanAdapter'] = __DIR__ . 
'/globalcollect_gateway/scripts/orphan_adapter.php';
+$wgAutoloadClasses['GlobalCollectOrphanAdapter'] = __DIR__ . 
'/globalcollect_gateway/scripts/orphan.adapter.php';
 $wgAutoloadClasses['GlobalCollectOrphanRectifier'] = __DIR__ . 
'/globalcollect_gateway/scripts/orphans.php';
 
 // Amazon
@@ -250,7 +250,7 @@
 
 //GlobalCollect gateway globals
 $wgGlobalCollectGatewayURL = 'https://ps.gcsip.nl/wdl/wdl';
-$wgGlobalCollectGatewayTestingURL = 'https://'; // GlobalCollect testing URL
+$wgGlobalCollectGatewayTestingURL = 'https://ps.gcsip.com/wdl/wdl'; // 
GlobalCollect testing URL
 
 #      $wgGlobalCollectGatewayAccountInfo['example'] = array(
 #              'MerchantID' => '', // GlobalCollect ID
diff --git a/globalcollect_gateway/globalcollect.adapter.php 
b/globalcollect_gateway/globalcollect.adapter.php
index 2926ee4..75085df 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -1180,6 +1180,9 @@
 
        /**
         * Either confirm or reject the payment
+        *
+        * FIXME: This function is way too complex.  Unroll into new functions.
+        *
         * @global WebRequest $wgRequest
         * @return PaymentTransactionResponse
         */
diff --git a/globalcollect_gateway/scripts/orphan_adapter.php 
b/globalcollect_gateway/scripts/orphan.adapter.php
similarity index 100%
rename from globalcollect_gateway/scripts/orphan_adapter.php
rename to globalcollect_gateway/scripts/orphan.adapter.php
diff --git a/globalcollect_gateway/scripts/orphans.php 
b/globalcollect_gateway/scripts/orphans.php
index 3ba8252..292dcf3 100644
--- a/globalcollect_gateway/scripts/orphans.php
+++ b/globalcollect_gateway/scripts/orphans.php
@@ -1,8 +1,6 @@
 <?php
 //actually, as a maintenance script, this totally is a valid entry point. 
-
-//If you want to use this script, you will have to add the following line to 
LocalSettings.php:
-//$wgAutoloadClasses['GlobalCollectOrphanAdapter'] = $IP . 
'/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php';
+// FIXME: Prevent web access even if the security is misconfigured so this is 
runnable.
 
 $IP = getenv( 'MW_INSTALL_PATH' );
 if ( $IP === false ) {
@@ -30,7 +28,7 @@
                $wgDonationInterfaceEnableIPVelocityFilter = false;
 
                if ( !$this->getOrphanGlobal( 'enable' ) ){
-                       echo "\nOrphan cron disabled. Have a nice day.";
+                       $this->info( 'Orphan cron disabled. Have a nice day!' );
                        return;
                }
 
@@ -64,7 +62,7 @@
         */
        protected function getProcessElapsed(){
                $elapsed = time() - $this->start_time;
-               echo "Elapsed Time: $elapsed\n";
+               $this->info( "Elapsed Time: {$elapsed}" );
                return $elapsed;
        }
 
@@ -83,7 +81,7 @@
                        $queue_pool = new CyclicalArray( 
GlobalCollectAdapter::GC_CC_LIMBO_QUEUE );
                }
 
-               echo "Slaying orphans...\n";
+               $this->info( "Slaying orphans..." );
                $this->start_time = time();
 
                //I want to be clear on the problem I hope to prevent with 
this.  Say,
@@ -100,7 +98,7 @@
                                $message = DonationQueue::instance()->peek( 
$current_queue );
 
                                if ( !$message ) {
-                                       $this->logger->info( "Emptied queue 
[{$current_queue}], removing from pool." );
+                                       $this->info( "Emptied queue 
[{$current_queue}], removing from pool." );
                                        $queue_pool->dropCurrent();
                                        continue;
                                }
@@ -118,7 +116,7 @@
                                // chronological order.
                                $elapsed = $this->start_time - $message['date'];
                                if ( $elapsed < $time_buffer ) {
-                                       $this->logger->info( "Exhausted new 
messages in [{$current_queue}], removing from pool..." );
+                                       $this->info( "Exhausted new messages in 
[{$current_queue}], removing from pool..." );
                                        $queue_pool->dropCurrent();
 
                                        continue;
@@ -138,7 +136,7 @@
                                $queue_pool->rotate();
                        } catch ( ConnectionException $ex ) {
                                // Drop this server, for the duration of this 
batch.
-                               $this->logger->error( "Queue server for 
[$current_queue] is down! Ignoring for this run..." );
+                               $this->error( "Queue server for 
[$current_queue] is down! Ignoring for this run..." );
                                $queue_pool->dropCurrent();
                        }
                }
@@ -165,8 +163,7 @@
                        }
                }
                $final .= "\n Approximately " . $this->getProcessElapsed() . " 
seconds to execute.\n";
-               $this->logger->info( $final );
-               echo $final;
+               $this->info( $final );
        }
 
        /**
@@ -179,18 +176,17 @@
        protected function rectifyOrphan( $data, $query_contribution_tracking = 
true ){
                $data['order_id'] = $data['gateway_txn_id'];
 
-               $this->logger->info( "Rectifying orphan: {$data['order_id']}" );
-               echo 'Rectifying Orphan ' . $data['order_id'] . "\n";
+               $this->info( "Rectifying orphan: {$data['order_id']}" );
                $rectified = false;
 
                $this->adapter->loadDataAndReInit( $data, 
$query_contribution_tracking );
                $results = $this->adapter->do_transaction( 'Confirm_CreditCard' 
);
                $message = $results->getMessage();
                if ( $results->getCommunicationStatus() ){
-                       $this->logger->info( $data['contribution_tracking_id'] 
. ": FINAL: " . $this->adapter->getValidationAction() );
+                       $this->info( $data['contribution_tracking_id'] . ": 
FINAL: " . $this->adapter->getValidationAction() );
                        $rectified = true;
                } else {
-                       $this->logger->info( $data['contribution_tracking_id'] 
. ": ERROR: " . $message );
+                       $this->info( $data['contribution_tracking_id'] . ": 
ERROR: " . $message );
                        if ( strpos( $message, "GET_ORDERSTATUS reports that 
the payment is already complete." ) === 0  ){
                                $rectified = true;
                        }
@@ -207,7 +203,7 @@
                        }
                }
 
-               echo $message . "\n";
+               $this->info( $message );
                
                return $rectified;
        }
@@ -226,6 +222,16 @@
                        return NULL;
                }
        }
+
+       protected function info( $msg ) {
+               $this->logger->info( $msg );
+               print( "{$msg}\n" );
+       }
+
+       protected function error( $msg ) {
+               $this->logger->error( $msg );
+               error_log( $msg );
+       }
 }
 
 $maintClass = 'GlobalCollectOrphanRectifier';

-- 
To view, visit https://gerrit.wikimedia.org/r/232906
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I87ad394c637827562c162c1728cf2e0231ba0708
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to