Ejegg has uploaded a new change for review.

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

Change subject: Rename get_recon_file_date function
......................................................................

Rename get_recon_file_date function

Not all audit reports come every day, and we just need some key
to sort them chronologically. Rename function to reflect usage.

Bug: T121129
Change-Id: I32c08c6ef1f6e21ac3affffe74ec8cc1d5e03b44
---
M sites/all/modules/wmf_audit/BaseAuditProcessor.php
M sites/all/modules/wmf_audit/amazon/AmazonAuditProcessor.php
M sites/all/modules/wmf_audit/astropay/AstroPayAuditProcessor.php
M sites/all/modules/wmf_audit/worldpay/WorldpayAuditProcessor.php
4 files changed, 18 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/50/271450/1

diff --git a/sites/all/modules/wmf_audit/BaseAuditProcessor.php 
b/sites/all/modules/wmf_audit/BaseAuditProcessor.php
index 667094d..3e24d63 100644
--- a/sites/all/modules/wmf_audit/BaseAuditProcessor.php
+++ b/sites/all/modules/wmf_audit/BaseAuditProcessor.php
@@ -34,7 +34,13 @@
 
        protected function get_log_line_xml_parent_nodes() {}
 
-       abstract protected function get_recon_file_date( $file );
+       /**
+        * Get some identifier for a given files to let us sort all
+        * recon files for this processor chronologically.
+        * @param string $file name of the recon file
+        * @return string key for chronological sort
+        */
+       abstract protected function get_recon_file_sort_key( $file );
 
        abstract protected function regex_for_recon();
 
@@ -477,26 +483,27 @@
        }
 
        /**
-        * Returns an array of the full paths to all valid reconciliation files
+        * Returns an array of the full paths to all valid reconciliation files,
+        * sorted in chronological order.
         * @return array Full paths to all recon files
         */
        protected function get_all_recon_files() {
                $files_directory = $this->get_recon_dir();
                //foreach file in the directory, if it matches our pattern, add 
it to the array.
-               $files_by_date = array();
+               $files_by_sort_key = array();
                if ( $handle = opendir( $files_directory ) ) {
                        while ( ( $file = readdir( $handle ) ) !== false ) {
                                if ( $this->get_filetype( $file ) === 'recon' ) 
{
-                                       $filedate = $this->get_recon_file_date( 
$file ); //which is not the same thing as the edited date... probably.
-                                       $files_by_date[$filedate][] = 
$files_directory . $file;
+                                       $sort_key = 
$this->get_recon_file_sort_key( $file ); // report date or sequence number or 
something
+                                       $files_by_sort_key[$sort_key][] = 
$files_directory . $file;
                                }
                        }
                        closedir( $handle );
-                       ksort( $files_by_date );
+                       ksort( $files_by_sort_key );
                        // now flatten it
                        $files = array();
-                       foreach ( $files_by_date as $date => $date_files ) {
-                               $files = array_merge( $files, $date_files );
+                       foreach ( $files_by_sort_key as $key => $key_files ) {
+                               $files = array_merge( $files, $key_files );
                        }
                        return $files;
                } else {
diff --git a/sites/all/modules/wmf_audit/amazon/AmazonAuditProcessor.php 
b/sites/all/modules/wmf_audit/amazon/AmazonAuditProcessor.php
index 01e3aae..1a7547a 100644
--- a/sites/all/modules/wmf_audit/amazon/AmazonAuditProcessor.php
+++ b/sites/all/modules/wmf_audit/amazon/AmazonAuditProcessor.php
@@ -9,7 +9,7 @@
                return new AuditParser();
        }
 
-       protected function get_recon_file_date( $file ) {
+       protected function get_recon_file_sort_key( $file ) {
                // Example:  2015-09-29-SETTLEMENT_DATA_353863080016707.csv
                // For that, we'd want to return 20150929
                $parts = preg_split( '/-/', $file );
diff --git a/sites/all/modules/wmf_audit/astropay/AstroPayAuditProcessor.php 
b/sites/all/modules/wmf_audit/astropay/AstroPayAuditProcessor.php
index 6a87c1f..fc0af38 100644
--- a/sites/all/modules/wmf_audit/astropay/AstroPayAuditProcessor.php
+++ b/sites/all/modules/wmf_audit/astropay/AstroPayAuditProcessor.php
@@ -9,7 +9,7 @@
                return new AstroPayAudit();
        }
 
-       protected function get_recon_file_date( $file ) {
+       protected function get_recon_file_sort_key( $file ) {
                // Example:  wikimedia_report_2015-06-16.csv
                // For that, we'd want to return 20150616
                $parts = preg_split( '/_|\./', $file );
diff --git a/sites/all/modules/wmf_audit/worldpay/WorldpayAuditProcessor.php 
b/sites/all/modules/wmf_audit/worldpay/WorldpayAuditProcessor.php
index 43f0db1..e1871d8 100644
--- a/sites/all/modules/wmf_audit/worldpay/WorldpayAuditProcessor.php
+++ b/sites/all/modules/wmf_audit/worldpay/WorldpayAuditProcessor.php
@@ -27,7 +27,7 @@
         * @param string $file Name of the recon file (not full path)
         * @return string date in YYYYMMDD format
         */
-       protected function get_recon_file_date( $file ) {
+       protected function get_recon_file_sort_key( $file ) {
                // FIXME: this is two-fer-one functionality.  Unmash.
 
                if ( preg_match( '/\.RECON\.WIKI\./', $file ) ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I32c08c6ef1f6e21ac3affffe74ec8cc1d5e03b44
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
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

Reply via email to