From d75612d4f2124d50e5022851e8ccc7fb2d795ef9 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Fri, 18 Sep 2015 11:27:00 -0500
Subject: [PATCH] cli: Fix crash deploying with --setup

---
 include/class.cli.php          | 10 +++++++++-
 include/cli/cli.inc.php        |  3 ---
 include/cli/modules/unpack.php |  5 +++++
 manage.php                     |  3 +--
 4 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/include/class.cli.php b/include/class.cli.php
index a4e3cfc16..f2f98ce29 100644
--- a/include/class.cli.php
+++ b/include/class.cli.php
@@ -232,8 +232,10 @@ class Module {
         die();
     }
 
-    function _run($module_name) {
+    function _run($module_name, $bootstrap=true) {
         $this->module_name = $module_name;
+        if ($bootstrap)
+            $this->bootstrap();
         $this->parseOptions();
         return $this->run($this->_args, $this->_options);
     }
@@ -242,6 +244,12 @@ class Module {
     function run($args, $options) {
     }
 
+    function bootstrap() {
+        Bootstrap::loadConfig();
+        Bootstrap::defineTables(TABLE_PREFIX);
+        Bootstrap::loadCode();
+    }
+
     function fail($message) {
         $this->stderr->write($message . "\n");
         die();
diff --git a/include/cli/cli.inc.php b/include/cli/cli.inc.php
index 401ddba40..cb833c921 100644
--- a/include/cli/cli.inc.php
+++ b/include/cli/cli.inc.php
@@ -23,7 +23,4 @@ define('INC_DIR',dirname(__file__).'/../inc/'); //local include dir!
 
 require_once INCLUDE_DIR . "class.cli.php";
 
-Bootstrap::loadConfig();
-Bootstrap::defineTables(TABLE_PREFIX);
-Bootstrap::loadCode();
 Bootstrap::i18n_prep();
diff --git a/include/cli/modules/unpack.php b/include/cli/modules/unpack.php
index 72f5fae82..75b73353d 100644
--- a/include/cli/modules/unpack.php
+++ b/include/cli/modules/unpack.php
@@ -215,6 +215,11 @@ class Unpacker extends Module {
         return $location = rtrim($INCLUDE_DIR, '/').'/';
     }
 
+    function bootstrap() {
+        // Don't load config and frieds as that will likely crash if not yet
+        // installed
+    }
+
     function run($args, $options) {
         $this->destination = $args['install-path'];
         if (!is_dir($this->destination))
diff --git a/manage.php b/manage.php
index 37317e7f5..25e1fd80e 100755
--- a/manage.php
+++ b/manage.php
@@ -80,5 +80,4 @@ class Manager extends Module {
 }
 
 $manager = new Manager();
-$manager->parseOptions();
-$manager->_run(basename(__file__));
+$manager->_run(basename(__file__), false);
-- 
GitLab