diff --git a/config/dmsDefaults.php b/config/dmsDefaults.php
index 3a45e33..7bcf9c6 100644
--- a/config/dmsDefaults.php
+++ b/config/dmsDefaults.php
@@ -104,12 +104,12 @@ require_once(KT_LIB_DIR . '/validation/customerror.php');
// {{{ prependPath()
function prependPath ($path) {
-
+
$include_path = ini_get('include_path');
ini_set('include_path', $path . PATH_SEPARATOR . $include_path);
}
// }}}
-
+
prependPath(KT_DIR . '/thirdparty/ZendFramework/library');
prependPath(KT_DIR . '/thirdparty/pear');
prependPath(KT_DIR . '/thirdparty/Smarty');
@@ -128,11 +128,11 @@ require_once(KT_LIB_DIR . '/util/ktutil.inc');
require_once(KT_LIB_DIR . '/ktentity.inc');
require_once(KT_LIB_DIR . '/config/config.inc.php');
-require_once(KT_DIR . '/search2/indexing/indexerCore.inc.php');
+require_once(KT_DIR . '/search2/indexing/indexerCore.inc.php');
// {{{ KTInit
class KTInit {
-
+
// {{{ setupLogging()
function setupLogging () {
global $default;
@@ -202,7 +202,7 @@ class KTInit {
}
// }}}
-
+
// {{{ cleanGlobals()
function cleanGlobals () {
@@ -373,25 +373,25 @@ class KTInit {
function catchFatalErrors()
{
-
+
$CustomErrorPage = KTCustomErrorViewer::getCustomErrorRedirectPage();
if($CustomErrorPage != '0')
{
ini_set('display_errors','On');
$phperror='>
';
ini_set('error_prepend_string',$phperror);
-
+
$sUrl = KTInit::guessRootUrl();
global $default;
$sRootUrl = ($default->sslEnabled ? 'https' : 'http') .'://'.$_SERVER['HTTP_HOST'].$sUrl;
-
+
$CustomErrorPage = basename($CustomErrorPage);
-
+
$phperror='
>
';
ini_set('error_append_string',$phperror);
}
-
+
}
@@ -450,61 +450,79 @@ class KTInit {
// {{{ initConfig
function initConfig() {
global $default;
+ $oKTConfig = KTConfig::getSingleton();
+
+ // TODO: refactor when all the config settings are stored in the database
+ // Check for the config cache
$use_cache = false;
$store_cache = false;
- if (file_exists(KT_DIR . '/config/cache-path')) {
+ $cachePathFile = KT_DIR . '/config/cache-path';
+ if (file_exists($cachePathFile)) {
$store_cache = true;
- $user = KTLegacyLog::running_user();
- // handle vhosts.
- $truehost = KTUtil::arrayGet($_SERVER, 'HTTP_HOST', 'default');
- $trueport = KTUtil::arrayGet($_SERVER, 'SERVER_PORT', '80');
- $cache_file = trim(file_get_contents(KT_DIR . '/config/cache-path')) . '/configcache' . $user . $truehost . $trueport;
- if (!KTUtil::isAbsolutePath($cache_file)) { $cache_file = sprintf('%s/%s', KT_DIR, $cache_file); }
- $config_file = trim(file_get_contents(KT_DIR . '/config/config-path'));
+ // Get the path to the config cache
+ $cachePath = trim(file_get_contents($cachePathFile));
+ $cachePath .= '/configcache';
+
+ $cachePath = (!KTUtil::isAbsolutePath($cachePath)) ? sprintf('%s/%s', KT_DIR, $cachePath) : $cachePath;
+
+ // Get the path to the config file
+ $configPathFile = KT_DIR . '/config/config-path';
+ $configPath = trim(file_get_contents($configPathFile));
+
+ $configPath = (!KTUtil::isAbsolutePath($configPath)) ? sprintf('%s/%s', KT_DIR, $configPath) : $configPath;
+
// Remove any double slashes
- $config_file = str_replace('//', '/', $config_file);
- $config_file = str_replace('\\\\', '\\', $config_file);
- if (!KTUtil::isAbsolutePath($config_file)) { $config_file = sprintf('%s/%s', KT_DIR, $config_file); }
-
- $exists = file_exists($cache_file);
- if ($exists) {
- $cachestat = stat($cache_file);
- $configstat = stat($config_file);
+ $configPath = str_replace('//', '/', $configPath);
+ $configPath = str_replace('\\\\', '\\', $configPath);
+
+ // This check can be removed once all config settings are in the database
+ // Check if the config file has been updated since the last time the cache file was generated.
+ if (file_exists($cachePath)) {
+ $cachestat = stat($cachePath);
+ $configstat = stat($configPath);
$tval = 9;
- // print sprintf("is %d > %d\n", $cachestat[$tval], $configstat[$tval]);
if ($cachestat[$tval] > $configstat[$tval]) {
$use_cache = true;
+ $store_cache = false;
}
}
- }
-/*
- if ($use_cache) {
- $oKTConfig =& KTConfig::getSingleton();
- $oKTConfig->loadCache($cache_file);
+ if ($use_cache) {
+ $oKTConfig->loadCache($cachePath);
- foreach ($oKTConfig->flat as $k => $v) {
- $default->$k = $oKTConfig->get($k);
- }
- } else {
- //fail safe will be put here
-
-
- if (PEAR::isError($res)) { return $res; }
-
- //$oKTConfig =& KTConfig::getSingleton();
- @touch($cache_file);
- if ($store_cache && is_writable($cache_file)) {
- $oKTConfig->createCache($cache_file);
+ foreach ($oKTConfig->flat as $k => $v) {
+ $default->$k = $oKTConfig->get($k);
+ }
}
+ }
+
+ //Read in DB settings and config settings
+ if(!$use_cache) $oKTConfig->readDBConfig();
+ $dbSetup = $oKTConfig->setupDB();
+
+ if(PEAR::isError($dbSetup))
+ {
+ $this->handleInitError($dbSetup);
+ }
+
+ // Get default server url settings
+ if(!$use_cache) $this->getDynamicConfigSettings();
+
+ // Read in the config settings from the database
+ // Create the global $default array
+ if(!$use_cache) $res = $oKTConfig->readConfig();
+ if($store_cache && isset($cachePath)){
+ @touch($cachePath);
+ if (is_writable($cachePath)) {
+ $oKTConfig->createCache($cachePath);
+ }
}
-*/
}
// }}}
-
+
// {{{ initTesting
function initTesting() {
@@ -530,31 +548,11 @@ class KTInit {
}
// }}}
-//Creating all the config settings
-//====================================
-$oKTConfig = KTConfig::getSingleton();
-
-//Read in DB specific config settings
-$res = $oKTConfig->readDBConfig();
-//Set up DB connection
-$dbSetup = $oKTConfig->setupDB();
$KTInit = new KTInit();
-
-if(PEAR::isError($dbSetup))
-{
- $KTInit->handleInitError($dbSetup);
-}
-
-
-
-$KTInit->getDynamicConfigSettings();
$KTInit->initConfig();
$KTInit->setupI18n();
-//Create final flatns and $default arrays to finish config setup
-$res = $oKTConfig->readConfig();
-
//====================================
define('KTLOG_CACHE',false);
@@ -563,8 +561,7 @@ if (isset($GLOBALS['kt_test'])) {
$KTInit->initTesting();
}
-
-
+$oKTConfig = KTConfig::getSingleton();
if($oKTConfig->get('CustomErrorMessages/customerrormessages') == 'on')
{
diff --git a/lib/config/config.inc.php b/lib/config/config.inc.php
index c1358c5..9fef648 100644
--- a/lib/config/config.inc.php
+++ b/lib/config/config.inc.php
@@ -6,31 +6,31 @@
* Document Management Made Simple
* Copyright (C) 2008 KnowledgeTree Inc.
* Portions copyright The Jam Warehouse Software (Pty) Limited
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
- *
- * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
+ *
+ * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
* California 94120-7775, or email info@knowledgetree.com.
- *
+ *
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
- *
+ *
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
+ * must display the words "Powered by KnowledgeTree" and retain the original
* copyright notice.
* Contributor( s): ______________________________________
*
@@ -44,11 +44,10 @@ require_once (KT_LIB_DIR. '/database/dbutil.inc');
class KTConfig {
var $conf = array();
var $aSectionFile;
- var $aFileRoot;
var $flat = array();
var $flatns = array();
- var $aDBConfig = array();
- var $aConfFile = array();
+ var $expanded = array();
+ var $expanding = array();
// FIXME nbm: how do we cache errors here?
function loadCache($filename) {
@@ -58,62 +57,44 @@ class KTConfig {
$this->flatns = $config_cache['flatns'];
$this->expanded = $config_cache['expanded'];
$this->expanding = $config_cache['expanding'];
- /*
- print "----- Me\n";
- unset($this->aFileRoot);
- unset($this->aSectionFile);
- var_dump($this);
- print "----- Cache\n";
- var_dump($config_cache);
- */
-
return true;
}
-
+
+ function createCache($filename) {
+ $config_cache = array();
+ $config_cache['flat'] = $this->flat;
+ $config_cache['flatns'] = $this->flatns;
+ $config_cache['expanded'] = $this->expanded;
+ $config_cache['expanding'] = $this->expanding;
+
+ file_put_contents($filename, serialize($config_cache));
+ }
+
// {{{ readConfig
function readConfig () {
global $default;
-
+
//Load config data from the database
$sQuery = 'select group_name, item, value, default_value from config_settings';
$confResult = DBUtil::getResultArray($sQuery);
- foreach ($confResult as $confItem)
+ foreach ($confResult as $confItem)
{
-
- //if $aConfFile doesn't contain the value already set the value
-
- if(!isset($this->aConfFile[$confItem['group_name']][$confItem['item']]) || $this->aConfFile[$confItem['group_name']][$confItem['item']] == 'default')
- {
- if($confItem['value'] != 'default')
- {
- $this->flatns[$confItem['group_name'].'/'.$confItem['item']] = $confItem['value'];
- $this->flat[$confItem['item']] = $confItem['value'];
-
- }
- else
- {
- $this->flatns[$confItem['group_name'].'/'.$confItem['item']] = $confItem['default_value'];
- $this->flat[$confItem['item']] = $confItem['default_value'];
-
- }
- }
- else //if $aConfFile does have the value set $default and flatns with $aConfFile
- {
- $this->flatns[$confItem['group_name'].'/'.$confItem['item']] = $this->aConfFile[$confItem['group_name']][$confItem['item']];
- $this->flat[$confItem['item']] = $this->aConfFile[$confItem['group_name']][$confItem['item']];
-
+ if(!isset($this->flatns[$confItem['group_name'].'/'.$confItem['item']])){
+ $this->setns($confItem['group_name'], $confItem['item'], $confItem['value'], $confItem['default_value']);
}
}
+
+ // Populate the global $default array
foreach($this->flatns as $sGroupItem => $sValue)
{
$aGroupItemArray = explode('/', $sGroupItem);
$default->$aGroupItemArray[1] = $this->expand($this->flatns[$sGroupItem]);
}
-
+
}
// }}}
-
+
// {{{ readDBConfig()
function readDBConfig()
{
@@ -125,7 +106,7 @@ class KTConfig {
}
}
// }}}
-
+
// {{{ loadDBFile()
function loadDBFile($filename, $bDefault = false)
{
@@ -136,27 +117,22 @@ class KTConfig {
return $root;
}
- $this->aFileRoot[$filename] =& $root;
-
- $conf =& $root->toArray();
-
- //Set the database specific config details here
- $this->aDBConfig = $conf['root']['db'];
-
- //load entire config file into $aConfFile array
- //These values will override those given by the database
- //This is in case the system fails and the user cannot get to the admin page
- //all items given the value default will be poplulated either by the DB or
- //by the setdefaultns function
- foreach($conf['root'] as $sItem => $sValue)
- {
- $this->aConfFile[$sItem] = $sValue;
+ $conf = $root->toArray();
+
+ // Populate the flat and flatns array with the settings from the config file
+ // These setting will be overwritten with the settings from the database.
+ if(isset($conf['root']) && !empty($conf['root'])){
+ foreach($conf['root'] as $group => $item){
+ foreach ($item as $key => $value){
+ $this->setns($group, $key, $value, false);
+ }
+ }
}
-
}
// }}}
-
+
function setupDB () {
+
global $default;
require_once('DB.php');
@@ -171,27 +147,25 @@ class KTConfig {
// KTEntity is the database-backed base class
require_once(KT_LIB_DIR . '/ktentity.inc');
-
-
$prefix = defined('USE_DB_ADMIN_USER')?'Admin':'';
- $sUser = 'dbUser';
- $sPass = 'dbPass';
-
+ $sUser = 'db/dbUser';
+ $sPass = 'db/dbPass';
+
if ($prefix == 'Admin')
{
- $sUser = 'dbAdminUser';
- $sPass = 'dbAdminPass';
+ $sUser = 'db/dbAdminUser';
+ $sPass = 'db/dbAdminPass';
}
$dsn = array(
- 'phptype' => $this->aDBConfig['dbType'],
- 'username' => $this->aDBConfig[$sUser],
- 'password' => $this->aDBConfig[$sPass],
- 'hostspec' => $this->aDBConfig['dbHost'],
- 'database' => $this->aDBConfig['dbName'],
- 'port' => $this->aDBConfig['dbPort']
+ 'phptype' => $this->flatns['db/dbType'],
+ 'username' => $this->flatns[$sUser],
+ 'password' => $this->flatns[$sPass],
+ 'hostspec' => $this->flatns['db/dbHost'],
+ 'database' => $this->flatns['db/dbName'],
+ 'port' => $this->flatns['db/dbPort']
);
-
+
$options = array(
'debug' => 2,
'portability' => DB_PORTABILITY_ERRORS,
@@ -204,24 +178,14 @@ class KTConfig {
return $default->_db;
}
$default->_db->setFetchMode(DB_FETCHMODE_ASSOC);
-
- }
-
- function createCache($filename) {
- $config_cache = array();
- $config_cache['flat'] = $this->flat;
- $config_cache['flatns'] = $this->flatns;
- $config_cache['expanded'] = $this->expanded;
- $config_cache['expanding'] = $this->expanding;
-
- file_put_contents($filename, serialize($config_cache));
-
-
}
function setns($seck, $k, $v, $bDefault = false) {
if ($v === "default") {
- return;
+ if($bDefault === false){
+ return;
+ }
+ $v = $bDefault;
} elseif ($v === "true") {
$v = true;
} elseif ($v === "false") {
@@ -238,8 +202,6 @@ class KTConfig {
return $this->setns($seck, $k, $v, true);
}
- var $expanded = array();
- var $expanding = array();
function expand($val) {
if (strpos($val, '$') === false) {
return $val;
@@ -258,8 +220,6 @@ class KTConfig {
}
function get($var, $oDefault = null) {
-
-
if (array_key_exists($var, $this->flatns)) {
return $this->expand($this->flatns[$var]);
}