From 175468c76528662b6c5056fc5b6272a829bf9dee Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Thu, 14 Mar 2013 15:30:34 -0400
Subject: [PATCH] Added -s (skip optimize) switch to batch-delete scripts.

---
 harvest/batch-delete.bat | 24 ++++++++++++++++++++++--
 harvest/batch-delete.sh  | 23 ++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/harvest/batch-delete.bat b/harvest/batch-delete.bat
index 7421d708aa8..bff832c87d2 100644
--- a/harvest/batch-delete.bat
+++ b/harvest/batch-delete.bat
@@ -25,11 +25,27 @@ echo You need to set the VUFIND_HOME environmental variable before running this
 goto end
 :vufindhomefound
 
+rem Save script name for message below (otherwise it may get shifted away)
+set SCRIPT_NAME=%0
+
+rem Set default behavior
+set SKIP_OPTIMIZE=0
+
+rem Process switches
+:switchloop
+if "%1"=="-s" goto sswitch
+goto switchloopend
+:sswitch
+set SKIP_OPTIMIZE=1
+shift
+goto switchloop
+:switchloopend
+
 rem Make sure command line parameter was included:
 if not "!%1!"=="!!" goto paramsokay
 echo This script deletes records based on files created by the OAI-PMH harvester.
 echo.
-echo Usage: %0 [harvest subdirectory] [index type]
+echo Usage: %SCRIPT_NAME% [harvest subdirectory] [index type]
 echo.
 echo [harvest subdirectory] is a directory name created by the OAI-PMH harvester.
 echo This script will search the harvest subdirectories of the directories defined
@@ -38,7 +54,10 @@ echo.
 echo [index type] is optional; defaults to Solr for main bibliographic index, but
 echo can be set to SolrAuth for authority index.
 echo.
-echo Example: %0 oai_source
+echo Example: %SCRIPT_NAME% oai_source
+echo.
+echo Options:
+echo -s:  Skip optimize operation after importing.
 goto end
 :paramsokay
 
@@ -67,6 +86,7 @@ for %%a in (%BASEPATH%\*.delete) do (
 )
 
 if "%FOUNDSOME%"=="0" goto end
+if not "%SKIP_OPTIMIZE%!"=="0!" goto end
 
 echo Optimizing index...
 php optimize.php
diff --git a/harvest/batch-delete.sh b/harvest/batch-delete.sh
index a913293f54e..f2c5b05a319 100755
--- a/harvest/batch-delete.sh
+++ b/harvest/batch-delete.sh
@@ -7,6 +7,21 @@ then
   exit 1
 fi
 
+SKIP_OPTIMIZE=0
+
+while getopts ":s" OPT
+do
+  case $OPT in
+    s) SKIP_OPTIMIZE=1;;
+    :)
+      echo "argument to '-$OPTARG' is missing" >&2
+      exit -1;;
+    \?) echo "Unrecognized option '-$OPTARG'" >&2;;
+  esac
+done
+# Decrement the argument pointer so it points to next argument
+shift $(($OPTIND - 1))
+
 # Make sure command line parameter was included:
 if [ -z "$1" ]
 then
@@ -22,6 +37,9 @@ then
   echo "can be set to SolrAuth for authority index."
   echo ""
   echo "Example: `basename $0` oai_source"
+  echo ""
+  echo "Options:"
+  echo "-s:  Skip optimize operation after importing."
   exit 1
 fi
 
@@ -50,7 +68,10 @@ for file in $BASEPATH/*.delete
 do
   if [ -f $file ]
   then
-    FOUNDSOME=1
+    if [ "$SKIP_OPTIMIZE" -eq "0" ]
+    then
+      FOUNDSOME=1
+    fi
     echo "Processing $file ..."
     php deletes.php $file flat $2
     mv $file $BASEPATH/processed/`basename $file`
-- 
GitLab