From 1cd69c69b98b67ecb93c8d95f712589c8d3a7c1c Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 1 Jan 2018 13:10:39 -0500 Subject: [PATCH] add defining ZM_SERVER_ID after loading config --- web/api/app/Config/bootstrap.php.in | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/web/api/app/Config/bootstrap.php.in b/web/api/app/Config/bootstrap.php.in index cc096f233..d1cd7857d 100644 --- a/web/api/app/Config/bootstrap.php.in +++ b/web/api/app/Config/bootstrap.php.in @@ -142,6 +142,27 @@ foreach( $configvals as $key => $value) { Configure::write( $key, $value ); } +// 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') ) { + App::uses('ClassRegistry', 'Utility'); + $ServerModel = ClassRegistry::init('Server'); + if ( defined('ZM_SERVER_NAME') and ZM_SERVER_NAME ) { + $Server = $ServerModel->find( 'first', array( 'conditions'=>array('Name'=>ZM_SERVER_NAME) ) ); + if ( ! $Server ) { + 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['Server']['Id'] ); + } + } else if ( defined('ZM_SERVER_HOST') and ZM_SERVER_HOST ) { + $Server = $ServerModel->find( 'first', array( 'conditions'=>array('Name'=>ZM_SERVER_HOST) ) ); + if ( ! $Server ) { + 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['Server']['Id'] ); + } + } +} + function process_configfile($configFile) { if ( is_readable( $configFile ) ) { $configvals = array();