From 3445e724991944017e963ae9efc1645adfcc0c20 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Thu, 19 Jul 2012 12:11:13 -0400
Subject: [PATCH] Abstracted use of exit() to make a cleaner solution easier to
 implement in the future.

---
 .../VuFind/CLI/Controller/AbstractBase.php    | 22 +++++++++++++++++++
 .../CLI/Controller/ImportController.php       |  6 ++---
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/module/VuFind/src/VuFind/CLI/Controller/AbstractBase.php b/module/VuFind/src/VuFind/CLI/Controller/AbstractBase.php
index 4aa60042d46..092ff02f7a6 100644
--- a/module/VuFind/src/VuFind/CLI/Controller/AbstractBase.php
+++ b/module/VuFind/src/VuFind/CLI/Controller/AbstractBase.php
@@ -71,4 +71,26 @@ class AbstractBase extends AbstractActionController
             echo "Without it, inappropriate default settings may be loaded.\n\n";
         }
     }
+
+    /**
+     * Indicate failure.
+     *
+     * @return void
+     */
+    protected function getFailureResponse()
+    {
+        // TODO: better framework integration for response codes
+        exit(1);
+    }
+
+    /**
+     * Indicate success.
+     *
+     * @return void
+     */
+    protected function getSuccessResponse()
+    {
+        // TODO: better framework integration for response codes
+        exit(0);
+    }
 }
\ No newline at end of file
diff --git a/module/VuFind/src/VuFind/CLI/Controller/ImportController.php b/module/VuFind/src/VuFind/CLI/Controller/ImportController.php
index 9dc622c71c4..bda3aabf2dd 100644
--- a/module/VuFind/src/VuFind/CLI/Controller/ImportController.php
+++ b/module/VuFind/src/VuFind/CLI/Controller/ImportController.php
@@ -72,7 +72,7 @@ class ImportController extends AbstractBase
                 . "SolrAuth to load authority records.\n\n"
                 . "Note: See vudl.properties and ojs.properties for configuration "
                 . "examples.\n";
-            exit(1);
+            return $this->getFailureResponse();
         }
 
         // Try to import the document if successful:
@@ -80,11 +80,11 @@ class ImportController extends AbstractBase
             Importer::save($argv[0], $argv[1], $index, $testMode);
         } catch (\Exception $e) {
             echo "Fatal error: " . $e->getMessage() . "\n";
-            exit(1);
+            return $this->getFailureResponse();
         }
         if (!$testMode) {
             echo "Successfully imported {$argv[0]}...\n";
         }
-        exit(0);
+        return $this->getSuccessResponse();
     }
 }
-- 
GitLab