Bug #9345: Need to make sure base config is loaded before doing vhost loading
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 28 Oct 2010 19:08:13 +0000 (13:08 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 28 Oct 2010 19:08:25 +0000 (13:08 -0600)
framework/Core/lib/Horde.php

index 4dca04f..8ffce13 100644 (file)
@@ -710,13 +710,13 @@ HTML;
         $config_dir = (($app == 'horde') && defined('HORDE_BASE'))
             ? HORDE_BASE . '/config/'
             : $registry->get('fileroot', $app) . '/config/';
-        $file = $config_dir . $config_file;
+        $base_path = $file = $config_dir . $config_file;
         if (file_exists($file)) {
             $filelist[$file] = 1;
         }
 
         // Load global configuration stanzas in .d directory
-        $directory = preg_replace('/\.php$/', '.d', $config_dir . $config_file);
+        $directory = preg_replace('/\.php$/', '.d', $base_path);
         if (file_exists($directory) &&
             is_dir($directory) &&
             ($sub_files = glob("$directory/*.php"))) {
@@ -725,18 +725,6 @@ HTML;
             }
         }
 
-        // Load vhost configuration file.
-        if (!empty($conf['vhosts']) || !empty($GLOBALS['conf']['vhosts'])) {
-            $server_name = isset($GLOBALS['conf'])
-                ? $GLOBALS['conf']['server']['name']
-                : $conf['server']['name'];
-            $file = $config_dir . substr($config_file, 0, -4) . '-' . $server_name . '.php';
-
-            if (file_exists($file)) {
-                $filelist[$file] = 0;
-            }
-        }
-
         foreach ($filelist as $file => $log_check) {
             /* If we are not exporting variables located in the configuration
              * file, or we are not capturing the output, then there is no
@@ -747,6 +735,10 @@ HTML;
                 : include $file;
             $output = self::endBuffer();
 
+            if (!$success) {
+                throw new Horde_Exception(sprintf('Failed to import configuration file "%s".', $file));
+            }
+
             if (!empty($output) && !$show_output) {
                 /* Horde 3 -> 4 conversion checking. This is the only place
                  * to catch PEAR_LOG errors. */
@@ -760,8 +752,29 @@ HTML;
                 }
             }
 
+            $was_included = true;
+        }
+
+        // Load vhost configuration file.
+        if (!empty($GLOBALS['conf']['vhosts']) ||
+            (($app == 'horde') &&
+             ($config_file == 'conf.php') &&
+             !empty($conf['vhosts']))) {
+            $server_name = isset($GLOBALS['conf'])
+                ? $GLOBALS['conf']['server']['name']
+                : $conf['server']['name'];
+            $file = $config_dir . substr($config_file, 0, -4) . '-' . $server_name . '.php';
+
+            self::startBuffer();
+            $success = (is_null($var_names) && !$show_output)
+                ? include_once $file
+                : include $file;
+            $output = self::endBuffer();
+
             if (!$success) {
                 throw new Horde_Exception(sprintf('Failed to import configuration file "%s".', $file));
+            } elseif (!empty($output) && !$show_output) {
+                throw new Horde_Exception(sprintf('Failed to import configuration file "%s": ', $file) . strip_tags($output));
             }
 
             $was_included = true;
@@ -770,7 +783,7 @@ HTML;
         // Return an error if neither main or vhosted versions of the config
         // file exist.
         if (!$was_included) {
-            throw new Horde_Exception(sprintf('Failed to import configuration file "%s".', $config_dir . $config_file));
+            throw new Horde_Exception(sprintf('Failed to import configuration file "%s".', $base_path));
         }
 
         if (isset($output) && $show_output) {
@@ -783,9 +796,9 @@ HTML;
             return compact($var_names);
         } elseif (isset($$var_names)) {
             return $$var_names;
-        } else {
-            return array();
         }
+
+        return array();
     }
 
     /**