From 8d044a30481569addfec74edaa6dda489590ed8f Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Fri, 6 Sep 2013 13:37:23 +0000
Subject: [PATCH] Provide a fallback ROOT_PATH

If unable to detect the root path, provide a fallback ROOT_PATH setting to
'./'. This is likely to happen if run from the commandline (like for crons)
or if DOCUMENT_ROOT and the folder of main.inc.php seem to have nothing in
common

Fixes #704
---
 include/class.misc.php | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/class.misc.php b/include/class.misc.php
index b92909caa..d49970e9f 100644
--- a/include/class.misc.php
+++ b/include/class.misc.php
@@ -141,11 +141,18 @@ class Misc {
 
     /* static */
     function siteRootPath($main_inc_path) {
+        if (!$_SERVER['DOCUMENT_ROOT'])
+            // Probably run from the command-line
+            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