/** * {@inheritdoc} */ public function run() { $this->db->sql_return_on_error(true); $languages = $this->language_helper->get_available_languages(); $installed_languages = array(); foreach ($languages as $lang_info) { $lang_pack = array('lang_iso' => $lang_info['iso'], 'lang_dir' => $lang_info['iso'], 'lang_english_name' => htmlspecialchars($lang_info['name']), 'lang_local_name' => htmlspecialchars($lang_info['local_name'], ENT_COMPAT, 'UTF-8'), 'lang_author' => htmlspecialchars($lang_info['author'], ENT_COMPAT, 'UTF-8')); $this->db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $this->db->sql_build_array('INSERT', $lang_pack)); $installed_languages[] = (int) $this->db->sql_nextid(); if ($this->db->get_sql_error_triggered()) { $error = $this->db->sql_error($this->db->get_sql_error_sql()); $this->iohandler->add_error_message($error['message']); } } $sql = 'SELECT * FROM ' . PROFILE_FIELDS_TABLE; $result = $this->db->sql_query($sql); $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, PROFILE_LANG_TABLE); while ($row = $this->db->sql_fetchrow($result)) { foreach ($installed_languages as $lang_id) { $insert_buffer->insert(array('field_id' => $row['field_id'], 'lang_id' => $lang_id, 'lang_name' => strtoupper(substr($row['field_name'], 6)), 'lang_explain' => '', 'lang_default_value' => '')); } } $this->db->sql_freeresult($result); $insert_buffer->flush(); }
/** * Loads all migrations and their application state from the database. * * @return null */ public function load_migration_state() { $this->migration_state = array(); // prevent errors in case the table does not exist yet $this->db->sql_return_on_error(true); $sql = "SELECT * FROM " . $this->migrations_table; $result = $this->db->sql_query($sql); if (!$this->db->get_sql_error_triggered()) { while ($migration = $this->db->sql_fetchrow($result)) { $this->migration_state[$migration['migration_name']] = $migration; $this->migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']); } } $this->db->sql_freeresult($result); $this->db->sql_return_on_error(false); }
/** * Wrapper for running queries to generate user feedback on updates * * @param string $sql SQL query to run on the database * @return mixed Query result from db->sql_query() */ protected function sql_query($sql) { $this->queries[] = $sql; $this->db->sql_return_on_error(true); if ($sql === 'begin') { $result = $this->db->sql_transaction('begin'); } else { if ($sql === 'commit') { $result = $this->db->sql_transaction('commit'); } else { $result = $this->db->sql_query($sql); if ($this->db->get_sql_error_triggered()) { $this->errors[] = array('sql' => $this->db->get_sql_error_sql(), 'code' => $this->db->get_sql_error_returned()); } } } $this->db->sql_return_on_error(false); return $result; }
/** * Add extra modules * * @param string $module_class */ protected function add_module_extras($module_class) { foreach ($this->module_extras[$module_class] as $cat_name => $mods) { $sql = 'SELECT module_id, left_id, right_id FROM ' . MODULES_TABLE . "\n\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($cat_name) . "'\n\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($module_class) . "'"; $result = $this->db->sql_query_limit($sql, 1); $row2 = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); foreach ($mods as $mod_name) { $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($mod_name) . "'\n\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($module_class) . "'\n\t\t\t\t\t\tAND module_basename <> ''"; $result = $this->db->sql_query_limit($sql, 1); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $module_data = array('module_basename' => $row['module_basename'], 'module_enabled' => (int) $row['module_enabled'], 'module_display' => (int) $row['module_display'], 'parent_id' => (int) $row2['module_id'], 'module_class' => $row['module_class'], 'module_langname' => $row['module_langname'], 'module_mode' => $row['module_mode'], 'module_auth' => $row['module_auth']); $this->module_manager->update_module_data($module_data); // Check for last sql error happened if ($this->db->get_sql_error_triggered()) { $error = $this->db->sql_error($this->db->get_sql_error_sql()); $this->iohandler->add_error_message('INST_ERR_DB', $error['message']); } } } }
/** * {@inheritdoc} */ public function run() { $this->db->sql_return_on_error(true); $module_classes = array('acp', 'mcp', 'ucp'); foreach ($module_classes as $module_class) { $categories = array(); foreach ($this->module_categories[$module_class] as $cat_name => $subs) { // Check if this sub-category has a basename. If it has, use it. $basename = isset($this->module_categories_basenames[$cat_name]) ? $this->module_categories_basenames[$cat_name] : ''; $module_data = array('module_basename' => $basename, 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => 0, 'module_class' => $module_class, 'module_langname' => $cat_name, 'module_mode' => '', 'module_auth' => ''); $this->module_manager->update_module_data($module_data); // Check for last sql error happened if ($this->db->get_sql_error_triggered()) { $error = $this->db->sql_error($this->db->get_sql_error_sql()); $this->iohandler->add_error_message('INST_ERR_DB', $error['message']); } $categories[$cat_name]['id'] = (int) $module_data['module_id']; $categories[$cat_name]['parent_id'] = 0; if (is_array($subs)) { foreach ($subs as $level2_name) { // Check if this sub-category has a basename. If it has, use it. $basename = isset($this->module_categories_basenames[$level2_name]) ? $this->module_categories_basenames[$level2_name] : ''; $module_data = array('module_basename' => $basename, 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => (int) $categories[$cat_name]['id'], 'module_class' => $module_class, 'module_langname' => $level2_name, 'module_mode' => '', 'module_auth' => ''); $this->module_manager->update_module_data($module_data); // Check for last sql error happened if ($this->db->get_sql_error_triggered()) { $error = $this->db->sql_error($this->db->get_sql_error_sql()); $this->iohandler->add_error_message('INST_ERR_DB', $error['message']); } $categories[$level2_name]['id'] = (int) $module_data['module_id']; $categories[$level2_name]['parent_id'] = (int) $categories[$cat_name]['id']; } } } // Get the modules we want to add... returned sorted by name $module_info = $this->module_manager->get_module_infos($module_class); foreach ($module_info as $module_basename => $fileinfo) { foreach ($fileinfo['modes'] as $module_mode => $row) { foreach ($row['cat'] as $cat_name) { if (!isset($categories[$cat_name])) { continue; } $module_data = array('module_basename' => $module_basename, 'module_enabled' => 1, 'module_display' => isset($row['display']) ? (int) $row['display'] : 1, 'parent_id' => (int) $categories[$cat_name]['id'], 'module_class' => $module_class, 'module_langname' => $row['title'], 'module_mode' => $module_mode, 'module_auth' => $row['auth']); $this->module_manager->update_module_data($module_data); // Check for last sql error happened if ($this->db->get_sql_error_triggered()) { $error = $this->db->sql_error($this->db->get_sql_error_sql()); $this->iohandler->add_error_message('INST_ERR_DB', $error['message']); } } } } // Move some of the modules around since the code above will put them in the wrong place if ($module_class === 'acp') { // Move main module 4 up... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'acp_main'\n\t\t\t\t\t\tAND module_class = 'acp'\n\t\t\t\t\t\tAND module_mode = 'main'"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $this->module_manager->move_module_by($row, 'acp', 'move_up', 4); // Move permissions intro screen module 4 up... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'acp_permissions'\n\t\t\t\t\t\tAND module_class = 'acp'\n\t\t\t\t\t\tAND module_mode = 'intro'"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $this->module_manager->move_module_by($row, 'acp', 'move_up', 4); // Move manage users screen module 5 up... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'acp_users'\n\t\t\t\t\t\tAND module_class = 'acp'\n\t\t\t\t\t\tAND module_mode = 'overview'"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $this->module_manager->move_module_by($row, 'acp', 'move_up', 5); // Move extension management module 1 up... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_langname = 'ACP_EXTENSION_MANAGEMENT'\n\t\t\t\t\t\tAND module_class = 'acp'\n\t\t\t\t\t\tAND module_mode = ''\n\t\t\t\t\t\tAND module_basename = ''"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $this->module_manager->move_module_by($row, 'acp', 'move_up', 1); } if ($module_class == 'mcp') { // Move pm report details module 3 down... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'mcp_pm_reports'\n\t\t\t\t\t\tAND module_class = 'mcp'\n\t\t\t\t\t\tAND module_mode = 'pm_report_details'"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $this->module_manager->move_module_by($row, 'mcp', 'move_down', 3); // Move closed pm reports module 3 down... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'mcp_pm_reports'\n\t\t\t\t\t\tAND module_class = 'mcp'\n\t\t\t\t\t\tAND module_mode = 'pm_reports_closed'"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $this->module_manager->move_module_by($row, 'mcp', 'move_down', 3); // Move open pm reports module 3 down... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'mcp_pm_reports'\n\t\t\t\t\t\tAND module_class = 'mcp'\n\t\t\t\t\t\tAND module_mode = 'pm_reports'"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $this->module_manager->move_module_by($row, 'mcp', 'move_down', 3); } if ($module_class == 'ucp') { // Move attachment module 4 down... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'ucp_attachments'\n\t\t\t\t\t\tAND module_class = 'ucp'\n\t\t\t\t\t\tAND module_mode = 'attachments'"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $this->module_manager->move_module_by($row, 'ucp', 'move_down', 4); // Move notification options module 4 down... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'ucp_notifications'\n\t\t\t\t\t\tAND module_class = 'ucp'\n\t\t\t\t\t\tAND module_mode = 'notification_options'"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $this->module_manager->move_module_by($row, 'ucp', 'move_down', 4); // Move OAuth module 5 down... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'ucp_auth_link'\n\t\t\t\t\t\tAND module_class = 'ucp'\n\t\t\t\t\t\tAND module_mode = 'auth_link'"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $this->module_manager->move_module_by($row, 'ucp', 'move_down', 5); } // And now for the special ones // (these are modules which appear in multiple categories and thus get added manually // to some for more control) if (isset($this->module_extras[$module_class])) { foreach ($this->module_extras[$module_class] as $cat_name => $mods) { $sql = 'SELECT module_id, left_id, right_id FROM ' . MODULES_TABLE . "\n\t\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($cat_name) . "'\n\t\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($module_class) . "'"; $result = $this->db->sql_query_limit($sql, 1); $row2 = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); foreach ($mods as $mod_name) { $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($mod_name) . "'\n\t\t\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($module_class) . "'\n\t\t\t\t\t\t\t\tAND module_basename <> ''"; $result = $this->db->sql_query_limit($sql, 1); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $module_data = array('module_basename' => $row['module_basename'], 'module_enabled' => (int) $row['module_enabled'], 'module_display' => (int) $row['module_display'], 'parent_id' => (int) $row2['module_id'], 'module_class' => $row['module_class'], 'module_langname' => $row['module_langname'], 'module_mode' => $row['module_mode'], 'module_auth' => $row['module_auth']); $this->module_manager->update_module_data($module_data); // Check for last sql error happened if ($this->db->get_sql_error_triggered()) { $error = $this->db->sql_error($this->db->get_sql_error_sql()); $this->iohandler->add_error_message('INST_ERR_DB', $error['message']); } } } } $this->module_manager->remove_cache_file($module_class); } }