$versions = array_keys($database_update_info); for ($i = 0; $i < sizeof($versions); $i++) { $version = $versions[$i]; $schema_changes = $database_update_info[$version]; $next_version = isset($versions[$i + 1]) ? $versions[$i + 1] : $updates_to_version; // If the installed version to be updated to is < than the current version, and if the current version is >= as the version to be updated to next, we will skip the process if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>=')) { continue; } if (!sizeof($schema_changes)) { continue; } $no_updates = false; // We run one index after the other... to be consistent with schema changes... foreach ($schema_changes as $key => $changes) { $statements = $db_tools->perform_schema_changes(array($key => $changes)); foreach ($statements as $sql) { _sql($sql, $errored, $error_ary); } } } _write_result($no_updates, $errored, $error_ary); // Data updates $error_ary = array(); $errored = $no_updates = false; ?> <br /><br /> <h1><?php echo $lang['UPDATING_DATA']; ?>
$no_updates = true; $versions = array_keys($database_update_info); for ($i = 0; $i < sizeof($versions); $i++) { $version = $versions[$i]; $schema_changes = $database_update_info[$version]; $next_version = isset($versions[$i + 1]) ? $versions[$i + 1] : $updates_to_version; // If the installed version to be updated to is < than the current version, and if the current version is >= as the version to be updated to next, we will skip the process // if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>=')) { continue; } if (!sizeof($schema_changes)) { continue; } $no_updates = false; $mod_db->perform_schema_changes($schema_changes); } _write_result($no_updates, $errored, $error_ary); // Data updates $error_ary = array(); $errored = $no_updates = false; ?> <br /><br /> <h1><?php echo $lang['UPDATING_DATA']; ?> </h1> <br /> <p><?php echo $lang['PROGRESS'];
/** * Add password salt field to the users table. */ function mybb_add_user_salt_field() { global $db, $phpbb_root_path, $phpEx; if (!class_exists('phpbb_db_tools')) { include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); } $schema_changes = array( 'add_columns' => array( USERS_TABLE => array( 'user_passwd_salt' => array('VCHAR:10', ''), ) ) ); $db_tools = new phpbb_db_tools($db); $db_tools->perform_schema_changes($schema_changes); }
/** * Load the contents of the schema into the database and then alter it based on what has been input during the installation */ function load_schema($mode, $sub) { global $db, $lang, $template, $phpbb_root_path, $phpEx, $dbms, $table_prefix; $this->page_title = $lang['STAGE_CREATE_TABLE']; $s_hidden_fields = ''; // Obtain any submitted data $data = $this->get_submitted_data(); //We will just setup $db here rather than try work it in earlier - might need to rethink this though for languages require $phpbb_root_path . 'includes/functions_convert.' . $phpEx; $available_dbms = get_available_dbms($dbms); // If mysql is chosen, we need to adjust the schema filename slightly to reflect the correct version. ;) if ($dbms == 'mysql') { if (version_compare($db->mysql_version, '4.1.3', '>=')) { $available_dbms[$dbms]['SCHEMA'] .= '_41'; } else { $available_dbms[$dbms]['SCHEMA'] .= '_40'; } } // Ok we have the db info go ahead and read in the relevant schema // and work on building the table $create_schema = 'schemas/' . $available_dbms[$dbms]['SCHEMA'] . '_schema.sql'; // How should we treat this schema? $remove_remarks = $available_dbms[$dbms]['COMMENTS']; $delimiter = $available_dbms[$dbms]['DELIM']; $create_query = file_get_contents($create_schema); $create_query = preg_replace('#phpbb_#i', $table_prefix, $create_query); $remove_remarks($create_query); $create_query = split_sql_file($create_query, $delimiter); foreach ($create_query as $sql) { //$sql = trim(str_replace('|', ';', $sql)); if (!$db->sql_query($sql)) { $error = $db->sql_error(); $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__); } } unset($create_query); // Ok tables have been built, let's fill in the basic information & prepare optional data too $sql_query = file_get_contents('schemas/schema_data.sql'); $make_query = file_get_contents('schemas/schema_make_data.sql'); $category_query = file_get_contents('schemas/schema_category_data.sql'); // Deal with any special comments switch ($dbms) { case 'mssql': case 'mssql_odbc': $sql_query = preg_replace('#\\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \\##s', 'SET IDENTITY_INSERT \\1 \\2;', $sql_query); $make_query = preg_replace('#\\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \\##s', 'SET IDENTITY_INSERT \\1 \\2;', $make_query); $category_query = preg_replace('#\\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \\##s', 'SET IDENTITY_INSERT \\1 \\2;', $category_query); break; case 'postgres': $sql_query = preg_replace('#\\# POSTGRES (BEGIN|COMMIT) \\##s', '\\1; ', $sql_query); $make_query = preg_replace('#\\# POSTGRES (BEGIN|COMMIT) \\##s', '\\1; ', $make_query); $category_query = preg_replace('#\\# POSTGRES (BEGIN|COMMIT) \\##s', '\\1; ', $category_query); break; } // Change prefix $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query); $make_query = preg_replace('#phpbb_#i', $table_prefix, $make_query); $category_query = preg_replace('#phpbb_#i', $table_prefix, $category_query); // Since we know the comment style and are able to remove it directly with remove_remarks remove_remarks($sql_query); remove_remarks($make_query); remove_remarks($category_query); $sql_query = split_sql_file($sql_query, ';'); $make_query = split_sql_file($make_query, ';'); $category_query = split_sql_file($category_query, ';'); foreach ($sql_query as $sql) { if (!$db->sql_query($sql)) { $error = $db->sql_error(); $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__); } } unset($sql_query); // Does the user want default makes if ($data['insert_makes']) { foreach ($make_query as $sql) { //$sql = trim(str_replace('|', ';', $sql)); if (!$db->sql_query($sql)) { $error = $db->sql_error(); $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__); } } unset($make_query); } // Does the user want default categories if ($data['insert_categories']) { foreach ($category_query as $sql) { //$sql = trim(str_replace('|', ';', $sql)); if (!$db->sql_query($sql)) { $error = $db->sql_error(); $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__); } } unset($category_query); } $schema_changes = array('add_columns' => array(USERS_TABLE => array('user_garage_index_columns' => array('BOOL', 2), 'user_garage_guestbook_email_notify' => array('BOOL', 1), 'user_garage_guestbook_pm_notify' => array('BOOL', 1), 'user_garage_mod_email_optout' => array('BOOL', 0), 'user_garage_mod_pm_optout' => array('BOOL', 0)))); require $phpbb_root_path . 'includes/db/db_tools.' . $phpEx; $mod_db = new phpbb_db_tools($db); $mod_db->perform_schema_changes($schema_changes); $submit = $lang['NEXT_STEP']; $url = $this->p_master->module_url . "?mode={$mode}&sub=create_permissions"; $template->assign_vars(array('BODY' => $lang['STAGE_CREATE_TABLE_EXPLAIN'], 'L_SUBMIT' => $submit, 'S_HIDDEN' => build_hidden_fields($data), 'U_ACTION' => $url)); }
function main($id, $mode) { global $db, $user, $template; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; $this->tpl_name = 'acp_syndication'; $this->page_title = 'SYNDICATION_TITLE'; $submit = isset($_POST['submit']) ? true : false; $form_key = 'acp_syndication'; add_form_key($form_key); $display_vars = array('title' => 'SYNDICATION_TITLE', 'vars' => array('legend' => 'SYNDICATION_LEGEND', 'enable_syndication' => array('lang' => 'ENABLE_SYNDICATION', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'syndication_default' => array('lang' => 'SYNDICATION_DEFAULT', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_syndication_default', 'explain' => true), 'syndication_items' => array('lang' => 'SYNDICATION_ITEMS', 'validate' => 'int', 'type' => 'text:2:2', 'explain' => false), 'syndication_ttl' => array('lang' => 'SYNDICATION_TTL', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true, 'append' => ' ' . $user->lang['SECONDS']))); $this->new_config = $config; $cfg_array = isset($_REQUEST['config']) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config; $error = array(); // We validate the complete config if whished validate_config_vars($display_vars['vars'], $cfg_array, $error); if ($submit && !check_form_key($form_key)) { $error[] = $user->lang['FORM_INVALID']; } // Do not write values if there is an error if (sizeof($error)) { $submit = false; } // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... foreach ($display_vars['vars'] as $config_name => $null) { if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) { continue; } if ($config_name == 'auth_method') { continue; } $this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; if ($submit) { set_config($config_name, $config_value); // we update the database structure to reflect this change for new users and the guest account. Also check for valid value if ($config_name == 'syndication_default' && ($config_value == SYNDICATION_ATOM || $config_value == SYNDICATION_RSS2)) { include $phpbb_root_path . 'includes/db/db_tools.' . $phpEx; $db_tools = new phpbb_db_tools($db); $db_tools->perform_schema_changes(array('change_columns' => array(USERS_TABLE => array('user_syndication_method' => array('BOOL', $config_value))))); $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\tSET user_syndication_method = {$config_value}\n\t\t\t\t\t\tWHERE user_id = " . ANONYMOUS; $db->sql_query($sql); } } } if ($submit) { add_log('admin', 'LOG_CONFIG_SYNDICATION'); trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); } $template->assign_vars(array('L_TITLE' => $user->lang[$display_vars['title']], 'L_TITLE_EXPLAIN' => $user->lang[$display_vars['title'] . '_EXPLAIN'], 'S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => implode('<br />', $error), 'S_SYNDICATION_DEFAULT' => $config['syndication_default'], 'U_ACTION' => $this->u_action)); // Output relevant page foreach ($display_vars['vars'] as $config_key => $vars) { if (!is_array($vars) && strpos($config_key, 'legend') === false) { continue; } if (strpos($config_key, 'legend') !== false) { $template->assign_block_vars('options', array('S_LEGEND' => true, 'LEGEND' => isset($user->lang[$vars]) ? $user->lang[$vars] : $vars)); continue; } $type = explode(':', $vars['type']); $l_explain = ''; if ($vars['explain'] && isset($vars['lang_explain'])) { $l_explain = isset($user->lang[$vars['lang_explain']]) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain']; } else { if ($vars['explain']) { $l_explain = isset($user->lang[$vars['lang'] . '_EXPLAIN']) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : ''; } } $template->assign_block_vars('options', array('KEY' => $config_key, 'TITLE' => isset($user->lang[$vars['lang']]) ? $user->lang[$vars['lang']] : $vars['lang'], 'S_EXPLAIN' => $vars['explain'], 'TITLE_EXPLAIN' => $l_explain, 'CONTENT' => build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars))); unset($display_vars['vars'][$config_key]); } }