Commit 552b7f136a9a7347b96399dae1e750b1334ba8a9

Authored by Megan Watson
1 parent 5178bbad

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.

KTS-3405
"Auto group creation option has been removed from the config.ini file"
Fixed. Added the new config option.

Committed by: Megan Watson 
Reviewed by: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8928 c91229c3-7414-0410-bfa2-8a42b809f60b
config/dmsDefaults.php
... ... @@ -455,16 +455,18 @@ class KTInit {
455 455 }
456 456  
457 457 if ($use_cache) {
458   - $oKTConfig->loadCache($cachePath);
459   -
460   - foreach ($oKTConfig->flat as $k => $v) {
461   - $default->$k = $oKTConfig->get($k);
462   - }
  458 + $use_cache = $oKTConfig->loadCache($cachePath);
463 459 }
464 460 }
465 461  
466   - //Read in DB settings and config settings
467   - if(!$use_cache) $oKTConfig->readDBConfig();
  462 + if(!$use_cache) {
  463 + // Get default server url settings
  464 + $this->getDynamicConfigSettings();
  465 +
  466 + //Read in DB settings and config settings
  467 + $oKTConfig->readDBConfig();
  468 + }
  469 +
468 470 $dbSetup = $oKTConfig->setupDB();
469 471  
470 472 if(PEAR::isError($dbSetup))
... ... @@ -474,9 +476,6 @@ class KTInit {
474 476 $this->handleInitError($dbSetup);
475 477 }
476 478  
477   - // Get default server url settings
478   - if(!$use_cache) $this->getDynamicConfigSettings();
479   -
480 479 // Read in the config settings from the database
481 480 // Create the global $default array
482 481 if(!$use_cache) $res = $oKTConfig->readConfig();
... ...
lib/config/config.inc.php
... ... @@ -85,6 +85,11 @@ class KTConfig {
85 85 $this->flatns = $config_cache['flatns'];
86 86 $this->expanded = $config_cache['expanded'];
87 87 $this->expanding = $config_cache['expanding'];
  88 +
  89 + if(empty($this->flatns)){
  90 + return false;
  91 + }
  92 + $this->populateDefault();
88 93 return true;
89 94 }
90 95  
... ... @@ -115,44 +120,43 @@ class KTConfig {
115 120  
116 121 // {{{ readConfig
117 122 function readConfig () {
118   - global $default;
119   -
120 123 //Load config data from the database
121 124 $sQuery = 'select group_name, item, value, default_value from config_settings';
122 125 $confResult = DBUtil::getResultArray($sQuery);
123 126  
  127 + if(PEAR::isError($confResult)){
  128 + return $confResult;
  129 + }
  130 +
  131 + // Update the config array - overwrite the current settings with the settings in the database.
124 132 foreach ($confResult as $confItem)
125 133 {
126   - if(!isset($this->flatns[$confItem['group_name'].'/'.$confItem['item']])){
127   - $this->setns($confItem['group_name'], $confItem['item'], $confItem['value'], $confItem['default_value']);
128   - }
  134 + $this->setns($confItem['group_name'], $confItem['item'], $confItem['value'], $confItem['default_value']);
129 135 }
  136 + $this->populateDefault();
  137 + }
  138 + // }}}
  139 +
  140 + /**
  141 + * Populate the global default array
  142 + *
  143 + */
  144 + function populateDefault()
  145 + {
  146 + global $default;
130 147  
131   - // Populate the global $default array
132 148 foreach($this->flatns as $sGroupItem => $sValue)
133 149 {
134 150 $aGroupItemArray = explode('/', $sGroupItem);
135 151 $default->$aGroupItemArray[1] = $this->expand($this->flatns[$sGroupItem]);
136 152 }
137   -
138 153 }
139   - // }}}
140 154  
141 155 // {{{ readDBConfig()
142 156 function readDBConfig()
143 157 {
144   - $sConfigFile = trim(file_get_contents(KT_DIR . '/config/config-path'));
145   - if (KTUtil::isAbsolutePath($sConfigFile)) {
146   - $res = $this->loadDBFile($sConfigFile);
147   - } else {
148   - $res = $this->loadDBFile(sprintf('%s/%s', KT_DIR, $sConfigFile));
149   - }
150   - }
151   - // }}}
  158 + $filename = $this->getConfigFilename();
152 159  
153   - // {{{ loadDBFile()
154   - function loadDBFile($filename, $bDefault = false)
155   - {
156 160 $c = new Config;
157 161 $root =& $c->parseConfig($filename, "IniCommented");
158 162  
... ... @@ -171,6 +175,7 @@ class KTConfig {
171 175 }
172 176 }
173 177 }
  178 + $this->populateDefault();
174 179 }
175 180 // }}}
176 181  
... ... @@ -224,16 +229,23 @@ class KTConfig {
224 229 }
225 230  
226 231 function setns($seck, $k, $v, $bDefault = false) {
227   - if ($v === "default") {
  232 + // If the value is default then set it to the default value
  233 + if ($v === 'default') {
  234 + // If there is no default then ignore the value
228 235 if($bDefault === false){
229 236 return;
230 237 }
231 238 $v = $bDefault;
232   - } elseif ($v === "true") {
  239 + }
  240 +
  241 + // If the value is true / false, set it as a boolean true / false
  242 + if ($v === 'true') {
233 243 $v = true;
234   - } elseif ($v === "false") {
  244 + } elseif ($v === 'false') {
235 245 $v = false;
236 246 }
  247 +
  248 + // Set the config arrays
237 249 $this->flat[$k] = $v;
238 250 if (!is_null($seck)) {
239 251 $this->flatns["$seck/$k"] = $v;
... ...
lib/database/dbutil.inc
... ... @@ -130,12 +130,14 @@ class DBUtil {
130 130  
131 131 function logQueryError($query, $result) {
132 132 global $default;
133   - if (!$default->queryLog->isDebugEnabled())
  133 + if (isset($default->queryLog) && !$default->queryLog->isDebugEnabled())
134 134 {
135 135 // if debug is enabled, the query is already logged.
136 136 $default->queryLog->error($query);
137 137 }
138   - $default->log->error('Query error: ' . $result->getMessage());
  138 + if(isset($default->log)){
  139 + $default->log->error('Query error: ' . $result->getMessage());
  140 + }
139 141 }
140 142  
141 143 function runQueries($aQueries, $db = null) {
... ...
lib/upgrades/UpgradeFunctions.inc.php
... ... @@ -6,31 +6,31 @@
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2008 KnowledgeTree Inc.
8 8 * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
  9 + *
10 10 * This program is free software; you can redistribute it and/or modify it under
11 11 * the terms of the GNU General Public License version 3 as published by the
12 12 * Free Software Foundation.
13   - *
  13 + *
14 14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 17 * details.
18   - *
  18 + *
19 19 * You should have received a copy of the GNU General Public License
20 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 23 * California 94120-7775, or email info@knowledgetree.com.
24   - *
  24 + *
25 25 * The interactive user interfaces in modified source and object code versions
26 26 * of this program must display Appropriate Legal Notices, as required under
27 27 * Section 5 of the GNU General Public License version 3.
28   - *
  28 + *
29 29 * In accordance with Section 7(b) of the GNU General Public License version 3,
30 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 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 34 * copyright notice.
35 35 * Contributor( s): ______________________________________
36 36 *
... ... @@ -61,6 +61,7 @@ class UpgradeFunctions {
61 61 '3.1.6.3' => array('cleanupGroupMembership'),
62 62 '3.5.0' => array('cleanupOldKTAdminVersionNotifier', 'updateConfigFile35', 'registerIndexingTasks'),
63 63 '3.5.2' => array('setStorageEngine','dropForeignKeys','dropPrimaryKeys','dropIndexes','createPrimaryKeys','createForeignKeys','createIndexes', 'removeSlashesFromObjects'),
  64 + '3.5.3' => array('moveConfigSettingsToDB')
64 65 );
65 66  
66 67 var $descriptions = array(
... ... @@ -90,7 +91,8 @@ class UpgradeFunctions {
90 91 'createPrimaryKeys'=>'Recreate db integrity:Create primary keys on the database',
91 92 'createForeignKeys'=>'Recreate db integrity:Create foreign keys on the database',
92 93 'createIndexes'=>'Recreate db integrity:Create indexes on the database',
93   - 'removeSlashesFromObjects'=>'Remove slashes from documents and folders'
  94 + 'removeSlashesFromObjects'=>'Remove slashes from documents and folders',
  95 + 'moveConfigSettingsToDB' => 'Move the configuration settings from the config.ini file into the new database table.'
94 96 );
95 97 var $phases = array(
96 98 "setPermissionFolder" => 1,
... ... @@ -109,6 +111,69 @@ class UpgradeFunctions {
109 111 'createIndexes'=>7,
110 112 );
111 113  
  114 + function moveConfigSettingsToDB()
  115 + {
  116 + require_once('Config.php');
  117 +
  118 + // Get config settings from config.ini
  119 + $oKTConfig = KTConfig::getSingleton();
  120 + $configPath = $oKTConfig->getConfigFilename();
  121 +
  122 + $c = new Config;
  123 + $root =& $c->parseConfig($configPath, "IniCommented");
  124 +
  125 + if (PEAR::isError($root)) {
  126 + return $root;
  127 + }
  128 +
  129 + $confRoot = $root->toArray();
  130 + $conf = $confRoot['root'];
  131 +
  132 + // Get the default settings from the database
  133 + $query = "SELECT id, s.group_name, s.item, s.value, s.default_value
  134 + FROM config_settings s
  135 + ORDER BY group_name, item";
  136 +
  137 + $settings = DBUtil::getResultArray($query);
  138 +
  139 + if(PEAR::isError($settings)){
  140 + return $settings;
  141 + }
  142 +
  143 + // update the settings in the database if not set to default or equal to the default value
  144 + foreach ($settings as $item){
  145 + if(!isset($conf[$item['group_name']][$item['item']])){
  146 + continue; // Don't overwrite the default with a null value
  147 + }
  148 +
  149 + $confValue = $conf[$item['group_name']][$item['item']];
  150 +
  151 + if($confValue == 'default'){
  152 + continue; // skip over if its set to default
  153 + }
  154 +
  155 + if($confValue == $item['value']){
  156 + continue; // skip over if it already has the same value
  157 + }
  158 +
  159 + if($confValue == $item['default_value']){
  160 + if($item['value'] == 'default' || $item['value'] == $item['default_value']){
  161 + continue; // skip over if it has the same value as the default value
  162 + }
  163 + // Set the value to default
  164 + $confValue = 'default';
  165 + }
  166 +
  167 + // Update the setting
  168 + $res = DBUtil::autoUpdate('config_settings', array('value' => $confValue), $item['id']);
  169 +
  170 + if(PEAR::isError($res)){
  171 + return $res;
  172 + }
  173 + }
  174 + return true;
  175 + }
  176 +
112 177 function dropForeignKeys()
113 178 {
114 179 $schemautil = KTSchemaUtil::getSingleton();
... ... @@ -1154,7 +1219,7 @@ class UpgradeFunctions {
1154 1219  
1155 1220 $ini->write();
1156 1221 }
1157   -*/
  1222 +*/
1158 1223 }
1159 1224 // }}}
1160 1225  
... ...
setup/upgrade.php
... ... @@ -151,6 +151,10 @@ function performPostUpgradeActions() {
151 151 unlink($lockFile);
152 152 }
153 153  
  154 + // Clear the configuration cache, it'll regenerate on next load
  155 + $oKTConfig = new KTConfig();
  156 + $oKTConfig->clearCache();
  157 +
154 158 // Clean out the plugin_helper table
155 159 $sql = "DELETE FROM plugin_helper";
156 160 $res = DBUtil::runQuery($sql);
... ...
sql/mysql/install/data.sql
... ... @@ -161,7 +161,8 @@ INSERT INTO `config_groups` VALUES
161 161 (21, 'ui', 'User Interface', 'General user interface configuration', 'User Interface Settings'),
162 162 (22, 'urls', 'Urls', 'KnowledgeTree server and filesystem paths (Advanced users only).', 'User Interface Settings'),
163 163 (23, 'user_prefs', 'User Preferences', 'User interface preferences', 'User Interface Settings'),
164   -(24, 'webservice', 'Web Services', 'KnowledgeTree Web Service Interface configuration. Note that a number of KnowledgeTree Tools rely on this service.', 'Client Tools Setting');
  164 +(24, 'webservice', 'Web Services', 'KnowledgeTree Web Service Interface configuration. Note that a number of KnowledgeTree Tools rely on this service.', 'Client Tools Setting'),
  165 +(25, 'ldapAuthentication', 'LDAP Authentication', 'Configuration of the ldap authentication.', 'General Settings');
165 166 /*!40000 ALTER TABLE `config_groups` ENABLE KEYS */;
166 167 UNLOCK TABLES;
167 168  
... ... @@ -278,12 +279,12 @@ INSERT INTO `config_settings` VALUES
278 279 (104, 'cache', 'Cache Enabled', 'Plugin cache configuration', 'cacheEnabled', 'default', 'false', 'boolean', NULL, 1),
279 280 (105, 'cache', 'Cache Directory', 'Plugin cache path', 'cacheDirectory', 'default', '${varDirectory}/cache', '', NULL, 1),
280 281 (106, 'cache', 'Cache Plugins', 'Plugins cache', 'cachePlugins', 'default', 'true', 'boolean', NULL, 1),
281   -(107, 'urls', 'Var Directory', 'Path to var directory', 'varDirectory', 'default', '${fileSystemRoot}/var', '', NULL, 1),
282   -(108, 'openoffice', 'Program Path', 'The Open Office program directory.', 'programPath', 'default', '../openoffice/program', 'string', NULL, 1),
283   -(109, 'urls', 'documentRoot', '', 'documentRoot', 'default', '${varDirectory}/Documents', '', NULL, 0),
284   -(110, 'KnowledgeTree', 'redirectToBrowse', 'set to true to redirect to browse screen ', 'redirectToBrowse', 'default', 'false', 'boolean', NULL, 1),
285   -(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),
286   -(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);
  282 +(107, 'openoffice', 'Program Path', 'The Open Office program directory.', 'programPath', 'default', '../openoffice/program', 'string', NULL, 1),
  283 +(108, 'urls', 'documentRoot', '', 'documentRoot', 'default', '${varDirectory}/Documents', '', NULL, 0),
  284 +(109, 'KnowledgeTree', 'redirectToBrowse', 'set to true to redirect to browse screen ', 'redirectToBrowse', 'default', 'false', 'boolean', NULL, 1),
  285 +(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),
  286 +(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),
  287 +(112, 'ldapAuthentication', 'Automatic group creation', 'Automatically create the ldap groups.', 'autoGroupCreation', 'default', 'false', 'boolean', '', 1);
287 288 /*!40000 ALTER TABLE `config_settings` ENABLE KEYS */;
288 289 UNLOCK TABLES;
289 290  
... ...
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
4 4 alter table archiving_type_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
5 5 alter table authentication_sources change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
6 6 alter table column_entries change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
7   -alter table config_settings change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
8 7 alter table dashlet_disables change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
9 8 alter table data_types change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
10 9 alter table discussion_comments change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
... ...
sql/mysql/upgrade/3.5.3/config_settings.sql
... ... @@ -40,7 +40,8 @@ INSERT INTO `config_groups` VALUES
40 40 (21, 'ui', 'User Interface', 'General user interface configuration', 'User Interface Settings'),
41 41 (22, 'urls', 'Urls', 'KnowledgeTree server and filesystem paths (Advanced users only).', 'User Interface Settings'),
42 42 (23, 'user_prefs', 'User Preferences', 'User interface preferences', 'User Interface Settings'),
43   -(24, 'webservice', 'Web Services', 'KnowledgeTree Web Service Interface configuration. Note that a number of KnowledgeTree Tools rely on this service. ', 'Client Tools Settings');
  43 +(24, 'webservice', 'Web Services', 'KnowledgeTree Web Service Interface configuration. Note that a number of KnowledgeTree Tools rely on this service. ', 'Client Tools Settings'),
  44 +(25, 'ldapAuthentication', 'LDAP Authentication', 'Configuration of the ldap authentication.', 'General Settings');
44 45  
45 46 -- --------------------------------------------------------
46 47  
... ... @@ -173,9 +174,9 @@ INSERT INTO `config_settings` VALUES
173 174 (104, 'cache', 'Cache Enabled', 'Plugin cache configuration', 'cacheEnabled', 'default', 'false', 'boolean', NULL, 1),
174 175 (105, 'cache', 'Cache Directory', 'Plugin cache path', 'cacheDirectory', 'default', '${varDirectory}/cache', '', NULL, 1),
175 176 (106, 'cache', 'Cache Plugins', 'Plugins cache', 'cachePlugins', 'default', 'true', 'boolean', NULL, 1),
176   -(107, 'urls', 'Var Directory', 'Path to var directory', 'varDirectory', 'default', '${fileSystemRoot}/var', '', NULL, 1),
177   -(108, 'openoffice', 'Program Path', 'The Open Office program directory.', 'programPath', 'default', '../openoffice/program', 'string', NULL, 1),
178   -(109, 'urls', 'documentRoot', '', 'documentRoot', 'default', '${varDirectory}/Documents', '', NULL, 0),
179   -(110, 'KnowledgeTree', 'redirectToBrowse', 'set to true to redirect to browse screen ', 'redirectToBrowse', 'default', 'false', 'boolean', NULL, 1),
180   -(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),
181   -(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);
182 177 \ No newline at end of file
  178 +(107, 'openoffice', 'Program Path', 'The Open Office program directory.', 'programPath', 'default', '../openoffice/program', 'string', NULL, 1),
  179 +(108, 'urls', 'documentRoot', '', 'documentRoot', 'default', '${varDirectory}/Documents', '', NULL, 0),
  180 +(109, 'KnowledgeTree', 'redirectToBrowse', 'set to true to redirect to browse screen ', 'redirectToBrowse', 'default', 'false', 'boolean', NULL, 1),
  181 +(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),
  182 +(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),
  183 +(112, 'ldapAuthentication', 'Automatic group creation', 'Automatically create the ldap groups.', 'autoGroupCreation', 'default', 'false', 'boolean', '', 1);
183 184 \ No newline at end of file
... ...