From 6cfb9419364fbcb39148c2ccdaec4e6c00d1b560 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Mon, 5 Jun 2017 11:40:13 -0400
Subject: [PATCH] Added optional switch to dump suppressed IDs to file.

---
 module/VuFindConsole/config/module.config.php |  2 +-
 .../Controller/UtilController.php             | 22 ++++++++++++++-----
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/module/VuFindConsole/config/module.config.php b/module/VuFindConsole/config/module.config.php
index a1099a66534..d02890ccae5 100644
--- a/module/VuFindConsole/config/module.config.php
+++ b/module/VuFindConsole/config/module.config.php
@@ -59,7 +59,7 @@ $routes = [
     'util/index_reserves' => 'util index_reserves [--help|-h] [-d=s] [-t=s] [-f=s]',
     'util/optimize' => 'util optimize [<core>]',
     'util/sitemap' => 'util sitemap',
-    'util/suppressed' => 'util suppressed [--help|-h] [--authorities]',
+    'util/suppressed' => 'util suppressed [--help|-h] [--authorities] [--outfile=s]',
     'util/switch_db_hash' => 'util switch_db_hash [<newhash>] [<newkey>]',
 ];
 
diff --git a/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php b/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php
index 26e23f63957..ba7f0c2c74a 100644
--- a/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php
+++ b/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php
@@ -539,6 +539,10 @@ class UtilController extends AbstractBase
                 . ' Delete authority records instead of bibliographic records'
             );
             Console::writeLine('--help or -h => Show this message');
+            Console::writeLine(
+                '--outfile=[/path/to/file] => Write the ID list to the specified'
+                . ' file instead of updating Solr (optional)'
+            );
             return $this->getFailureResponse();
         }
 
@@ -565,11 +569,19 @@ class UtilController extends AbstractBase
             return $this->getSuccessResponse();
         }
 
-        // Get Suppressed Records and Delete from index
-        $solr = $this->serviceLocator->get('VuFind\Solr\Writer');
-        $solr->deleteRecords($backend, $result);
-        $solr->commit($backend);
-        $solr->optimize($backend);
+        // If 'outfile' set, write the list
+        if ($file = $request->getParam('outfile')) {
+            if (!file_put_contents($file, implode("\n", $result))) {
+                Console::writeLine("Problem writing to $file");
+                return $this->getFailureResponse();
+            }
+        } else {
+            // Default behavior: Get Suppressed Records and Delete from index
+            $solr = $this->serviceLocator->get('VuFind\Solr\Writer');
+            $solr->deleteRecords($backend, $result);
+            $solr->commit($backend);
+            $solr->optimize($backend);
+        }
         return $this->getSuccessResponse();
     }
 
-- 
GitLab