Awight has uploaded a new change for review.

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

Change subject: WIP Remove unused code from the orphans script
......................................................................

WIP Remove unused code from the orphans script

This can't be true.

Change-Id: I54a38ff05aba7556f7afba6de5c2308be6a11c46
---
M globalcollect_gateway/scripts/orphan_adapter.php
M globalcollect_gateway/scripts/orphans.php
2 files changed, 8 insertions(+), 210 deletions(-)


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

diff --git a/globalcollect_gateway/scripts/orphan_adapter.php 
b/globalcollect_gateway/scripts/orphan_adapter.php
index 435bc93..cbe091b 100644
--- a/globalcollect_gateway/scripts/orphan_adapter.php
+++ b/globalcollect_gateway/scripts/orphan_adapter.php
@@ -39,6 +39,7 @@
                return $unstaged;
        }
 
+       // FIXME: This looks like serious code reuse fail.
        public function loadDataAndReInit( $data, $useDB = true ) {
                //re-init all these arrays, because this is a batch thing.
                $this->session_killAllEverything(); // just to be sure
diff --git a/globalcollect_gateway/scripts/orphans.php 
b/globalcollect_gateway/scripts/orphans.php
index 52fd3a3..9ea9056 100644
--- a/globalcollect_gateway/scripts/orphans.php
+++ b/globalcollect_gateway/scripts/orphans.php
@@ -16,11 +16,12 @@
        
        protected $killfiles = array();
        protected $order_ids = array();
+       // FIXME: Get defaults from global config.
        protected $max_per_execute = 500; //only really used if you're going 
by-file.
-       protected $target_execute_time = 30; //(seconds) - only used by the 
stomp option.
+       protected $target_execute_time = 180; //(seconds) - only used by the 
stomp option.
        protected $adapter;
        
-       function execute(){
+       function execute() {
                //have to turn this off here, until we know it's using the 
user's ip, and 
                //not 127.0.0.1 during the batch process.
                global $wgDonationInterfaceEnableIPVelocityFilter;
@@ -29,26 +30,7 @@
                        return;
                }
                $wgDonationInterfaceEnableIPVelocityFilter = false;
-               
-               $func = 'parse_files';
-               if ( $this->getOrphanGlobal( 'override_command_line_params' ) ){
-                       //do that
-                       $func = $this->getOrphanGlobal( 'function' );
-                       $this->target_execute_time = $this->getOrphanGlobal( 
'target_execute_time' );
-                       $this->max_per_execute = $this->getOrphanGlobal( 
'max_per_execute' );
-               } else {
-                       if ( !empty( $_SERVER['argv'][1] ) ){
-                               if ( $_SERVER['argv'][1] === 'stomp' ){
-                                       $func = 'orphan_stomp';
-                                       if ( !empty( $_SERVER['argv'][2] ) && 
is_numeric( $_SERVER['argv'][2] ) ){
-                                               $this->target_execute_time = 
$_SERVER['argv'][2];
-                                       }
-                               } elseif ( is_numeric( $_SERVER['argv'][1] ) ){
-                                       $this->max_per_execute = 
$_SERVER['argv'][1];
-                               }
-                       }
-               }
-               
+
                // FIXME: Is this just to trigger batch mode?
                $data = array(
                        'wheeee' => 'yes'
@@ -57,12 +39,7 @@
                $this->logger = DonationLoggerFactory::getLogger( 
$this->adapter );
 
                //Now, actually do the processing. 
-               if ( method_exists( $this, $func ) ) {
-                       $this->{$func}();
-               } else {
-                       echo "There's no $func in Orphan Rectifying!\n";
-                       die();
-               }
+               $this->orphan_stomp();
        }
        
        function orphan_stomp(){
@@ -274,75 +251,7 @@
                
                return $orphans;
        }
-       
-       function parse_files(){
-               //all the old stuff goes here. 
-               $order_ids = file( 'orphanlogs/order_ids.txt', 
FILE_SKIP_EMPTY_LINES );
-               foreach ( $order_ids as $key=>$val ){
-                       $order_ids[$key] = trim( $val );
-               }
-               foreach ( $order_ids as $id ){
-                       $this->order_ids[$id] = $id; //easier to unset this 
way. 
-               }
-               $outstanding_count = count( $this->order_ids );
-               echo "Order ID count: $outstanding_count \n";
-               
-               $files = $this->getAllLogFileNames();
-               $payments = array();
-               foreach ( $files as $file ){
-                       if ( count( $payments ) < $this->max_per_execute ){
-                               $file_array = $this->getLogfileLines( $file );
-                               $payments = array_merge( 
$this->findTransactionLines( $file_array ), $payments );
-                               if ( count( $payments ) === 0 ){
-                                       $this->killfiles[] = $file;
-                                       echo print_r( $this->killfiles, true );
-                               }
-                       }
-               }
-               
-               
$this->adapter->setCurrentTransaction('INSERT_ORDERWITHPAYMENT');
-               $xml = new DomDocument;
-               
-               //fields that have generated notices if they're not there. 
-               $additional_fields = array(
-                       'card_num',
-                       'utm_medium',
-                       'utm_campaign',
-                       'referrer',
-               );
-               
-               foreach ($payments as $key => $payment_data){
-                       $xml->loadXML($payment_data['xml']);
-                       $parsed = $this->adapter->getResponseData($xml);
-                       $payments[$key]['parsed'] = $parsed;
-                       $payments[$key]['unstaged'] = 
$this->adapter->unstage_data($parsed);
-                       $payments[$key]['unstaged']['contribution_tracking_id'] 
= $payments[$key]['contribution_tracking_id'];
-                       foreach ($additional_fields as $val){
-                               if (!array_key_exists($val, 
$payments[$key]['unstaged'])){
-                                       $payments[$key]['unstaged'][$val] = 
null;
-                               }
-                       }
-               }
-               
-               // ADDITIONAL: log out what you did here, to... somewhere. 
-               // Preferably *before* you rewrite the Order ID file. 
 
-               //we may need to unset some hooks out here. Anything that 
requires user interaction would make no sense here.
-               $i = 0;
-               foreach($payments as $payment_data){
-                       if ($i < $this->max_per_execute){
-                               ++$i;
-                               if ( $this->rectifyOrphan( 
$payment_data['unstaged'] ) ) {
-                                       unset( 
$this->order_ids[$payment_data['unstaged']['order_id']] );
-                               }
-                       }
-               }
-               
-               if ($outstanding_count != count($this->order_ids)){
-                       $this->rewriteOrderIds();
-               }
-       }
-       
        /**
         * Uses the Orphan Adapter to rectify a single orphan. Returns a 
boolean letting the caller know if
         * the orphan has been fully rectified or not. 
@@ -383,6 +292,8 @@
        /**
         * Gets the global setting for the key passed in.
         * @param type $key
+        *
+        * FIXME: Reuse GatewayAdapter::getGlobal.
         */
        function getOrphanGlobal( $key ){
                global $wgDonationInterfaceOrphanCron;
@@ -392,120 +303,6 @@
                        return NULL;
                }
        }
-       
-       function getAllLogFileNames(){
-               $files = array();
-               if ($handle = opendir(dirname(__FILE__) . '/orphanlogs/')){
-                       while ( ($file = readdir($handle)) !== false ){
-                               if (trim($file, '.') != '' && $file != 
'order_ids.txt' && $file != '.svn'){
-                                       $files[] = dirname(__FILE__) . 
'/orphanlogs/' . $file;
-                               }
-                       }
-               }
-               closedir($handle);
-               return $files;
-       }
-       
-       function findTransactionLines($file){
-               $lines = array();
-               $orders = array();
-               $contrib_id_finder = array();
-               foreach ($file as $line_no=>$line_data){
-                       if (strpos($line_data, 
'<XML><REQUEST><ACTION>INSERT_ORDERWITHPAYMENT') === 0){
-                               $lines[$line_no] = $line_data;
-                       } elseif (strpos($line_data, 'Raw XML Response')){
-                               $contrib_id_finder[] = $line_data;
-                       } elseif (strpos(trim($line_data), '<ORDERID>') === 0){
-                               $contrib_id_finder[] = trim($line_data);
-                       }
-               }
-               
-               $order_ids = $this->order_ids;
-               foreach ($lines as $line_no=>$line_data){
-                       if (count($orders) < $this->max_per_execute){
-                               $pos1 = strpos($line_data, '<ORDERID>') + 9;
-                               $pos2 = strpos($line_data, '</ORDERID>');
-                               if ($pos2 > $pos1){
-                                       $tmp = substr($line_data, $pos1, 
$pos2-$pos1);
-                                       if (isset($order_ids[$tmp])){
-                                               $orders[$tmp] = 
trim($line_data);
-                                               unset($order_ids[$tmp]);
-                                       }
-                               }
-                       }
-               }
-               
-               //reverse the array, so we find the last instance first.
-               $contrib_id_finder = array_reverse($contrib_id_finder);
-               foreach ($orders as $order_id => $xml){
-                       $finder = array_search("<ORDERID>$order_id</ORDERID>", 
$contrib_id_finder);
-                       
-                       //now search forward (which is actually backward) to 
the "Raw XML" line, so we can get the contribution_tracking_id
-                       //TODO: Some kind of (in)sanity check for this. Just 
because we've found it one step backward doesn't mean...
-                       //...but it's kind of good. For now. 
-                       $explode_me = false;
-                       while (!$explode_me){
-                               ++$finder;
-                               if (strpos($contrib_id_finder[$finder], "Raw 
XML Response")){
-                                       $explode_me = 
$contrib_id_finder[$finder];
-                               }
-                       }
-                       if (strlen($explode_me)){
-                               $explode_me = explode(': ', $explode_me);
-                               $contribution_tracking_id = 
trim($explode_me[1]);
-                               $orders[$order_id] = array(
-                                       'xml' => $xml,
-                                       'contribution_tracking_id' => 
$contribution_tracking_id,
-                               );
-                       }
-               }
-               
-               return $orders;
-       }
-       
-       function rewriteOrderIds() {
-               $file = fopen('orphanlogs/order_ids.txt', 'w');
-               $outstanding_orders = implode("\n", $this->order_ids);          
-               fwrite($file, $outstanding_orders);
-               fclose($file);
-       }
-       
-       function getLogfileLines( $file ){
-               $array = file($file, FILE_SKIP_EMPTY_LINES);
-               //now, check about 50 lines to make sure we're not seeing any 
of that #012, #015 crap.
-               $checkcount = 50;
-               if (count($array) < $checkcount){
-                       $checkcount = count($array);
-               }
-               $convert = false;
-               for ($i=0; $i<$checkcount; ++$i){
-                       if( strpos($array[$i], '#012') || strpos($array[$i], 
'#015') ){
-                               $convert = true;
-                               break;
-                       }
-               }
-               if ($convert) {
-                       $array2 = array(); 
-                       foreach ($array as $line){
-                               if (strpos($line, '#012')){
-                                       $line = str_replace('#012', "\n", 
$line);
-                               }
-                               if (strpos($line, '#015') ){
-                                       $line = str_replace('#015', "\r", 
$line);       
-                               }
-                               $array2[] = $line;
-                       }
-                       $newfile = implode("\n", $array2);
-                       
-                       $handle = fopen($file, 'w');
-                       fwrite($handle, $newfile);
-                       fclose($handle);
-                       $array = file($file, FILE_SKIP_EMPTY_LINES);
-               }
-               
-               return $array;
-       }
-       
 }
 
 $maintClass = "GlobalCollectOrphanRectifier";

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I54a38ff05aba7556f7afba6de5c2308be6a11c46
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