Index: branches/unlabeled/unlabeled-1.110.2/admin/install.php =================================================================== diff -u -r6799 -r6942 --- branches/unlabeled/unlabeled-1.110.2/admin/install.php (.../install.php) (revision 6799) +++ branches/unlabeled/unlabeled-1.110.2/admin/install.php (.../install.php) (revision 6942) @@ -1269,11 +1269,13 @@ $installed = TableExists($ado,"ConfigurationAdmin,Category,Permissions"); if(!$installed) { - // create tables + // run core install script + K4_RunSQL('/core/install/install_schema.sql'); + K4_RunSQL('/core/install/install_data.sql'); + + // run in-portal install script $filename = $pathtoroot.$admin."/install/inportal_schema.sql"; RunSchemaFile($ado,$filename); - - // insert default info $filename = $pathtoroot.$admin."/install/inportal_data.sql"; RunSQLFile($ado,$filename); Index: branches/unlabeled/unlabeled-1.5.2/admin/install/inst_ado.php =================================================================== diff -u -r4254 -r6942 --- branches/unlabeled/unlabeled-1.5.2/admin/install/inst_ado.php (.../inst_ado.php) (revision 4254) +++ branches/unlabeled/unlabeled-1.5.2/admin/install/inst_ado.php (.../inst_ado.php) (revision 6942) @@ -1,23 +1,41 @@ 0 ) + /** + * Returns reference to database connection + * + * @param bool $new_type Return Kernel4 or in-portal connection object + * @return kDBConnection + */ + function &inst_GetADODBConnection($new_type = false) { - $DB = ADONewConnection($g_DBType); - $connected = $DB->Connect($g_DBHost, $g_DBUser, $g_DBUserPassword, $g_DBName); - - $ADODB_CACHE_DIR = $pathtoroot.'cache'; - $ADODB_FETCH_MODE = 2; - $ADODB_COUNTRECS = false; - $DB->debug = false; - $DB->cacheSecs = 3600; + static $DB = null; + global $g_DBType, $g_DBHost, $g_DBUser, $g_DBUserPassword, $g_DBName, $g_DebugMode; + global $ADODB_FETCH_MODE, $ADODB_COUNTRECS, $ADODB_CACHE_DIR, $pathtoroot; + + if ($new_type) { + static $new_db = null; + + if (!isset($new_db) && $g_DBType) { + require_once FULL_PATH.'/core/kernel/db/db_connection.php'; + $new_db = new kDBConnection($g_DBType); + $new_db->Connect($g_DBHost, $g_DBUser, $g_DBUserPassword, $g_DBName); + } + + return $new_db; + } + + if( !isset($DB) && strlen($g_DBType) > 0 ) + { + $DB = ADONewConnection($g_DBType); + $connected = $DB->Connect($g_DBHost, $g_DBUser, $g_DBUserPassword, $g_DBName); + + $ADODB_CACHE_DIR = $pathtoroot.'cache'; + $ADODB_FETCH_MODE = 2; + $ADODB_COUNTRECS = false; + $DB->debug = false; + $DB->cacheSecs = 3600; + } + return $DB; } - return $DB; -} ?> Index: branches/unlabeled/unlabeled-1.45.2/admin/install/install_lib.php =================================================================== diff -u -r6443 -r6942 --- branches/unlabeled/unlabeled-1.45.2/admin/install/install_lib.php (.../install_lib.php) (revision 6443) +++ branches/unlabeled/unlabeled-1.45.2/admin/install/install_lib.php (.../install_lib.php) (revision 6942) @@ -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);