function upgrade_database_conf() { // // Create new keywords (if necessary) // This must be done at the end, in case keyword DB structure changed // include_lcm('inc_meta'); include_lcm('inc_keywords_default'); $all_default_kwgs = get_default_keywords(); create_groups($all_default_kwgs); // // Create new meta (if necessary) // This must be done at the end, in case meta DB structure changed // include_lcm('inc_meta_defaults'); init_default_config(); // Rewrite metas in inc/data/inc_meta_cache.php, just to be sure write_metas(); // // Update lcm_fields // include_lcm('inc_repfields_defaults'); $fields = get_default_repfields(); create_repfields($fields); }
function install_step_3() { $db_address = _request('db_address'); $db_login = _request('db_login'); $db_password = _request('db_password'); global $lcm_db_version; $install_log = ""; $upgrade_log = ""; // Possible errors will get trapped in the output buffer and displayed later, // so that they don't mess up with headers/html. ob_start(); if (_request('db_choice') == "__manual__") { $sel_db = _request('manual_db'); } else { $sel_db = _request('db_choice'); } $link = lcm_connect_db($db_address, 0, $db_login, $db_password, $sel_db); $io_output = ob_get_contents(); ob_end_clean(); if (!$link) { install_html_start('AUTO', '', 3); lcm_panic("connection denied: " . lcm_sql_error()); } // // TEMPORARY (used by testing the installer) /* lcm_query("DROP TABLE lcm_case", true); lcm_query("DROP TABLE lcm_case_attachment", true); lcm_query("DROP TABLE lcm_stage", true); lcm_query("DROP TABLE lcm_followup", true); lcm_query("DROP TABLE lcm_author", true); lcm_query("DROP TABLE lcm_client", true); lcm_query("DROP TABLE lcm_client_attachment", true); lcm_query("DROP TABLE lcm_org", true); lcm_query("DROP TABLE lcm_org_attachment", true); lcm_query("DROP TABLE lcm_contact", true); lcm_query("DROP TABLE lcm_keyword", true); lcm_query("DROP TABLE lcm_keyword_case", true); lcm_query("DROP TABLE lcm_keyword_client", true); lcm_query("DROP TABLE lcm_keyword_org", true); lcm_query("DROP TABLE lcm_keyword_group", true); lcm_query("DROP TABLE lcm_report", true); lcm_query("DROP TABLE lcm_fields", true); lcm_query("DROP TABLE lcm_filter", true); lcm_query("DROP TABLE lcm_app", true); lcm_query("DROP TABLE lcm_app_client_org", true); lcm_query("DROP TABLE lcm_app_fu", true); lcm_query("DROP TABLE lcm_author_app", true); lcm_query("DROP TABLE lcm_case_client_org", true); lcm_query("DROP TABLE lcm_case_author", true); lcm_query("DROP TABLE lcm_client_org", true); lcm_query("DROP TABLE lcm_rep_col", true); lcm_query("DROP TABLE lcm_rep_line", true); lcm_query("DROP TABLE lcm_rep_filters", true); lcm_query("DROP TABLE lcm_filter_conds", true); lcm_query("DROP TABLE lcm_rep_filter", true); lcm_query("DROP TABLE lcm_meta", true); */ // Test if the software was already installed $result = lcm_query("SELECT * FROM lcm_meta", true); $already_installed = !lcm_sql_errno() && lcm_num_rows($result); $old_lcm_version = 'NONE'; if ($already_installed) { lcm_log("LCM already installed", 'install'); // Find the current database version $old_lcm_db_version = 0; $query = "SELECT value FROM lcm_meta WHERE name = 'lcm_db_version'"; $result = lcm_query_db($query); while ($row = lcm_fetch_array($result)) { $old_lcm_db_version = $row['value']; } lcm_log("LCM version installed is {$old_lcm_db_version}", 'install'); // Check if upgrade is needed if ($old_lcm_db_version < $lcm_db_version) { lcm_log("Calling the upgrade procedure (since < {$lcm_db_version})", 'install'); include_lcm('inc_db_upgrade'); $upgrade_log = upgrade_database($old_lcm_db_version); } else { lcm_log("Upgrade _not_ called, looks OK (= {$lcm_db_version})", 'install'); } } else { lcm_log("Creating the database from scratch", 'install'); include_lcm('inc_db_create'); $install_log .= create_database(); lcm_log("DB creation complete", 'install'); } // Create default meta + keywords include_lcm('inc_meta'); include_lcm('inc_keywords_default'); include_lcm('inc_meta_defaults'); init_default_config(); init_languages(); $skwg = get_default_keywords(); create_groups($skwg); write_metas(); // regenerate inc/data/inc_meta_cache.php // Test DB: not used for now.. include_lcm('inc_db_test'); $structure_ok = lcm_structure_test(); if (!empty($install_log)) { install_html_start('AUTO', '', 3); echo "<h3><small>" . _T('install_step_three') . "</small> " . _T('install_title_creating_database') . "</h3>\n"; echo "<div class='box_error'>\n"; echo "<p>"; echo "<b>" . _T('warning_operation_failed') . "</b> " . _T('install_database_install_failed'); echo " " . lcm_help("install_connection") . "</p>\n"; echo "</div>\n"; // Dump error listing echo put_text_in_textbox($install_log); install_html_end(); } else { if (!empty($upgrade_log)) { install_html_start('AUTO', '', 3); echo "<h3><small>" . _T('install_step_three') . "</small> " . _T('install_title_creating_database') . "</h3>\n"; echo "<div class='box_error'>\n"; echo "<p>" . _T('install_warning_update_impossible', array('old_version' => $old_lcm_version, 'version' => $lcm_version)) . "</p>\n"; echo "</div>\n"; // Dump error listing echo put_text_in_textbox($upgrade_log); install_html_end(); } else { if (!$structure_ok) { install_html_start('AUTO', '', 3); echo "<h3><small>" . _T('install_step_three') . "</small> " . _T('install_title_creating_database') . "</h3>\n"; echo "<div class='box_error'>\n"; echo "<p> STRUCTURE PROBLEM </p>\n"; // TRAD echo "</div>\n"; install_html_end(); } else { // Everything OK $conn = '<' . '?php' . "\n"; $conn .= "if (defined('_CONFIG_INC_CONNECT')) return;\n"; $conn .= "define('_CONFIG_INC_CONNECT', '1');\n"; $conn .= "\$GLOBALS['lcm_connect_version'] = 0.1;\n"; $conn .= "include_lcm('inc_db');\n"; $conn .= "@lcm_connect_db('{$db_address}','','{$db_login}','{$db_password}','{$sel_db}');\n"; $conn .= "\$GLOBALS['db_ok'] = !!@lcm_num_rows(@lcm_query_db('SELECT COUNT(*) FROM lcm_meta'));\n"; $conn .= '?' . '>'; $lcm_config_prefix = isset($_SERVER['LcmConfigDir']) ? $_SERVER['LcmConfigDir'] : 'inc/config'; $myFile = fopen($lcm_config_prefix . '/inc_connect_install.php', 'wb'); fputs($myFile, $conn); fclose($myFile); install_step_4(); } } } }