From 8c35190b0a47bb3870f3ba693e574ea03dd7b51d Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 3 Jan 2023 13:16:03 -0500 Subject: [PATCH] Move loading of global Servers array into config.php. --- web/includes/config.php.in | 40 +++++++++++++++++++++++++------------- web/index.php | 3 --- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/web/includes/config.php.in b/web/includes/config.php.in index 7324a9617..7bae6d6c2 100644 --- a/web/includes/config.php.in +++ b/web/includes/config.php.in @@ -220,25 +220,37 @@ function loadConfig( $defineConsts=true ) { return $config; } # end function loadConfig +require_once('Server.php'); +#global $Servers; +#global $thisServer; +$Servers = ZM\Server::find([], ['order'=>'lower(Name)']); +$thisServer = null; + // For Human-readability, use ZM_SERVER_HOST or ZM_SERVER_NAME in zm.conf, and convert it here to a ZM_SERVER_ID -if ( ! defined('ZM_SERVER_ID') ) { - require_once('Server.php'); - if ( defined('ZM_SERVER_NAME') and ZM_SERVER_NAME ) { - # Use Server lookup so that it caches - $Server = ZM\Server::find_one(array('Name'=>ZM_SERVER_NAME)); - if ( !$Server ) { - ZM\Error('Invalid Multi-Server configration detected. ZM_SERVER_NAME set to ' . ZM_SERVER_NAME . ' in zm.conf, but no corresponding entry found in Servers table.'); - } else { - define('ZM_SERVER_ID', $Server->Id()); +if (!defined('ZM_SERVER_ID')) { + if (defined('ZM_SERVER_NAME') and ZM_SERVER_NAME) { + foreach ($Servers as $s) { + if ($s->Name() == ZM_SERVER_NAME) { + $thisServer = $s; + define('ZM_SERVER_ID', $Server->Id()); + } } - } else if ( defined('ZM_SERVER_HOST') and ZM_SERVER_HOST ) { - $Server = ZM\Server::find_one(array('Name'=>ZM_SERVER_HOST)); - if ( ! $Server ) { + if (!$thisServer) { + ZM\Error('Invalid Multi-Server configration detected. ZM_SERVER_NAME set to ' . ZM_SERVER_NAME . ' in zm.conf, but no corresponding entry found in Servers table.'); + } + } else if (defined('ZM_SERVER_HOST') and ZM_SERVER_HOST) { + foreach ($Servers as $s) { + if ($s->Name() == ZM_SERVER_HOST) { + $thisServer = $s; + define('ZM_SERVER_ID', $s->Id()); + } + } + if (!$thisServer) { ZM\Error('Invalid Multi-Server configration detected. ZM_SERVER_HOST set to ' . ZM_SERVER_HOST . ' in zm.conf, but no corresponding entry found in Servers table.'); - } else { - define('ZM_SERVER_ID', $Server->Id()); } } +} else { + $thisServer = ZM\Server::find_one(['Id'=>ZM_SERVER_ID]); // Should be cached } if ( defined('ZM_TIMEZONE') and ZM_TIMEZONE ) diff --git a/web/index.php b/web/index.php index c5a5edd14..85dfde90f 100644 --- a/web/index.php +++ b/web/index.php @@ -45,7 +45,6 @@ if ( false ) { require_once('includes/config.php'); require_once('includes/session.php'); require_once('includes/logger.php'); // already included in config -require_once('includes/Server.php'); // Useful debugging lines for mobile devices if ( 0 and ZM\Logger::fetch()->debugOn() ) { @@ -56,8 +55,6 @@ if ( 0 and ZM\Logger::fetch()->debugOn() ) { } ZM\Debug(print_r($_REQUEST, true)); -global $Servers; -$Servers = ZM\Server::find([], ['order'=>'lower(Name)']); if ( (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')