} SystemPref::Set("DBReplicationPort", $f_db_repl_port); } else { SystemPref::Set("UseDBReplication", 'N'); } // template filter SystemPref::Set("TemplateFilter", $f_template_filter); // External cron management SystemPref::Set('ExternalCronManagement', $f_external_cron_management); // geolocation foreach ($f_geo as $key => $value) { $name = ''; foreach (explode('_', $key) as $part) { $name .= ucfirst($part); } SystemPref::Set($name, $value); } $f_mysql_client_command_path = Input::Get('f_mysql_client_command_path', 'string'); SystemPref::Set('MysqlClientCommandPath', $f_mysql_client_command_path); require_once $GLOBALS['g_campsiteDir'] . '/bin/cli_script_lib.php'; global $Campsite; global $g_ado_db; if (!camp_geodata_loaded($g_ado_db) && !empty($f_mysql_client_command_path)) { camp_load_geodata($f_mysql_client_command_path, $Campsite['db']); } // Success message if everything was ok if ($msg_ok == 1) { camp_html_add_msg(getGS("System preferences updated."), "ok"); } CampPlugin::PluginAdminHooks(__FILE__); camp_html_goto_page("/{$ADMIN}/system_pref/");
/** * */ private function databaseConfiguration($p_input) { global $g_db; if (file_exists(CS_PATH_SITE . DIR_SEP . '.htaccess')) { if (!file_exists(CS_PATH_SITE . DIR_SEP . '.htaccess-default')) { @copy(CS_PATH_SITE . DIR_SEP . '.htaccess', CS_PATH_SITE . DIR_SEP . '.htaccess-default'); } @unlink(CS_PATH_SITE . DIR_SEP . '.htaccess'); } $session = CampSession::singleton(); $db_hostname = Input::Get('db_hostname', 'text'); $db_hostport = Input::Get('db_hostport', 'int'); $db_username = Input::Get('db_username', 'text'); $db_userpass = Input::Get('db_userpass', 'text'); $db_database = Input::Get('db_database', 'text'); $db_overwrite = Input::Get('db_overwrite', 'int', 0); $dbhost = $db_hostname; if (empty($db_hostport)) { $db_hostport = 3306; } if (empty($db_hostname) || empty($db_hostport) || empty($db_username) || empty($db_database)) { $this->m_step = 'database'; $this->m_message = 'Error: Please input the requested data'; return false; } $error = false; $connectionParams = array('dbname' => $db_database, 'user' => $db_username, 'password' => $db_userpass, 'host' => $db_hostname, 'port' => $db_hostport); $g_db = $this->getTestDbConnection($connectionParams); if (!$g_db->isConnected(true)) { $error = true; } else { $isDbEmpty = TRUE; $selectDb = $g_db->hasDatabase($db_database); if ($selectDb) { $g_db = $this->getDbConnection($connectionParams); $dbTables = $g_db->GetAll('SHOW TABLES'); $isDbEmpty = empty($dbTables) ? TRUE : FALSE; } if (!$isDbEmpty && !$db_overwrite) { $this->m_step = 'database'; $this->m_overwriteDb = true; $this->m_message = '<p>There is already a database named <i>' . $db_database . '</i>.</p><p>If you are sure to overwrite it, check <i>Yes</i> for the option below. If not, just change the <i>Database Name</i> and continue.</p>'; $this->m_config['database'] = array('hostname' => $db_hostname, 'hostport' => $db_hostport, 'username' => $db_username, 'userpass' => $db_userpass, 'database' => $db_database); $session->unsetData('config.db', 'installation'); $session->setData('config.db', $this->m_config['database'], 'installation', true); return false; } } if (!$error && !$selectDb) { try { $g_db->createDatabase($db_database); $g_db = $this->getDbConnection($connectionParams); } catch (\Exception $e) { $error = true; } } if ($error == true) { $this->m_step = 'database'; $this->m_message = 'Error: Database parameters invalid. Could not ' . 'connect to database server.'; return false; } $sqlFile = CS_INSTALL_DIR . DIR_SEP . 'sql' . DIR_SEP . 'campsite_core.sql'; $errors = CampInstallationBaseHelper::ImportDB($sqlFile, $errorQueries); if ($errors > 0) { $this->m_step = 'database'; $this->m_message = 'Error: Importing Database'; foreach ($errorQueries as $query) { $this->m_message .= "<br>{$query}"; } return false; } // load geonames set_time_limit(0); foreach (array('CityNames', 'CityLocations') as $table) { $conn_specs = 'mysql:host=' . $db_hostname . ';'; if (!empty($db_hostport)) { $conn_specs .= 'port=' . $db_hostport . ';'; } $conn_specs .= 'dbname=' . $db_database . ''; $l_db = new PDO($conn_specs, $db_username, $db_userpass, array(PDO::MYSQL_ATTR_LOCAL_INFILE => 1, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); $l_db->exec("TRUNCATE `{$table}`"); $l_db->exec("ALTER TABLE `{$table}` DISABLE KEYS"); $csvFile = CS_INSTALL_DIR . DIR_SEP . 'sql' . DIR_SEP . "{$table}.csv"; $csvFile = str_replace("\\", "\\\\", $csvFile); $l_db->exec("LOAD DATA LOCAL INFILE '{$csvFile}' INTO TABLE {$table} FIELDS TERMINATED BY ';' ENCLOSED BY '\"'"); $l_db->exec("ALTER TABLE `{$table}` ENABLE KEYS"); } require_once $GLOBALS['g_campsiteDir'] . '/bin/cli_script_lib.php'; if (!camp_geodata_loaded($g_db)) { $which_output = ''; $which_ret = ''; @exec('which mysql', $which_output, $which_ret); if (is_array($which_output) && isset($which_output[0])) { $mysql_client_command = $which_output[0]; if (0 < strlen($mysql_client_command)) { $db_conf = array('host' => $db_hostname, 'port' => $db_hostport, 'user' => $db_username, 'pass' => $db_userpass, 'name' => $db_database); camp_load_geodata($mysql_client_command, $db_conf); } } } // installing the stored function for 'point in polygon' checking $sqlFile = CS_INSTALL_DIR . DIR_SEP . 'sql' . DIR_SEP . "checkpp.sql"; importSqlStoredProgram($g_db, $sqlFile); $this->m_config['database'] = array('hostname' => $db_hostname, 'hostport' => $db_hostport, 'username' => $db_username, 'userpass' => $db_userpass, 'database' => $db_database); require_once $GLOBALS['g_campsiteDir'] . '/bin/cli_script_lib.php'; camp_remove_dir(CS_PATH_TEMPLATES . DIR_SEP . '*', null, array('system_templates', 'unassigned')); $db_versions = array_map('basename', glob($GLOBALS['g_campsiteDir'] . '/install/sql/upgrade/[2-9].[0-9]*')); if (!empty($db_versions)) { usort($db_versions, 'camp_version_compare'); $db_last_version = array_pop($db_versions); $db_last_version_dir = $GLOBALS['g_campsiteDir'] . "/install/sql/upgrade/{$db_last_version}/"; $db_last_roll = ''; $db_rolls = camp_search_db_rolls($db_last_version_dir, ''); if (!empty($db_rolls)) { $db_last_roll_info = array_slice($db_rolls, -1, 1, true); $db_last_roll_info_keys = array_keys($db_last_roll_info); $db_last_roll = $db_last_roll_info_keys[0]; } camp_save_database_version($g_db, $db_last_version, $db_last_roll); } return true; }