From 5705f30e976bc6b9f95d3c9491e23c1dd4800ece Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Mon, 22 Jun 2020 12:46:39 +0300
Subject: [PATCH] Sort filenames in MergeMarcCommand.

---
 .../Command/Harvest/MergeMarcCommand.php        | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/module/VuFindConsole/src/VuFindConsole/Command/Harvest/MergeMarcCommand.php b/module/VuFindConsole/src/VuFindConsole/Command/Harvest/MergeMarcCommand.php
index 8872e351862..034622e0bcc 100644
--- a/module/VuFindConsole/src/VuFindConsole/Command/Harvest/MergeMarcCommand.php
+++ b/module/VuFindConsole/src/VuFindConsole/Command/Harvest/MergeMarcCommand.php
@@ -89,18 +89,23 @@ class MergeMarcCommand extends RelativeFileAwareCommand
         }
 
         $output->writeln('<collection>');
+        $fileList = [];
         while (false !== ($file = readdir($handle))) {
             // Only operate on XML files:
             if (pathinfo($file, PATHINFO_EXTENSION) === "xml") {
                 // get file content
-                $filePath = $dir . '/' . $file;
-                $fileContent = file_get_contents($filePath);
-
-                // output content:
-                $output->writeln("<!-- $filePath -->");
-                $output->write($fileContent);
+                $fileList[] = $dir . '/' . $file;
             }
         }
+        // Sort filenames so that we have consistent results:
+        sort($fileList);
+        foreach ($fileList as $filePath) {
+            $fileContent = file_get_contents($filePath);
+
+            // output content:
+            $output->writeln("<!-- $filePath -->");
+            $output->write($fileContent);
+        }
         $output->writeln('</collection>');
         return 0;
     }
-- 
GitLab