Index: trunk/admin/install/install_lib.php =================================================================== diff -u -N -r6428 -r7391 --- trunk/admin/install/install_lib.php (.../install_lib.php) (revision 6428) +++ trunk/admin/install/install_lib.php (.../install_lib.php) (revision 7391) @@ -293,6 +293,53 @@ } } +/** + * Executes all sqls in selected file (in K4 style) + * + * @param string $filename + * @param kDBConnection $db + * @param mixed $replace_from + * @param mixed $replace_to + */ +function K4_RunSQL($filename, $replace_from = null, $replace_to = null) +{ + if (!file_exists(FULL_PATH.$filename)) { + return ; + } + + $db =& inst_GetADODBConnection(true); + $sqls = file_get_contents(FULL_PATH.$filename); + + // add prefix to all tables + if (strlen(TABLE_PREFIX) > 0) { + $replacements = Array ('CREATE TABLE ', 'INSERT INTO ', 'UPDATE ', 'ALTER TABLE '); + foreach ($replacements as $replacement) { + $sqls = str_replace($replacement, $replacement.TABLE_PREFIX, $sqls); + } + $sqls = str_replace('DROP TABLE ', 'DROP TABLE IF EXISTS '.TABLE_PREFIX, $sqls); + } + + if (isset($replace_from) && isset($replace_to)) { + // replace something additionally, e.g. module root category + $sqls = str_replace($replace_from, $replace_to, $sqls); + } + + $sqls = explode(";\n", $sqls); + + foreach ($sqls as $sql) { + $sql = trim($sql); + if (!$sql || substr($sql, 0, 1) == '#') { + continue; // usually last line || comment + } + $db->Query($sql); + if ($db->getErrorCode() != 0) { + $db_error = $db->getErrorMsg()." COMMAND:
$sql
"; + $error = true; +// break; + } + } +} + function RunRestoreFile($ado,$filename,$FileOffset,$MaxLines) { $size = filesize($filename); @@ -924,8 +971,8 @@ $lang_path = FULL_PATH.'/'.$module_name.'/admin/install/langpacks'; $lang_xml->Parse($lang_path.'/english.lang', '|0|1|2|', ''); - - $app->Redirect('modules/modules_list', Array('pass' => 'all', 'admin' => 1, 'RefreshTree' => 1), '', 'index.php'); + + $app->Redirect('in-portal/modules/modules_list', Array('pass' => 'all', 'admin' => 1, 'RefreshTree' => 1), '', 'index.php'); } /**