Index: branches/unlabeled/unlabeled-1.110.2/admin/install.php =================================================================== diff -u -r6988 -r7529 --- branches/unlabeled/unlabeled-1.110.2/admin/install.php (.../install.php) (revision 6988) +++ branches/unlabeled/unlabeled-1.110.2/admin/install.php (.../install.php) (revision 7529) @@ -1216,7 +1216,8 @@ // run core install script K4_RunSQL('/core/install/install_schema.sql'); K4_RunSQL('/core/install/install_data.sql'); - + K4_SetModuleVersion('Core'); + // run in-portal install script $filename = $pathtoroot.$admin."/install/inportal_schema.sql"; RunSchemaFile($ado,$filename); Index: branches/unlabeled/unlabeled-1.45.2/admin/install/install_lib.php =================================================================== diff -u -r6999 -r7529 --- branches/unlabeled/unlabeled-1.45.2/admin/install/install_lib.php (.../install_lib.php) (revision 6999) +++ branches/unlabeled/unlabeled-1.45.2/admin/install/install_lib.php (.../install_lib.php) (revision 7529) @@ -324,12 +324,14 @@ $sqls = str_replace($replace_from, $replace_to, $sqls); } + $sqls = str_replace("\r\n", "\n", $sqls); // convert to linux line endings + $sqls = preg_replace("/#(.*?)\n/", '', $sqls); // remove all comments $sqls = explode(";\n", $sqls); foreach ($sqls as $sql) { $sql = trim($sql); - if (!$sql || substr($sql, 0, 1) == '#') { - continue; // usually last line || comment + if (!$sql) { + continue; // usually last line } $db->Query($sql); if ($db->getErrorCode() != 0) { @@ -339,6 +341,47 @@ } } } + +/** + * Sets module version to passed + * + * @param string $module_name + * @param string $version + */ +function K4_SetModuleVersion($module_name, $version = false) +{ + if ($version === false) { + $version = K4_GetMaxModuleVersion($module_name); + } + + $sql = 'UPDATE '.TABLE_PREFIX.'Modules + SET Version = "'.$version.'" + WHERE Name = "'.$module_name.'"'; + + $db =& inst_GetADODBConnection(true); + $db->Query($sql); +} + +function K4_GetMaxModuleVersion($module_name) +{ + define('UPGRADES_FILE', FULL_PATH.'/%sinstall/upgrades.sql'); + define('VERSION_MARK', '# ===== v ([\d]+\.[\d]+\.[\d]+) ====='); + + $upgrades_file = sprintf(UPGRADES_FILE, strtolower($module_name).'/'); + if (!file_exists($upgrades_file)) { + // no upgrade file + return '4.0.1'; + } + + $sqls = file_get_contents($upgrades_file); + $versions_found = preg_match_all('/'.VERSION_MARK.'/s', $sqls, $regs); + if (!$versions_found) { + // upgrades file doesn't contain version definitions + return '4.0.1'; + } + + return end($regs[1]); +} function RunRestoreFile($ado,$filename,$FileOffset,$MaxLines) {