From 552b7f136a9a7347b96399dae1e750b1334ba8a9 Mon Sep 17 00:00:00 2001 From: Megan Watson Date: Fri, 1 Aug 2008 13:36:29 +0000 Subject: [PATCH] KTS-3410 "Upgrade does not work when upgrading to 3.5.3 with new DB config setup." Fixed. Added upgrade function to copy config values from config.ini to the database table. --- config/dmsDefaults.php | 19 +++++++++---------- lib/config/config.inc.php | 56 ++++++++++++++++++++++++++++++++++---------------------- lib/database/dbutil.inc | 6 ++++-- lib/upgrades/UpgradeFunctions.inc.php | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- setup/upgrade.php | 4 ++++ sql/mysql/install/data.sql | 15 ++++++++------- sql/mysql/upgrade/3.5.3/add_autoinc.sql | 1 - sql/mysql/upgrade/3.5.3/config_settings.sql | 15 ++++++++------- 8 files changed, 143 insertions(+), 60 deletions(-) diff --git a/config/dmsDefaults.php b/config/dmsDefaults.php index 9be47c9..443a8b6 100644 --- a/config/dmsDefaults.php +++ b/config/dmsDefaults.php @@ -455,16 +455,18 @@ class KTInit { } if ($use_cache) { - $oKTConfig->loadCache($cachePath); - - foreach ($oKTConfig->flat as $k => $v) { - $default->$k = $oKTConfig->get($k); - } + $use_cache = $oKTConfig->loadCache($cachePath); } } - //Read in DB settings and config settings - if(!$use_cache) $oKTConfig->readDBConfig(); + if(!$use_cache) { + // Get default server url settings + $this->getDynamicConfigSettings(); + + //Read in DB settings and config settings + $oKTConfig->readDBConfig(); + } + $dbSetup = $oKTConfig->setupDB(); if(PEAR::isError($dbSetup)) @@ -474,9 +476,6 @@ class KTInit { $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(); diff --git a/lib/config/config.inc.php b/lib/config/config.inc.php index c9d9339..356482c 100644 --- a/lib/config/config.inc.php +++ b/lib/config/config.inc.php @@ -85,6 +85,11 @@ class KTConfig { $this->flatns = $config_cache['flatns']; $this->expanded = $config_cache['expanded']; $this->expanding = $config_cache['expanding']; + + if(empty($this->flatns)){ + return false; + } + $this->populateDefault(); return true; } @@ -115,44 +120,43 @@ class KTConfig { // {{{ 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); + if(PEAR::isError($confResult)){ + return $confResult; + } + + // Update the config array - overwrite the current settings with the settings in the database. foreach ($confResult as $confItem) { - if(!isset($this->flatns[$confItem['group_name'].'/'.$confItem['item']])){ - $this->setns($confItem['group_name'], $confItem['item'], $confItem['value'], $confItem['default_value']); - } + $this->setns($confItem['group_name'], $confItem['item'], $confItem['value'], $confItem['default_value']); } + $this->populateDefault(); + } + // }}} + + /** + * Populate the global default array + * + */ + function populateDefault() + { + global $default; - // 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() { - $sConfigFile = trim(file_get_contents(KT_DIR . '/config/config-path')); - if (KTUtil::isAbsolutePath($sConfigFile)) { - $res = $this->loadDBFile($sConfigFile); - } else { - $res = $this->loadDBFile(sprintf('%s/%s', KT_DIR, $sConfigFile)); - } - } - // }}} + $filename = $this->getConfigFilename(); - // {{{ loadDBFile() - function loadDBFile($filename, $bDefault = false) - { $c = new Config; $root =& $c->parseConfig($filename, "IniCommented"); @@ -171,6 +175,7 @@ class KTConfig { } } } + $this->populateDefault(); } // }}} @@ -224,16 +229,23 @@ class KTConfig { } function setns($seck, $k, $v, $bDefault = false) { - if ($v === "default") { + // If the value is default then set it to the default value + if ($v === 'default') { + // If there is no default then ignore the value if($bDefault === false){ return; } $v = $bDefault; - } elseif ($v === "true") { + } + + // If the value is true / false, set it as a boolean true / false + if ($v === 'true') { $v = true; - } elseif ($v === "false") { + } elseif ($v === 'false') { $v = false; } + + // Set the config arrays $this->flat[$k] = $v; if (!is_null($seck)) { $this->flatns["$seck/$k"] = $v; diff --git a/lib/database/dbutil.inc b/lib/database/dbutil.inc index f221dbc..cbece5a 100644 --- a/lib/database/dbutil.inc +++ b/lib/database/dbutil.inc @@ -130,12 +130,14 @@ class DBUtil { function logQueryError($query, $result) { global $default; - if (!$default->queryLog->isDebugEnabled()) + if (isset($default->queryLog) && !$default->queryLog->isDebugEnabled()) { // if debug is enabled, the query is already logged. $default->queryLog->error($query); } - $default->log->error('Query error: ' . $result->getMessage()); + if(isset($default->log)){ + $default->log->error('Query error: ' . $result->getMessage()); + } } function runQueries($aQueries, $db = null) { diff --git a/lib/upgrades/UpgradeFunctions.inc.php b/lib/upgrades/UpgradeFunctions.inc.php index 6067706..644951c 100644 --- a/lib/upgrades/UpgradeFunctions.inc.php +++ b/lib/upgrades/UpgradeFunctions.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): ______________________________________ * @@ -61,6 +61,7 @@ class UpgradeFunctions { '3.1.6.3' => array('cleanupGroupMembership'), '3.5.0' => array('cleanupOldKTAdminVersionNotifier', 'updateConfigFile35', 'registerIndexingTasks'), '3.5.2' => array('setStorageEngine','dropForeignKeys','dropPrimaryKeys','dropIndexes','createPrimaryKeys','createForeignKeys','createIndexes', 'removeSlashesFromObjects'), + '3.5.3' => array('moveConfigSettingsToDB') ); var $descriptions = array( @@ -90,7 +91,8 @@ class UpgradeFunctions { 'createPrimaryKeys'=>'Recreate db integrity:Create primary keys on the database', 'createForeignKeys'=>'Recreate db integrity:Create foreign keys on the database', 'createIndexes'=>'Recreate db integrity:Create indexes on the database', - 'removeSlashesFromObjects'=>'Remove slashes from documents and folders' + 'removeSlashesFromObjects'=>'Remove slashes from documents and folders', + 'moveConfigSettingsToDB' => 'Move the configuration settings from the config.ini file into the new database table.' ); var $phases = array( "setPermissionFolder" => 1, @@ -109,6 +111,69 @@ class UpgradeFunctions { 'createIndexes'=>7, ); + function moveConfigSettingsToDB() + { + require_once('Config.php'); + + // Get config settings from config.ini + $oKTConfig = KTConfig::getSingleton(); + $configPath = $oKTConfig->getConfigFilename(); + + $c = new Config; + $root =& $c->parseConfig($configPath, "IniCommented"); + + if (PEAR::isError($root)) { + return $root; + } + + $confRoot = $root->toArray(); + $conf = $confRoot['root']; + + // Get the default settings from the database + $query = "SELECT id, s.group_name, s.item, s.value, s.default_value + FROM config_settings s + ORDER BY group_name, item"; + + $settings = DBUtil::getResultArray($query); + + if(PEAR::isError($settings)){ + return $settings; + } + + // update the settings in the database if not set to default or equal to the default value + foreach ($settings as $item){ + if(!isset($conf[$item['group_name']][$item['item']])){ + continue; // Don't overwrite the default with a null value + } + + $confValue = $conf[$item['group_name']][$item['item']]; + + if($confValue == 'default'){ + continue; // skip over if its set to default + } + + if($confValue == $item['value']){ + continue; // skip over if it already has the same value + } + + if($confValue == $item['default_value']){ + if($item['value'] == 'default' || $item['value'] == $item['default_value']){ + continue; // skip over if it has the same value as the default value + } + // Set the value to default + $confValue = 'default'; + } + + // Update the setting + $res = DBUtil::autoUpdate('config_settings', array('value' => $confValue), $item['id']); + + if(PEAR::isError($res)){ + return $res; + } + } + return true; + } + function dropForeignKeys() { $schemautil = KTSchemaUtil::getSingleton(); @@ -1154,7 +1219,7 @@ class UpgradeFunctions { $ini->write(); } -*/ +*/ } // }}} diff --git a/setup/upgrade.php b/setup/upgrade.php index 0c36aeb..9ea42d8 100644 --- a/setup/upgrade.php +++ b/setup/upgrade.php @@ -151,6 +151,10 @@ function performPostUpgradeActions() { unlink($lockFile); } + // Clear the configuration cache, it'll regenerate on next load + $oKTConfig = new KTConfig(); + $oKTConfig->clearCache(); + // Clean out the plugin_helper table $sql = "DELETE FROM plugin_helper"; $res = DBUtil::runQuery($sql); diff --git a/sql/mysql/install/data.sql b/sql/mysql/install/data.sql index 3393a35..40048cc 100644 --- a/sql/mysql/install/data.sql +++ b/sql/mysql/install/data.sql @@ -161,7 +161,8 @@ INSERT INTO `config_groups` VALUES (21, 'ui', 'User Interface', 'General user interface configuration', 'User Interface Settings'), (22, 'urls', 'Urls', 'KnowledgeTree server and filesystem paths (Advanced users only).', 'User Interface Settings'), (23, 'user_prefs', 'User Preferences', 'User interface preferences', 'User Interface Settings'), -(24, 'webservice', 'Web Services', 'KnowledgeTree Web Service Interface configuration. Note that a number of KnowledgeTree Tools rely on this service.', 'Client Tools Setting'); +(24, 'webservice', 'Web Services', 'KnowledgeTree Web Service Interface configuration. Note that a number of KnowledgeTree Tools rely on this service.', 'Client Tools Setting'), +(25, 'ldapAuthentication', 'LDAP Authentication', 'Configuration of the ldap authentication.', 'General Settings'); /*!40000 ALTER TABLE `config_groups` ENABLE KEYS */; UNLOCK TABLES; @@ -278,12 +279,12 @@ INSERT INTO `config_settings` VALUES (104, 'cache', 'Cache Enabled', 'Plugin cache configuration', 'cacheEnabled', 'default', 'false', 'boolean', NULL, 1), (105, 'cache', 'Cache Directory', 'Plugin cache path', 'cacheDirectory', 'default', '${varDirectory}/cache', '', NULL, 1), (106, 'cache', 'Cache Plugins', 'Plugins cache', 'cachePlugins', 'default', 'true', 'boolean', NULL, 1), -(107, 'urls', 'Var Directory', 'Path to var directory', 'varDirectory', 'default', '${fileSystemRoot}/var', '', NULL, 1), -(108, 'openoffice', 'Program Path', 'The Open Office program directory.', 'programPath', 'default', '../openoffice/program', 'string', NULL, 1), -(109, 'urls', 'documentRoot', '', 'documentRoot', 'default', '${varDirectory}/Documents', '', NULL, 0), -(110, 'KnowledgeTree', 'redirectToBrowse', 'set to true to redirect to browse screen ', 'redirectToBrowse', 'default', 'false', 'boolean', NULL, 1), -(111, 'KnowledgeTree', 'redirectToBrowseExceptions', 'if redirectToBrowse is true, adding usernames to this list will force specific users to be redirected to dashboard e.g. redirectToBrowseExceptions = admin, joebloggs ', 'redirectToBrowseExceptions', 'default', '', '', NULL, 1), -(112, 'session', 'Allow automatic sign in', 'If a user doesn''t exist in the system, the account will be created on first login.', 'allowAutoSignup', 'default', 'false', 'boolean', '', 1); +(107, 'openoffice', 'Program Path', 'The Open Office program directory.', 'programPath', 'default', '../openoffice/program', 'string', NULL, 1), +(108, 'urls', 'documentRoot', '', 'documentRoot', 'default', '${varDirectory}/Documents', '', NULL, 0), +(109, 'KnowledgeTree', 'redirectToBrowse', 'set to true to redirect to browse screen ', 'redirectToBrowse', 'default', 'false', 'boolean', NULL, 1), +(110, 'KnowledgeTree', 'redirectToBrowseExceptions', 'if redirectToBrowse is true, adding usernames to this list will force specific users to be redirected to dashboard e.g. redirectToBrowseExceptions = admin, joebloggs ', 'redirectToBrowseExceptions', 'default', '', '', NULL, 1), +(111, 'session', 'Allow automatic sign in', 'If a user doesn''t exist in the system, the account will be created on first login.', 'allowAutoSignup', 'default', 'false', 'boolean', '', 1), +(112, 'ldapAuthentication', 'Automatic group creation', 'Automatically create the ldap groups.', 'autoGroupCreation', 'default', 'false', 'boolean', '', 1); /*!40000 ALTER TABLE `config_settings` ENABLE KEYS */; UNLOCK TABLES; diff --git a/sql/mysql/upgrade/3.5.3/add_autoinc.sql b/sql/mysql/upgrade/3.5.3/add_autoinc.sql index 74771c4..7bf4294 100644 --- a/sql/mysql/upgrade/3.5.3/add_autoinc.sql +++ b/sql/mysql/upgrade/3.5.3/add_autoinc.sql @@ -4,7 +4,6 @@ alter table archiving_settings change `id` `id` int (11) NOT NULL AUTO_INCREMEN alter table archiving_type_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT; alter table authentication_sources change `id` `id` int (11) NOT NULL AUTO_INCREMENT; alter table column_entries change `id` `id` int (11) NOT NULL AUTO_INCREMENT; -alter table config_settings change `id` `id` int (11) NOT NULL AUTO_INCREMENT; alter table dashlet_disables change `id` `id` int (11) NOT NULL AUTO_INCREMENT; alter table data_types change `id` `id` int (11) NOT NULL AUTO_INCREMENT; alter table discussion_comments change `id` `id` int (11) NOT NULL AUTO_INCREMENT; diff --git a/sql/mysql/upgrade/3.5.3/config_settings.sql b/sql/mysql/upgrade/3.5.3/config_settings.sql index 9aaad18..f371da0 100644 --- a/sql/mysql/upgrade/3.5.3/config_settings.sql +++ b/sql/mysql/upgrade/3.5.3/config_settings.sql @@ -40,7 +40,8 @@ INSERT INTO `config_groups` VALUES (21, 'ui', 'User Interface', 'General user interface configuration', 'User Interface Settings'), (22, 'urls', 'Urls', 'KnowledgeTree server and filesystem paths (Advanced users only).', 'User Interface Settings'), (23, 'user_prefs', 'User Preferences', 'User interface preferences', 'User Interface Settings'), -(24, 'webservice', 'Web Services', 'KnowledgeTree Web Service Interface configuration. Note that a number of KnowledgeTree Tools rely on this service. ', 'Client Tools Settings'); +(24, 'webservice', 'Web Services', 'KnowledgeTree Web Service Interface configuration. Note that a number of KnowledgeTree Tools rely on this service. ', 'Client Tools Settings'), +(25, 'ldapAuthentication', 'LDAP Authentication', 'Configuration of the ldap authentication.', 'General Settings'); -- -------------------------------------------------------- @@ -173,9 +174,9 @@ INSERT INTO `config_settings` VALUES (104, 'cache', 'Cache Enabled', 'Plugin cache configuration', 'cacheEnabled', 'default', 'false', 'boolean', NULL, 1), (105, 'cache', 'Cache Directory', 'Plugin cache path', 'cacheDirectory', 'default', '${varDirectory}/cache', '', NULL, 1), (106, 'cache', 'Cache Plugins', 'Plugins cache', 'cachePlugins', 'default', 'true', 'boolean', NULL, 1), -(107, 'urls', 'Var Directory', 'Path to var directory', 'varDirectory', 'default', '${fileSystemRoot}/var', '', NULL, 1), -(108, 'openoffice', 'Program Path', 'The Open Office program directory.', 'programPath', 'default', '../openoffice/program', 'string', NULL, 1), -(109, 'urls', 'documentRoot', '', 'documentRoot', 'default', '${varDirectory}/Documents', '', NULL, 0), -(110, 'KnowledgeTree', 'redirectToBrowse', 'set to true to redirect to browse screen ', 'redirectToBrowse', 'default', 'false', 'boolean', NULL, 1), -(111, 'KnowledgeTree', 'redirectToBrowseExceptions', 'if redirectToBrowse is true, adding usernames to this list will force specific users to be redirected to dashboard e.g. redirectToBrowseExceptions = admin, joebloggs ', 'redirectToBrowseExceptions', 'default', '', '', NULL, 1), -(112, 'session', 'Allow automatic sign in', 'If a user doesn''t exist in the system, the account will be created on first login.', 'allowAutoSignup', 'default', 'false', 'boolean', '', 1); \ No newline at end of file +(107, 'openoffice', 'Program Path', 'The Open Office program directory.', 'programPath', 'default', '../openoffice/program', 'string', NULL, 1), +(108, 'urls', 'documentRoot', '', 'documentRoot', 'default', '${varDirectory}/Documents', '', NULL, 0), +(109, 'KnowledgeTree', 'redirectToBrowse', 'set to true to redirect to browse screen ', 'redirectToBrowse', 'default', 'false', 'boolean', NULL, 1), +(110, 'KnowledgeTree', 'redirectToBrowseExceptions', 'if redirectToBrowse is true, adding usernames to this list will force specific users to be redirected to dashboard e.g. redirectToBrowseExceptions = admin, joebloggs ', 'redirectToBrowseExceptions', 'default', '', '', NULL, 1), +(111, 'session', 'Allow automatic sign in', 'If a user doesn''t exist in the system, the account will be created on first login.', 'allowAutoSignup', 'default', 'false', 'boolean', '', 1), +(112, 'ldapAuthentication', 'Automatic group creation', 'Automatically create the ldap groups.', 'autoGroupCreation', 'default', 'false', 'boolean', '', 1); \ No newline at end of file -- libgit2 0.21.4