From f574da5553cc875ffee3739be6c4203cd48d7072 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Fri, 6 Sep 2013 13:30:37 +0000
Subject: [PATCH] Provide default ROOT_PATH for command-line scripts

---
 include/class.misc.php | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/class.misc.php b/include/class.misc.php
index b92909caa..8d5dbb382 100644
--- a/include/class.misc.php
+++ b/include/class.misc.php
@@ -141,11 +141,17 @@ class Misc {
 
     /* static */
     function siteRootPath($main_inc_path) {
+        if (!$_SERVER['DOCUMENT_ROOT'])
+            return './';
         $root = str_replace('\\', '/', $main_inc_path);
         $root2 = str_replace('\\','/', $_SERVER['DOCUMENT_ROOT']);
         $path = '';
         while (strpos($_SERVER['DOCUMENT_ROOT'], $root) === false) {
             $lastslash = strrpos($root, '/');
+            if ($lastslash === false)
+                // Unable to find any commonality between $root and
+                // DOCUMENT_ROOT
+                return './';
             $path = substr($root, $lastslash) . $path;
             $root = substr($root, 0, $lastslash);
         }
-- 
GitLab