Commit e0a528792eb9dd5d66048b375d98970468badd29
1 parent
40419fcf
KTS-3437
"Document upload failed: Could not create directory" Fixed. Refactored the code slightly, changed the order in which things are loaded. Added caching back in. Committed by: Megan Watson Reviewed by: Conrad Vermeulen git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8613 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
125 additions
and
168 deletions
config/dmsDefaults.php
| @@ -104,12 +104,12 @@ require_once(KT_LIB_DIR . '/validation/customerror.php'); | @@ -104,12 +104,12 @@ require_once(KT_LIB_DIR . '/validation/customerror.php'); | ||
| 104 | 104 | ||
| 105 | // {{{ prependPath() | 105 | // {{{ prependPath() |
| 106 | function prependPath ($path) { | 106 | function prependPath ($path) { |
| 107 | - | 107 | + |
| 108 | $include_path = ini_get('include_path'); | 108 | $include_path = ini_get('include_path'); |
| 109 | ini_set('include_path', $path . PATH_SEPARATOR . $include_path); | 109 | ini_set('include_path', $path . PATH_SEPARATOR . $include_path); |
| 110 | } | 110 | } |
| 111 | // }}} | 111 | // }}} |
| 112 | - | 112 | + |
| 113 | prependPath(KT_DIR . '/thirdparty/ZendFramework/library'); | 113 | prependPath(KT_DIR . '/thirdparty/ZendFramework/library'); |
| 114 | prependPath(KT_DIR . '/thirdparty/pear'); | 114 | prependPath(KT_DIR . '/thirdparty/pear'); |
| 115 | prependPath(KT_DIR . '/thirdparty/Smarty'); | 115 | prependPath(KT_DIR . '/thirdparty/Smarty'); |
| @@ -128,11 +128,11 @@ require_once(KT_LIB_DIR . '/util/ktutil.inc'); | @@ -128,11 +128,11 @@ require_once(KT_LIB_DIR . '/util/ktutil.inc'); | ||
| 128 | require_once(KT_LIB_DIR . '/ktentity.inc'); | 128 | require_once(KT_LIB_DIR . '/ktentity.inc'); |
| 129 | 129 | ||
| 130 | require_once(KT_LIB_DIR . '/config/config.inc.php'); | 130 | require_once(KT_LIB_DIR . '/config/config.inc.php'); |
| 131 | -require_once(KT_DIR . '/search2/indexing/indexerCore.inc.php'); | 131 | +require_once(KT_DIR . '/search2/indexing/indexerCore.inc.php'); |
| 132 | 132 | ||
| 133 | // {{{ KTInit | 133 | // {{{ KTInit |
| 134 | class KTInit { | 134 | class KTInit { |
| 135 | - | 135 | + |
| 136 | // {{{ setupLogging() | 136 | // {{{ setupLogging() |
| 137 | function setupLogging () { | 137 | function setupLogging () { |
| 138 | global $default; | 138 | global $default; |
| @@ -202,7 +202,7 @@ class KTInit { | @@ -202,7 +202,7 @@ class KTInit { | ||
| 202 | } | 202 | } |
| 203 | // }}} | 203 | // }}} |
| 204 | 204 | ||
| 205 | - | 205 | + |
| 206 | 206 | ||
| 207 | // {{{ cleanGlobals() | 207 | // {{{ cleanGlobals() |
| 208 | function cleanGlobals () { | 208 | function cleanGlobals () { |
| @@ -373,25 +373,25 @@ class KTInit { | @@ -373,25 +373,25 @@ class KTInit { | ||
| 373 | 373 | ||
| 374 | function catchFatalErrors() | 374 | function catchFatalErrors() |
| 375 | { | 375 | { |
| 376 | - | 376 | + |
| 377 | $CustomErrorPage = KTCustomErrorViewer::getCustomErrorRedirectPage(); | 377 | $CustomErrorPage = KTCustomErrorViewer::getCustomErrorRedirectPage(); |
| 378 | if($CustomErrorPage != '0') | 378 | if($CustomErrorPage != '0') |
| 379 | { | 379 | { |
| 380 | ini_set('display_errors','On'); | 380 | ini_set('display_errors','On'); |
| 381 | $phperror='><div id="phperror" style="display:none">'; | 381 | $phperror='><div id="phperror" style="display:none">'; |
| 382 | ini_set('error_prepend_string',$phperror); | 382 | ini_set('error_prepend_string',$phperror); |
| 383 | - | 383 | + |
| 384 | $sUrl = KTInit::guessRootUrl(); | 384 | $sUrl = KTInit::guessRootUrl(); |
| 385 | global $default; | 385 | global $default; |
| 386 | $sRootUrl = ($default->sslEnabled ? 'https' : 'http') .'://'.$_SERVER['HTTP_HOST'].$sUrl; | 386 | $sRootUrl = ($default->sslEnabled ? 'https' : 'http') .'://'.$_SERVER['HTTP_HOST'].$sUrl; |
| 387 | - | 387 | + |
| 388 | $CustomErrorPage = basename($CustomErrorPage); | 388 | $CustomErrorPage = basename($CustomErrorPage); |
| 389 | - | 389 | + |
| 390 | $phperror='</div>><form name="catcher" action="'.$sRootUrl.'/'.$CustomErrorPage.'" method="post" ><input type="hidden" name="fatal" value=""></form> | 390 | $phperror='</div>><form name="catcher" action="'.$sRootUrl.'/'.$CustomErrorPage.'" method="post" ><input type="hidden" name="fatal" value=""></form> |
| 391 | <script> document.catcher.fatal.value = document.getElementById("phperror").innerHTML; document.catcher.submit();</script>'; | 391 | <script> document.catcher.fatal.value = document.getElementById("phperror").innerHTML; document.catcher.submit();</script>'; |
| 392 | ini_set('error_append_string',$phperror); | 392 | ini_set('error_append_string',$phperror); |
| 393 | } | 393 | } |
| 394 | - | 394 | + |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | 397 | ||
| @@ -450,61 +450,79 @@ class KTInit { | @@ -450,61 +450,79 @@ class KTInit { | ||
| 450 | // {{{ initConfig | 450 | // {{{ initConfig |
| 451 | function initConfig() { | 451 | function initConfig() { |
| 452 | global $default; | 452 | global $default; |
| 453 | + $oKTConfig = KTConfig::getSingleton(); | ||
| 454 | + | ||
| 455 | + // TODO: refactor when all the config settings are stored in the database | ||
| 456 | + // Check for the config cache | ||
| 453 | $use_cache = false; | 457 | $use_cache = false; |
| 454 | $store_cache = false; | 458 | $store_cache = false; |
| 455 | - if (file_exists(KT_DIR . '/config/cache-path')) { | 459 | + $cachePathFile = KT_DIR . '/config/cache-path'; |
| 460 | + if (file_exists($cachePathFile)) { | ||
| 456 | $store_cache = true; | 461 | $store_cache = true; |
| 457 | - $user = KTLegacyLog::running_user(); | ||
| 458 | - // handle vhosts. | ||
| 459 | - $truehost = KTUtil::arrayGet($_SERVER, 'HTTP_HOST', 'default'); | ||
| 460 | - $trueport = KTUtil::arrayGet($_SERVER, 'SERVER_PORT', '80'); | ||
| 461 | - $cache_file = trim(file_get_contents(KT_DIR . '/config/cache-path')) . '/configcache' . $user . $truehost . $trueport; | ||
| 462 | - if (!KTUtil::isAbsolutePath($cache_file)) { $cache_file = sprintf('%s/%s', KT_DIR, $cache_file); } | ||
| 463 | - $config_file = trim(file_get_contents(KT_DIR . '/config/config-path')); | 462 | + // Get the path to the config cache |
| 463 | + $cachePath = trim(file_get_contents($cachePathFile)); | ||
| 464 | + $cachePath .= '/configcache'; | ||
| 465 | + | ||
| 466 | + $cachePath = (!KTUtil::isAbsolutePath($cachePath)) ? sprintf('%s/%s', KT_DIR, $cachePath) : $cachePath; | ||
| 467 | + | ||
| 468 | + // Get the path to the config file | ||
| 469 | + $configPathFile = KT_DIR . '/config/config-path'; | ||
| 470 | + $configPath = trim(file_get_contents($configPathFile)); | ||
| 471 | + | ||
| 472 | + $configPath = (!KTUtil::isAbsolutePath($configPath)) ? sprintf('%s/%s', KT_DIR, $configPath) : $configPath; | ||
| 473 | + | ||
| 464 | // Remove any double slashes | 474 | // Remove any double slashes |
| 465 | - $config_file = str_replace('//', '/', $config_file); | ||
| 466 | - $config_file = str_replace('\\\\', '\\', $config_file); | ||
| 467 | - if (!KTUtil::isAbsolutePath($config_file)) { $config_file = sprintf('%s/%s', KT_DIR, $config_file); } | ||
| 468 | - | ||
| 469 | - $exists = file_exists($cache_file); | ||
| 470 | - if ($exists) { | ||
| 471 | - $cachestat = stat($cache_file); | ||
| 472 | - $configstat = stat($config_file); | 475 | + $configPath = str_replace('//', '/', $configPath); |
| 476 | + $configPath = str_replace('\\\\', '\\', $configPath); | ||
| 477 | + | ||
| 478 | + // This check can be removed once all config settings are in the database | ||
| 479 | + // Check if the config file has been updated since the last time the cache file was generated. | ||
| 480 | + if (file_exists($cachePath)) { | ||
| 481 | + $cachestat = stat($cachePath); | ||
| 482 | + $configstat = stat($configPath); | ||
| 473 | $tval = 9; | 483 | $tval = 9; |
| 474 | - // print sprintf("is %d > %d\n", $cachestat[$tval], $configstat[$tval]); | ||
| 475 | if ($cachestat[$tval] > $configstat[$tval]) { | 484 | if ($cachestat[$tval] > $configstat[$tval]) { |
| 476 | $use_cache = true; | 485 | $use_cache = true; |
| 486 | + $store_cache = false; | ||
| 477 | } | 487 | } |
| 478 | } | 488 | } |
| 479 | - } | ||
| 480 | 489 | ||
| 481 | -/* | ||
| 482 | - if ($use_cache) { | ||
| 483 | - $oKTConfig =& KTConfig::getSingleton(); | ||
| 484 | - $oKTConfig->loadCache($cache_file); | 490 | + if ($use_cache) { |
| 491 | + $oKTConfig->loadCache($cachePath); | ||
| 485 | 492 | ||
| 486 | - foreach ($oKTConfig->flat as $k => $v) { | ||
| 487 | - $default->$k = $oKTConfig->get($k); | ||
| 488 | - } | ||
| 489 | - } else { | ||
| 490 | - //fail safe will be put here | ||
| 491 | - | ||
| 492 | - | ||
| 493 | - if (PEAR::isError($res)) { return $res; } | ||
| 494 | - | ||
| 495 | - //$oKTConfig =& KTConfig::getSingleton(); | ||
| 496 | - @touch($cache_file); | ||
| 497 | - if ($store_cache && is_writable($cache_file)) { | ||
| 498 | - $oKTConfig->createCache($cache_file); | 493 | + foreach ($oKTConfig->flat as $k => $v) { |
| 494 | + $default->$k = $oKTConfig->get($k); | ||
| 495 | + } | ||
| 499 | } | 496 | } |
| 497 | + } | ||
| 498 | + | ||
| 499 | + //Read in DB settings and config settings | ||
| 500 | + if(!$use_cache) $oKTConfig->readDBConfig(); | ||
| 501 | + $dbSetup = $oKTConfig->setupDB(); | ||
| 502 | + | ||
| 503 | + if(PEAR::isError($dbSetup)) | ||
| 504 | + { | ||
| 505 | + $this->handleInitError($dbSetup); | ||
| 506 | + } | ||
| 507 | + | ||
| 508 | + // Get default server url settings | ||
| 509 | + if(!$use_cache) $this->getDynamicConfigSettings(); | ||
| 510 | + | ||
| 511 | + // Read in the config settings from the database | ||
| 512 | + // Create the global $default array | ||
| 513 | + if(!$use_cache) $res = $oKTConfig->readConfig(); | ||
| 500 | 514 | ||
| 501 | 515 | ||
| 516 | + if($store_cache && isset($cachePath)){ | ||
| 517 | + @touch($cachePath); | ||
| 518 | + if (is_writable($cachePath)) { | ||
| 519 | + $oKTConfig->createCache($cachePath); | ||
| 520 | + } | ||
| 502 | } | 521 | } |
| 503 | -*/ | ||
| 504 | } | 522 | } |
| 505 | // }}} | 523 | // }}} |
| 506 | 524 | ||
| 507 | - | 525 | + |
| 508 | 526 | ||
| 509 | // {{{ initTesting | 527 | // {{{ initTesting |
| 510 | function initTesting() { | 528 | function initTesting() { |
| @@ -530,31 +548,11 @@ class KTInit { | @@ -530,31 +548,11 @@ class KTInit { | ||
| 530 | } | 548 | } |
| 531 | // }}} | 549 | // }}} |
| 532 | 550 | ||
| 533 | -//Creating all the config settings | ||
| 534 | -//==================================== | ||
| 535 | -$oKTConfig = KTConfig::getSingleton(); | ||
| 536 | - | ||
| 537 | -//Read in DB specific config settings | ||
| 538 | -$res = $oKTConfig->readDBConfig(); | ||
| 539 | -//Set up DB connection | ||
| 540 | -$dbSetup = $oKTConfig->setupDB(); | ||
| 541 | 551 | ||
| 542 | $KTInit = new KTInit(); | 552 | $KTInit = new KTInit(); |
| 543 | - | ||
| 544 | -if(PEAR::isError($dbSetup)) | ||
| 545 | -{ | ||
| 546 | - $KTInit->handleInitError($dbSetup); | ||
| 547 | -} | ||
| 548 | - | ||
| 549 | - | ||
| 550 | - | ||
| 551 | -$KTInit->getDynamicConfigSettings(); | ||
| 552 | $KTInit->initConfig(); | 553 | $KTInit->initConfig(); |
| 553 | $KTInit->setupI18n(); | 554 | $KTInit->setupI18n(); |
| 554 | 555 | ||
| 555 | -//Create final flatns and $default arrays to finish config setup | ||
| 556 | -$res = $oKTConfig->readConfig(); | ||
| 557 | - | ||
| 558 | //==================================== | 556 | //==================================== |
| 559 | 557 | ||
| 560 | define('KTLOG_CACHE',false); | 558 | define('KTLOG_CACHE',false); |
| @@ -563,8 +561,7 @@ if (isset($GLOBALS['kt_test'])) { | @@ -563,8 +561,7 @@ if (isset($GLOBALS['kt_test'])) { | ||
| 563 | $KTInit->initTesting(); | 561 | $KTInit->initTesting(); |
| 564 | } | 562 | } |
| 565 | 563 | ||
| 566 | - | ||
| 567 | - | 564 | +$oKTConfig = KTConfig::getSingleton(); |
| 568 | 565 | ||
| 569 | if($oKTConfig->get('CustomErrorMessages/customerrormessages') == 'on') | 566 | if($oKTConfig->get('CustomErrorMessages/customerrormessages') == 'on') |
| 570 | { | 567 | { |
lib/config/config.inc.php
| @@ -6,31 +6,31 @@ | @@ -6,31 +6,31 @@ | ||
| 6 | * Document Management Made Simple | 6 | * Document Management Made Simple |
| 7 | * Copyright (C) 2008 KnowledgeTree Inc. | 7 | * Copyright (C) 2008 KnowledgeTree Inc. |
| 8 | * Portions copyright The Jam Warehouse Software (Pty) Limited | 8 | * Portions copyright The Jam Warehouse Software (Pty) Limited |
| 9 | - * | 9 | + * |
| 10 | * This program is free software; you can redistribute it and/or modify it under | 10 | * This program is free software; you can redistribute it and/or modify it under |
| 11 | * the terms of the GNU General Public License version 3 as published by the | 11 | * the terms of the GNU General Public License version 3 as published by the |
| 12 | * Free Software Foundation. | 12 | * Free Software Foundation. |
| 13 | - * | 13 | + * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT | 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 16 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 17 | * details. | 17 | * details. |
| 18 | - * | 18 | + * |
| 19 | * You should have received a copy of the GNU General Public License | 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | - * | ||
| 22 | - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | 21 | + * |
| 22 | + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | ||
| 23 | * California 94120-7775, or email info@knowledgetree.com. | 23 | * California 94120-7775, or email info@knowledgetree.com. |
| 24 | - * | 24 | + * |
| 25 | * The interactive user interfaces in modified source and object code versions | 25 | * The interactive user interfaces in modified source and object code versions |
| 26 | * of this program must display Appropriate Legal Notices, as required under | 26 | * of this program must display Appropriate Legal Notices, as required under |
| 27 | * Section 5 of the GNU General Public License version 3. | 27 | * Section 5 of the GNU General Public License version 3. |
| 28 | - * | 28 | + * |
| 29 | * In accordance with Section 7(b) of the GNU General Public License version 3, | 29 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 30 | * these Appropriate Legal Notices must retain the display of the "Powered by | 30 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 31 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | 31 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the |
| 32 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | 32 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 33 | - * must display the words "Powered by KnowledgeTree" and retain the original | 33 | + * must display the words "Powered by KnowledgeTree" and retain the original |
| 34 | * copyright notice. | 34 | * copyright notice. |
| 35 | * Contributor( s): ______________________________________ | 35 | * Contributor( s): ______________________________________ |
| 36 | * | 36 | * |
| @@ -44,11 +44,10 @@ require_once (KT_LIB_DIR. '/database/dbutil.inc'); | @@ -44,11 +44,10 @@ require_once (KT_LIB_DIR. '/database/dbutil.inc'); | ||
| 44 | class KTConfig { | 44 | class KTConfig { |
| 45 | var $conf = array(); | 45 | var $conf = array(); |
| 46 | var $aSectionFile; | 46 | var $aSectionFile; |
| 47 | - var $aFileRoot; | ||
| 48 | var $flat = array(); | 47 | var $flat = array(); |
| 49 | var $flatns = array(); | 48 | var $flatns = array(); |
| 50 | - var $aDBConfig = array(); | ||
| 51 | - var $aConfFile = array(); | 49 | + var $expanded = array(); |
| 50 | + var $expanding = array(); | ||
| 52 | 51 | ||
| 53 | // FIXME nbm: how do we cache errors here? | 52 | // FIXME nbm: how do we cache errors here? |
| 54 | function loadCache($filename) { | 53 | function loadCache($filename) { |
| @@ -58,62 +57,44 @@ class KTConfig { | @@ -58,62 +57,44 @@ class KTConfig { | ||
| 58 | $this->flatns = $config_cache['flatns']; | 57 | $this->flatns = $config_cache['flatns']; |
| 59 | $this->expanded = $config_cache['expanded']; | 58 | $this->expanded = $config_cache['expanded']; |
| 60 | $this->expanding = $config_cache['expanding']; | 59 | $this->expanding = $config_cache['expanding']; |
| 61 | - /* | ||
| 62 | - print "----- Me\n"; | ||
| 63 | - unset($this->aFileRoot); | ||
| 64 | - unset($this->aSectionFile); | ||
| 65 | - var_dump($this); | ||
| 66 | - print "----- Cache\n"; | ||
| 67 | - var_dump($config_cache); | ||
| 68 | - */ | ||
| 69 | - | ||
| 70 | return true; | 60 | return true; |
| 71 | } | 61 | } |
| 72 | - | 62 | + |
| 63 | + function createCache($filename) { | ||
| 64 | + $config_cache = array(); | ||
| 65 | + $config_cache['flat'] = $this->flat; | ||
| 66 | + $config_cache['flatns'] = $this->flatns; | ||
| 67 | + $config_cache['expanded'] = $this->expanded; | ||
| 68 | + $config_cache['expanding'] = $this->expanding; | ||
| 69 | + | ||
| 70 | + file_put_contents($filename, serialize($config_cache)); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | // {{{ readConfig | 73 | // {{{ readConfig |
| 74 | function readConfig () { | 74 | function readConfig () { |
| 75 | global $default; | 75 | global $default; |
| 76 | - | 76 | + |
| 77 | //Load config data from the database | 77 | //Load config data from the database |
| 78 | $sQuery = 'select group_name, item, value, default_value from config_settings'; | 78 | $sQuery = 'select group_name, item, value, default_value from config_settings'; |
| 79 | $confResult = DBUtil::getResultArray($sQuery); | 79 | $confResult = DBUtil::getResultArray($sQuery); |
| 80 | 80 | ||
| 81 | - foreach ($confResult as $confItem) | 81 | + foreach ($confResult as $confItem) |
| 82 | { | 82 | { |
| 83 | - | ||
| 84 | - //if $aConfFile doesn't contain the value already set the value | ||
| 85 | - | ||
| 86 | - if(!isset($this->aConfFile[$confItem['group_name']][$confItem['item']]) || $this->aConfFile[$confItem['group_name']][$confItem['item']] == 'default') | ||
| 87 | - { | ||
| 88 | - if($confItem['value'] != 'default') | ||
| 89 | - { | ||
| 90 | - $this->flatns[$confItem['group_name'].'/'.$confItem['item']] = $confItem['value']; | ||
| 91 | - $this->flat[$confItem['item']] = $confItem['value']; | ||
| 92 | - | ||
| 93 | - } | ||
| 94 | - else | ||
| 95 | - { | ||
| 96 | - $this->flatns[$confItem['group_name'].'/'.$confItem['item']] = $confItem['default_value']; | ||
| 97 | - $this->flat[$confItem['item']] = $confItem['default_value']; | ||
| 98 | - | ||
| 99 | - } | ||
| 100 | - } | ||
| 101 | - else //if $aConfFile does have the value set $default and flatns with $aConfFile | ||
| 102 | - { | ||
| 103 | - $this->flatns[$confItem['group_name'].'/'.$confItem['item']] = $this->aConfFile[$confItem['group_name']][$confItem['item']]; | ||
| 104 | - $this->flat[$confItem['item']] = $this->aConfFile[$confItem['group_name']][$confItem['item']]; | ||
| 105 | - | 83 | + if(!isset($this->flatns[$confItem['group_name'].'/'.$confItem['item']])){ |
| 84 | + $this->setns($confItem['group_name'], $confItem['item'], $confItem['value'], $confItem['default_value']); | ||
| 106 | } | 85 | } |
| 107 | } | 86 | } |
| 87 | + | ||
| 88 | + // Populate the global $default array | ||
| 108 | foreach($this->flatns as $sGroupItem => $sValue) | 89 | foreach($this->flatns as $sGroupItem => $sValue) |
| 109 | { | 90 | { |
| 110 | $aGroupItemArray = explode('/', $sGroupItem); | 91 | $aGroupItemArray = explode('/', $sGroupItem); |
| 111 | $default->$aGroupItemArray[1] = $this->expand($this->flatns[$sGroupItem]); | 92 | $default->$aGroupItemArray[1] = $this->expand($this->flatns[$sGroupItem]); |
| 112 | } | 93 | } |
| 113 | - | 94 | + |
| 114 | } | 95 | } |
| 115 | // }}} | 96 | // }}} |
| 116 | - | 97 | + |
| 117 | // {{{ readDBConfig() | 98 | // {{{ readDBConfig() |
| 118 | function readDBConfig() | 99 | function readDBConfig() |
| 119 | { | 100 | { |
| @@ -125,7 +106,7 @@ class KTConfig { | @@ -125,7 +106,7 @@ class KTConfig { | ||
| 125 | } | 106 | } |
| 126 | } | 107 | } |
| 127 | // }}} | 108 | // }}} |
| 128 | - | 109 | + |
| 129 | // {{{ loadDBFile() | 110 | // {{{ loadDBFile() |
| 130 | function loadDBFile($filename, $bDefault = false) | 111 | function loadDBFile($filename, $bDefault = false) |
| 131 | { | 112 | { |
| @@ -136,27 +117,22 @@ class KTConfig { | @@ -136,27 +117,22 @@ class KTConfig { | ||
| 136 | return $root; | 117 | return $root; |
| 137 | } | 118 | } |
| 138 | 119 | ||
| 139 | - $this->aFileRoot[$filename] =& $root; | ||
| 140 | - | ||
| 141 | - $conf =& $root->toArray(); | ||
| 142 | - | ||
| 143 | - //Set the database specific config details here | ||
| 144 | - $this->aDBConfig = $conf['root']['db']; | ||
| 145 | - | ||
| 146 | - //load entire config file into $aConfFile array | ||
| 147 | - //These values will override those given by the database | ||
| 148 | - //This is in case the system fails and the user cannot get to the admin page | ||
| 149 | - //all items given the value default will be poplulated either by the DB or | ||
| 150 | - //by the setdefaultns function | ||
| 151 | - foreach($conf['root'] as $sItem => $sValue) | ||
| 152 | - { | ||
| 153 | - $this->aConfFile[$sItem] = $sValue; | 120 | + $conf = $root->toArray(); |
| 121 | + | ||
| 122 | + // Populate the flat and flatns array with the settings from the config file | ||
| 123 | + // These setting will be overwritten with the settings from the database. | ||
| 124 | + if(isset($conf['root']) && !empty($conf['root'])){ | ||
| 125 | + foreach($conf['root'] as $group => $item){ | ||
| 126 | + foreach ($item as $key => $value){ | ||
| 127 | + $this->setns($group, $key, $value, false); | ||
| 128 | + } | ||
| 129 | + } | ||
| 154 | } | 130 | } |
| 155 | - | ||
| 156 | } | 131 | } |
| 157 | // }}} | 132 | // }}} |
| 158 | - | 133 | + |
| 159 | function setupDB () { | 134 | function setupDB () { |
| 135 | + | ||
| 160 | global $default; | 136 | global $default; |
| 161 | 137 | ||
| 162 | require_once('DB.php'); | 138 | require_once('DB.php'); |
| @@ -171,27 +147,25 @@ class KTConfig { | @@ -171,27 +147,25 @@ class KTConfig { | ||
| 171 | // KTEntity is the database-backed base class | 147 | // KTEntity is the database-backed base class |
| 172 | require_once(KT_LIB_DIR . '/ktentity.inc'); | 148 | require_once(KT_LIB_DIR . '/ktentity.inc'); |
| 173 | 149 | ||
| 174 | - | ||
| 175 | - | ||
| 176 | $prefix = defined('USE_DB_ADMIN_USER')?'Admin':''; | 150 | $prefix = defined('USE_DB_ADMIN_USER')?'Admin':''; |
| 177 | 151 | ||
| 178 | - $sUser = 'dbUser'; | ||
| 179 | - $sPass = 'dbPass'; | ||
| 180 | - | 152 | + $sUser = 'db/dbUser'; |
| 153 | + $sPass = 'db/dbPass'; | ||
| 154 | + | ||
| 181 | if ($prefix == 'Admin') | 155 | if ($prefix == 'Admin') |
| 182 | { | 156 | { |
| 183 | - $sUser = 'dbAdminUser'; | ||
| 184 | - $sPass = 'dbAdminPass'; | 157 | + $sUser = 'db/dbAdminUser'; |
| 158 | + $sPass = 'db/dbAdminPass'; | ||
| 185 | } | 159 | } |
| 186 | $dsn = array( | 160 | $dsn = array( |
| 187 | - 'phptype' => $this->aDBConfig['dbType'], | ||
| 188 | - 'username' => $this->aDBConfig[$sUser], | ||
| 189 | - 'password' => $this->aDBConfig[$sPass], | ||
| 190 | - 'hostspec' => $this->aDBConfig['dbHost'], | ||
| 191 | - 'database' => $this->aDBConfig['dbName'], | ||
| 192 | - 'port' => $this->aDBConfig['dbPort'] | 161 | + 'phptype' => $this->flatns['db/dbType'], |
| 162 | + 'username' => $this->flatns[$sUser], | ||
| 163 | + 'password' => $this->flatns[$sPass], | ||
| 164 | + 'hostspec' => $this->flatns['db/dbHost'], | ||
| 165 | + 'database' => $this->flatns['db/dbName'], | ||
| 166 | + 'port' => $this->flatns['db/dbPort'] | ||
| 193 | ); | 167 | ); |
| 194 | - | 168 | + |
| 195 | $options = array( | 169 | $options = array( |
| 196 | 'debug' => 2, | 170 | 'debug' => 2, |
| 197 | 'portability' => DB_PORTABILITY_ERRORS, | 171 | 'portability' => DB_PORTABILITY_ERRORS, |
| @@ -204,24 +178,14 @@ class KTConfig { | @@ -204,24 +178,14 @@ class KTConfig { | ||
| 204 | return $default->_db; | 178 | return $default->_db; |
| 205 | } | 179 | } |
| 206 | $default->_db->setFetchMode(DB_FETCHMODE_ASSOC); | 180 | $default->_db->setFetchMode(DB_FETCHMODE_ASSOC); |
| 207 | - | ||
| 208 | - } | ||
| 209 | - | ||
| 210 | - function createCache($filename) { | ||
| 211 | - $config_cache = array(); | ||
| 212 | - $config_cache['flat'] = $this->flat; | ||
| 213 | - $config_cache['flatns'] = $this->flatns; | ||
| 214 | - $config_cache['expanded'] = $this->expanded; | ||
| 215 | - $config_cache['expanding'] = $this->expanding; | ||
| 216 | - | ||
| 217 | - file_put_contents($filename, serialize($config_cache)); | ||
| 218 | - | ||
| 219 | - | ||
| 220 | } | 181 | } |
| 221 | 182 | ||
| 222 | function setns($seck, $k, $v, $bDefault = false) { | 183 | function setns($seck, $k, $v, $bDefault = false) { |
| 223 | if ($v === "default") { | 184 | if ($v === "default") { |
| 224 | - return; | 185 | + if($bDefault === false){ |
| 186 | + return; | ||
| 187 | + } | ||
| 188 | + $v = $bDefault; | ||
| 225 | } elseif ($v === "true") { | 189 | } elseif ($v === "true") { |
| 226 | $v = true; | 190 | $v = true; |
| 227 | } elseif ($v === "false") { | 191 | } elseif ($v === "false") { |
| @@ -238,8 +202,6 @@ class KTConfig { | @@ -238,8 +202,6 @@ class KTConfig { | ||
| 238 | return $this->setns($seck, $k, $v, true); | 202 | return $this->setns($seck, $k, $v, true); |
| 239 | } | 203 | } |
| 240 | 204 | ||
| 241 | - var $expanded = array(); | ||
| 242 | - var $expanding = array(); | ||
| 243 | function expand($val) { | 205 | function expand($val) { |
| 244 | if (strpos($val, '$') === false) { | 206 | if (strpos($val, '$') === false) { |
| 245 | return $val; | 207 | return $val; |
| @@ -258,8 +220,6 @@ class KTConfig { | @@ -258,8 +220,6 @@ class KTConfig { | ||
| 258 | } | 220 | } |
| 259 | 221 | ||
| 260 | function get($var, $oDefault = null) { | 222 | function get($var, $oDefault = null) { |
| 261 | - | ||
| 262 | - | ||
| 263 | if (array_key_exists($var, $this->flatns)) { | 223 | if (array_key_exists($var, $this->flatns)) { |
| 264 | return $this->expand($this->flatns[$var]); | 224 | return $this->expand($this->flatns[$var]); |
| 265 | } | 225 | } |