Exemple #1
0
    /**
     * Track an object.
     *
     * @param int $type			Object type
     * @param int $id			Object id
     * @param bool|int $time	Optional track time to use, if none is given
     * 		the value from time() is used.
     */
    public function track($type, $id, $time = false)
    {
        // Ignore
        $this->get_track_cookie();
        // Cookie storage method
        if (!$this->user->data['is_registered']) {
            $this->track_cookie($type, $id, $time);
            return;
        }
        if ($this->get_track($type, $id, true) >= ($time === false ? time() : (int) $time)) {
            return;
        }
        $sql = 'UPDATE ' . $this->sql_table . '
			SET track_time = ' . ($time === false ? time() : (int) $time) . '
			WHERE track_type = ' . (int) $type . '
				AND track_id = ' . (int) $id . '
				AND track_user_id = ' . (int) $this->user->data['user_id'];
        $this->db->sql_query($sql);
        if (!$this->db->sql_affectedrows()) {
            $sql_ary = array('track_type' => (int) $type, 'track_id' => (int) $id, 'track_user_id' => (int) $this->user->data['user_id'], 'track_time' => $time === false ? time() : (int) $time);
            $this->db->sql_return_on_error(true);
            $this->db->sql_query('INSERT INTO ' . $this->sql_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary));
            $this->db->sql_return_on_error();
        }
        $this->store[$type][$id] = $time === false ? time() : (int) $time;
    }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $table_prefix = $this->config->get('table_prefix');
     $change_prefix = $this->config->get('change_table_prefix', true);
     if (!defined('CONFIG_TABLE')) {
         // CONFIG_TABLE is required by sql_create_index() to check the
         // length of index names. However table_prefix is not defined
         // here yet, so we need to create the constant ourselves.
         define('CONFIG_TABLE', $table_prefix . 'config');
     }
     $db_table_schema = @file_get_contents($this->schema_file_path);
     $db_table_schema = json_decode($db_table_schema, true);
     $total = sizeof($db_table_schema);
     $i = $this->config->get('add_table_index', 0);
     $db_table_schema = array_slice($db_table_schema, $i);
     foreach ($db_table_schema as $table_name => $table_data) {
         $i++;
         $this->db_tools->sql_create_table($change_prefix ? $table_prefix . substr($table_name, 6) : $table_name, $table_data);
         // Stop execution if resource limit is reached
         if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) {
             break;
         }
     }
     $this->config->set('add_table_index', $i);
     if ($i < $total) {
         throw new resource_limit_reached_exception();
     } else {
         @unlink($this->schema_file_path);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $table_prefix = $this->config->get('table_prefix');
     $dbms = $this->config->get('dbms');
     $dbms_info = $this->database_helper->get_available_dbms($dbms);
     // Get schema data from file
     $sql_query = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema_data.sql');
     // Clean up SQL
     $sql_query = $this->replace_dbms_specific_sql($sql_query);
     $sql_query = preg_replace('# phpbb_([^\\s]*) #i', ' ' . $table_prefix . '\\1 ', $sql_query);
     $sql_query = preg_replace_callback('#\\{L_([A-Z0-9\\-_]*)\\}#s', array($this, 'lang_replace_callback'), $sql_query);
     $sql_query = $this->database_helper->remove_comments($sql_query);
     $sql_query = $this->database_helper->split_sql_file($sql_query, $dbms_info[$dbms]['DELIM']);
     $i = $this->config->get('add_default_data_index', 0);
     $total = sizeof($sql_query);
     $sql_query = array_slice($sql_query, $i);
     foreach ($sql_query as $sql) {
         if (!$this->db->sql_query($sql)) {
             $error = $this->db->sql_error($this->db->get_sql_error_sql());
             $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
         }
         $i++;
         // Stop execution if resource limit is reached
         if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) {
             break;
         }
     }
     $this->config->set('add_default_data_index', $i);
     if ($i < $total) {
         throw new resource_limit_reached_exception();
     }
 }
Exemple #4
0
 /**
  * {@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();
 }
Exemple #5
0
    /**
     * {@inheritdoc}
     */
    public function run()
    {
        $this->db->sql_return_on_error(true);
        $sql = 'SELECT group_id
			FROM ' . GROUPS_TABLE . "\n\t\t\tWHERE group_name = 'BOTS'";
        $result = $this->db->sql_query($sql);
        $group_id = (int) $this->db->sql_fetchfield('group_id');
        $this->db->sql_freeresult($result);
        if (!$group_id) {
            // If we reach this point then something has gone very wrong
            $this->io_handler->add_error_message('NO_GROUP');
        }
        foreach ($this->bot_list as $bot_name => $bot_ary) {
            $user_row = array('user_type' => USER_IGNORE, 'group_id' => $group_id, 'username' => $bot_name, 'user_regdate' => time(), 'user_password' => '', 'user_colour' => '9E8DA7', 'user_email' => '', 'user_lang' => $this->install_config->get('default_lang'), 'user_style' => 1, 'user_timezone' => 'UTC', 'user_dateformat' => $this->language->lang('default_dateformat'), 'user_allow_massemail' => 0, 'user_allow_pm' => 0);
            if (!function_exists('user_add')) {
                include $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext;
            }
            $user_id = user_add($user_row);
            if (!$user_id) {
                // If we can't insert this user then continue to the next one to avoid inconsistent data
                $this->io_handler->add_error_message('CONV_ERROR_INSERT_BOT');
                continue;
            }
            $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array('bot_active' => 1, 'bot_name' => (string) $bot_name, 'user_id' => (int) $user_id, 'bot_agent' => (string) $bot_ary[0], 'bot_ip' => (string) $bot_ary[1]));
            $this->db->sql_query($sql);
        }
    }
Exemple #6
0
	/**
	* 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);
	}
    /**
     * Deletes the users from the list, whose visit is to old.
     */
    public function prune()
    {
        $timestamp = time();
        if ($this->config['wwh_version']) {
            /* OLD function
            			self::$prune_timestamp = gmmktime(0, 0, 0, gmdate('m', $timestamp), gmdate('d', $timestamp), gmdate('Y', $timestamp));
            			self::$prune_timestamp -= ($this->config['board_timezone'] * 3600);
            			self::$prune_timestamp -= ($this->config['board_dst'] * 3600);*/
            // Correct Time Zone. https://www.phpbb.com/community/viewtopic.php?f=456&t=2297986&start=30#p14022491
            $timezone = new \DateTimeZone($this->config['board_timezone']);
            self::$prune_timestamp = $this->user->get_timestamp_from_format('Y-m-d H:i:s', date('Y', $timestamp) . '-' . date('m', $timestamp) . '-' . date('d', $timestamp) . ' 00:00:00', $timezone);
            self::$prune_timestamp = self::$prune_timestamp < $timestamp - 86400 ? self::$prune_timestamp + 86400 : (self::$prune_timestamp > $timestamp ? self::$prune_timestamp - 86400 : self::$prune_timestamp);
        } else {
            self::$prune_timestamp = $timestamp - (3600 * $this->config['wwh_del_time_h'] + 60 * $this->config['wwh_del_time_m'] + $this->config['wwh_del_time_s']);
        }
        if (!isset($this->config['wwh_last_clean']) || $this->config['wwh_last_clean'] != self::$prune_timestamp || !$this->config['wwh_version']) {
            $this->db->sql_return_on_error(true);
            $sql = 'DELETE FROM ' . WWH_TABLE . '
				WHERE wwh_lastpage <= ' . self::$prune_timestamp;
            $result = $this->db->sql_query($sql);
            $this->db->sql_return_on_error(false);
            if ((bool) $result === false) {
                // database does not exist yet...
                return false;
            }
            if ($this->config['wwh_version']) {
                $this->config->set('wwh_last_clean', self::$prune_timestamp);
            }
        }
        // Purging was not needed or done succesfully...
        return true;
    }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $server_name = $this->install_config->get('server_name');
     $current_time = time();
     $user_ip = phpbb_ip_normalise($this->iohandler->get_server_variable('REMOTE_ADDR'));
     $user_ip = $user_ip === false ? '' : $user_ip;
     $referer = $this->iohandler->get_server_variable('REFERER');
     // Calculate cookie domain
     $cookie_domain = $server_name;
     if (strpos($cookie_domain, 'www.') === 0) {
         $cookie_domain = substr($cookie_domain, 3);
     }
     // Set default config and post data, this applies to all DB's
     $sql_ary = array('INSERT INTO ' . $this->config_table . " (config_name, config_value)\n\t\t\t\tVALUES ('board_startdate', '{$current_time}')", 'INSERT INTO ' . $this->config_table . " (config_name, config_value)\n\t\t\t\tVALUES ('default_lang', '" . $this->db->sql_escape($this->install_config->get('default_lang')) . "')", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('img_imagick')) . "'\n\t\t\t\tWHERE config_name = 'img_imagick'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_name')) . "'\n\t\t\t\tWHERE config_name = 'server_name'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_port')) . "'\n\t\t\t\tWHERE config_name = 'server_port'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'\n\t\t\t\tWHERE config_name = 'board_email'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'\n\t\t\t\tWHERE config_name = 'board_contact'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($cookie_domain) . "'\n\t\t\t\tWHERE config_name = 'cookie_domain'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "'\n\t\t\t\tWHERE config_name = 'default_dateformat'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('email_enable')) . "'\n\t\t\t\tWHERE config_name = 'email_enable'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_delivery')) . "'\n\t\t\t\tWHERE config_name = 'smtp_delivery'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_host')) . "'\n\t\t\t\tWHERE config_name = 'smtp_host'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_port')) . "'\n\t\t\t\tWHERE config_name = 'smtp_port'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_auth')) . "'\n\t\t\t\tWHERE config_name = 'smtp_auth_method'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_user')) . "'\n\t\t\t\tWHERE config_name = 'smtp_username'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_pass')) . "'\n\t\t\t\tWHERE config_name = 'smtp_password'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('cookie_secure')) . "'\n\t\t\t\tWHERE config_name = 'cookie_secure'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('force_server_vars')) . "'\n\t\t\t\tWHERE config_name = 'force_server_vars'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('script_path')) . "'\n\t\t\t\tWHERE config_name = 'script_path'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_protocol')) . "'\n\t\t\t\tWHERE config_name = 'server_protocol'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE config_name = 'newest_username'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'avatar_salt'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'plupload_salt'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_name')) . "'\n\t\t\t\tWHERE config_name = 'sitename'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_description')) . "'\n\t\t\t\tWHERE config_name = 'site_desc'", 'UPDATE ' . $this->user_table . "\n\t\t\t\tSET username = '******'admin_name')) . "',\n\t\t\t\t\tuser_password='******'admin_passwd')) . "',\n\t\t\t\t\tuser_ip = '" . $this->db->sql_escape($user_ip) . "',\n\t\t\t\t\tuser_lang = '" . $this->db->sql_escape($this->install_config->get('user_language', 'en')) . "',\n\t\t\t\t\tuser_email='" . $this->db->sql_escape($this->install_config->get('board_email')) . "',\n\t\t\t\t\tuser_dateformat='" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "',\n\t\t\t\t\tuser_email_hash = " . $this->db->sql_escape(phpbb_email_hash($this->install_config->get('board_email'))) . ",\n\t\t\t\t\tusername_clean = '" . $this->db->sql_escape(utf8_clean_string($this->install_config->get('admin_name'))) . "'\n\t\t\t\tWHERE username = '******'", 'UPDATE ' . $this->moderator_cache_table . "\n\t\t\t\tSET username = '******'admin_name')) . "'\n\t\t\t\tWHERE username = '******'", 'UPDATE ' . $this->forums_table . "\n\t\t\t\tSET forum_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE forum_last_poster_name = 'Admin'", 'UPDATE ' . $this->topics_table . "\n\t\t\t\tSET topic_first_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',\n\t\t\t\ttopic_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE topic_first_poster_name = 'Admin'\n\t\t\t\t\tOR topic_last_poster_name = 'Admin'", 'UPDATE ' . $this->user_table . "\n\t\t\t\tSET user_regdate = {$current_time}", 'UPDATE ' . $this->posts_table . "\n\t\t\t\tSET post_time = {$current_time}, poster_ip = '" . $this->db->sql_escape($user_ip) . "'", 'UPDATE ' . $this->topics_table . "\n\t\t\t\tSET topic_time = {$current_time}, topic_last_post_time = {$current_time}", 'UPDATE ' . $this->forums_table . "\n\t\t\t\tSET forum_last_post_time = {$current_time}", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->db->sql_server_info(true)) . "'\n\t\t\t\tWHERE config_name = 'dbms_version'");
     if (@extension_loaded('gd')) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = 'core.captcha.plugins.gd'\n\t\t\t\tWHERE config_name = 'captcha_plugin'";
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '1'\n\t\t\t\tWHERE config_name = 'captcha_gd'";
     }
     $ref = substr($referer, strpos($referer, '://') + 3);
     if (!(stripos($ref, $server_name) === 0)) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'referer_validation'";
     }
     // We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
     $cookie_name = 'phpbb3_';
     $rand_str = md5(mt_rand());
     $rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35));
     $rand_str = substr($rand_str, 0, 5);
     $cookie_name .= strtolower($rand_str);
     $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\tSET config_value = '" . $this->db->sql_escape($cookie_name) . "'\n\t\t\tWHERE config_name = 'cookie_name'";
     // Disable avatars if upload directory is not writable
     if (!$this->filesystem->is_writable($this->phpbb_root_path . 'images/avatars/upload/')) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'allow_avatar'";
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'allow_avatar_upload'";
     }
     $i = $this->install_config->get('add_config_settings_index', 0);
     $total = sizeof($sql_ary);
     $sql_ary = array_slice($sql_ary, $i);
     foreach ($sql_ary as $sql) {
         if (!$this->db->sql_query($sql)) {
             $error = $this->db->sql_error($this->db->get_sql_error_sql());
             $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
         }
         $i++;
         // Stop execution if resource limit is reached
         if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) {
             break;
         }
     }
     if ($i < $total) {
         $this->install_config->set('add_config_settings_index', $i);
         throw new resource_limit_reached_exception();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $table_prefix = $this->config->get('table_prefix');
     $dbms = $this->config->get('dbms');
     $dbms_info = $this->database_helper->get_available_dbms($dbms);
     // Get schema data from file
     $sql_query = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema_data.sql');
     // Clean up SQL
     $sql_query = $this->replace_dbms_specific_sql($sql_query);
     $sql_query = preg_replace('# phpbb_([^\\s]*) #i', ' ' . $table_prefix . '\\1 ', $sql_query);
     $sql_query = preg_replace_callback('#\\{L_([A-Z0-9\\-_]*)\\}#s', array($this, 'lang_replace_callback'), $sql_query);
     $sql_query = $this->database_helper->remove_comments($sql_query);
     $sql_query = $this->database_helper->split_sql_file($sql_query, $dbms_info[$dbms]['DELIM']);
     foreach ($sql_query as $sql) {
         if (!$this->db->sql_query($sql)) {
             $error = $this->db->sql_error($this->db->get_sql_error_sql());
             $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
         }
     }
 }
Exemple #10
0
 /**
  * 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;
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $dbms = $this->config->get('dbms');
     $dbms_info = $this->database_helper->get_available_dbms($dbms);
     $delimiter = $dbms_info[$dbms]['DELIM'];
     $table_prefix = $this->config->get('table_prefix');
     $sql_query = @file_get_contents($this->schema_file_path);
     $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);
     $sql_query = $this->database_helper->remove_comments($sql_query);
     $sql_query = $this->database_helper->split_sql_file($sql_query, $delimiter);
     foreach ($sql_query as $sql) {
         if (!$this->db->sql_query($sql)) {
             $error = $this->db->sql_error($this->db->get_sql_error_sql());
             $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
         }
     }
     unset($sql_query);
 }
	/**
	* Updates wordlist and wordmatch tables when a message is posted or changed
	*
	* @param	string	$mode		Contains the post mode: edit, post, reply, quote
	* @param	int		$post_id	The id of the post which is modified/created
	* @param	string	&$message	New or updated post content
	* @param	string	&$subject	New or updated post subject
	* @param	int		$poster_id	Post author's user id
	* @param	int		$forum_id	The id of the forum in which the post is located
	*/
	public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
	{
		if (!$this->config['fulltext_native_load_upd'])
		{
			/**
			* The search indexer is disabled, return
			*/
			return;
		}

		// Split old and new post/subject to obtain array of 'words'
		$split_text = $this->split_message($message);
		$split_title = $this->split_message($subject);

		$cur_words = array('post' => array(), 'title' => array());

		$words = array();
		if ($mode == 'edit')
		{
			$words['add']['post'] = array();
			$words['add']['title'] = array();
			$words['del']['post'] = array();
			$words['del']['title'] = array();

			$sql = 'SELECT w.word_id, w.word_text, m.title_match
				FROM ' . SEARCH_WORDLIST_TABLE . ' w, ' . SEARCH_WORDMATCH_TABLE . " m
				WHERE m.post_id = $post_id
					AND w.word_id = m.word_id";
			$result = $this->db->sql_query($sql);

			while ($row = $this->db->sql_fetchrow($result))
			{
				$which = ($row['title_match']) ? 'title' : 'post';
				$cur_words[$which][$row['word_text']] = $row['word_id'];
			}
			$this->db->sql_freeresult($result);

			$words['add']['post'] = array_diff($split_text, array_keys($cur_words['post']));
			$words['add']['title'] = array_diff($split_title, array_keys($cur_words['title']));
			$words['del']['post'] = array_diff(array_keys($cur_words['post']), $split_text);
			$words['del']['title'] = array_diff(array_keys($cur_words['title']), $split_title);
		}
		else
		{
			$words['add']['post'] = $split_text;
			$words['add']['title'] = $split_title;
			$words['del']['post'] = array();
			$words['del']['title'] = array();
		}
		unset($split_text);
		unset($split_title);

		// Get unique words from the above arrays
		$unique_add_words = array_unique(array_merge($words['add']['post'], $words['add']['title']));

		// We now have unique arrays of all words to be added and removed and
		// individual arrays of added and removed words for text and title. What
		// we need to do now is add the new words (if they don't already exist)
		// and then add (or remove) matches between the words and this post
		if (sizeof($unique_add_words))
		{
			$sql = 'SELECT word_id, word_text
				FROM ' . SEARCH_WORDLIST_TABLE . '
				WHERE ' . $this->db->sql_in_set('word_text', $unique_add_words);
			$result = $this->db->sql_query($sql);

			$word_ids = array();
			while ($row = $this->db->sql_fetchrow($result))
			{
				$word_ids[$row['word_text']] = $row['word_id'];
			}
			$this->db->sql_freeresult($result);
			$new_words = array_diff($unique_add_words, array_keys($word_ids));

			$this->db->sql_transaction('begin');
			if (sizeof($new_words))
			{
				$sql_ary = array();

				foreach ($new_words as $word)
				{
					$sql_ary[] = array('word_text' => (string) $word, 'word_count' => 0);
				}
				$this->db->sql_return_on_error(true);
				$this->db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary);
				$this->db->sql_return_on_error(false);
			}
			unset($new_words, $sql_ary);
		}
		else
		{
			$this->db->sql_transaction('begin');
		}

		// now update the search match table, remove links to removed words and add links to new words
		foreach ($words['del'] as $word_in => $word_ary)
		{
			$title_match = ($word_in == 'title') ? 1 : 0;

			if (sizeof($word_ary))
			{
				$sql_in = array();
				foreach ($word_ary as $word)
				{
					$sql_in[] = $cur_words[$word_in][$word];
				}

				$sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . '
					WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . '
						AND post_id = ' . intval($post_id) . "
						AND title_match = $title_match";
				$this->db->sql_query($sql);

				$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
					SET word_count = word_count - 1
					WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . '
						AND word_count > 0';
				$this->db->sql_query($sql);

				unset($sql_in);
			}
		}

		$this->db->sql_return_on_error(true);
		foreach ($words['add'] as $word_in => $word_ary)
		{
			$title_match = ($word_in == 'title') ? 1 : 0;

			if (sizeof($word_ary))
			{
				$sql = 'INSERT INTO ' . SEARCH_WORDMATCH_TABLE . ' (post_id, word_id, title_match)
					SELECT ' . (int) $post_id . ', word_id, ' . (int) $title_match . '
					FROM ' . SEARCH_WORDLIST_TABLE . '
					WHERE ' . $this->db->sql_in_set('word_text', $word_ary);
				$this->db->sql_query($sql);

				$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
					SET word_count = word_count + 1
					WHERE ' . $this->db->sql_in_set('word_text', $word_ary);
				$this->db->sql_query($sql);
			}
		}
		$this->db->sql_return_on_error(false);

		$this->db->sql_transaction('commit');

		// destroy cached search results containing any of the words removed or added
		$this->destroy_cache(array_unique(array_merge($words['add']['post'], $words['add']['title'], $words['del']['post'], $words['del']['title'])), array($poster_id));

		unset($unique_add_words);
		unset($words);
		unset($cur_words);
	}
Exemple #13
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $dbms = $this->config->get('dbms');
     $dbms_info = $this->database_helper->get_available_dbms($dbms);
     $schema_name = $dbms_info[$dbms]['SCHEMA'];
     $delimiter = $dbms_info[$dbms]['DELIM'];
     $table_prefix = $this->config->get('table_prefix');
     if ($dbms === 'mysql') {
         if (version_compare($this->db->sql_server_info(true), '4.1.3', '>=')) {
             $schema_name .= '_41';
         } else {
             $schema_name .= '_40';
         }
     }
     $db_schema_path = $this->phpbb_root_path . 'install/schemas/' . $schema_name . '_schema.sql';
     // Load database vendor specific code if there is any
     if ($this->filesystem->exists($db_schema_path)) {
         $sql_query = @file_get_contents($db_schema_path);
         $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);
         $sql_query = $this->database_helper->remove_comments($sql_query);
         $sql_query = $this->database_helper->split_sql_file($sql_query, $delimiter);
         foreach ($sql_query as $sql) {
             if (!$this->db->sql_query($sql)) {
                 $error = $this->db->sql_error($this->db->get_sql_error_sql());
                 $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
             }
         }
         unset($sql_query);
     }
     $change_prefix = false;
     // Generate database schema
     if ($this->filesystem->exists($this->phpbb_root_path . 'install/schemas/schema.json')) {
         $db_table_schema = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema.json');
         $db_table_schema = json_decode($db_table_schema, true);
         $change_prefix = true;
     } else {
         global $table_prefix;
         $table_prefix = $this->config->get('table_prefix');
         if (!defined('CONFIG_TABLE')) {
             // We need to include the constants file for the table constants
             // when we generate the schema from the migration files.
             include $this->phpbb_root_path . 'includes/constants.' . $this->php_ext;
         }
         $finder = new \phpbb\finder($this->filesystem, $this->phpbb_root_path, null, $this->php_ext);
         $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
         $factory = new \phpbb\db\tools\factory();
         $db_tools = $factory->get($this->db, true);
         $schema_generator = new \phpbb\db\migration\schema_generator($migrator_classes, new \phpbb\config\config(array()), $this->db, $db_tools, $this->phpbb_root_path, $this->php_ext, $table_prefix);
         $db_table_schema = $schema_generator->get_schema();
     }
     if (!defined('CONFIG_TABLE')) {
         // CONFIG_TABLE is required by sql_create_index() to check the
         // length of index names. However table_prefix is not defined
         // here yet, so we need to create the constant ourselves.
         define('CONFIG_TABLE', $table_prefix . 'config');
     }
     foreach ($db_table_schema as $table_name => $table_data) {
         $this->db_tools->sql_create_table($change_prefix ? $table_prefix . substr($table_name, 6) : $table_name, $table_data);
     }
 }
Exemple #14
0
 /**
  * Validates settings form
  *
  * @param string	$convertor
  */
 public function proccess_settings_form($convertor)
 {
     global $phpbb_root_path, $phpEx, $get_info;
     $phpbb_root_path = $this->phpbb_root_path;
     $phpEx = $this->php_ext;
     $get_info = true;
     require_once $this->phpbb_root_path . 'includes/constants.' . $this->php_ext;
     require_once $this->phpbb_root_path . 'includes/functions_convert.' . $this->php_ext;
     // Include convertor if available
     $convertor_file_path = $this->phpbb_root_path . 'install/convertors/convert_' . $convertor . '.' . $this->php_ext;
     include $convertor_file_path;
     // We expect to have an AJAX request here
     $src_dbms = $this->request->variable('src_dbms', $convertor_data['dbms']);
     $src_dbhost = $this->request->variable('src_dbhost', $convertor_data['dbhost']);
     $src_dbport = $this->request->variable('src_dbport', $convertor_data['dbport']);
     $src_dbuser = $this->request->variable('src_dbuser', $convertor_data['dbuser']);
     $src_dbpasswd = $this->request->variable('src_dbpasswd', $convertor_data['dbpasswd']);
     $src_dbname = $this->request->variable('src_dbname', $convertor_data['dbname']);
     $src_table_prefix = $this->request->variable('src_table_prefix', $convertor_data['table_prefix']);
     $forum_path = $this->request->variable('forum_path', $convertor_data['forum_path']);
     $refresh = $this->request->variable('refresh', 1);
     // Default URL of the old board
     // @todo Are we going to use this for attempting to convert URL references in posts, or should we remove it?
     //		-> We should convert old urls to the new relative urls format
     // $src_url = $request->variable('src_url', 'Not in use at the moment');
     // strip trailing slash from old forum path
     $forum_path = strlen($forum_path) && $forum_path[strlen($forum_path) - 1] == '/' ? substr($forum_path, 0, -1) : $forum_path;
     $error = array();
     if (!file_exists($this->phpbb_root_path . $forum_path . '/' . $test_file)) {
         $error[] = $this->language->lang('COULD_NOT_FIND_PATH', $forum_path);
     }
     $connect_test = false;
     $available_dbms = $this->db_helper->get_available_dbms(false, true, true);
     if (!isset($available_dbms[$src_dbms]) || !$available_dbms[$src_dbms]['AVAILABLE']) {
         $error[] = $this->language->lang('INST_ERR_NO_DB');
     } else {
         $connect_test = $this->db_helper->check_database_connection($src_dbms, $src_dbhost, $src_dbport, $src_dbuser, $src_dbpasswd, $src_dbname, $src_table_prefix);
     }
     extract($this->config_php_file->get_all());
     // The forum prefix of the old and the new forum can only be the same if two different databases are used.
     if ($src_table_prefix === $table_prefix && $src_dbms === $dbms && $src_dbhost === $dbhost && $src_dbport === $dbport && $src_dbname === $dbname) {
         $error[] = $this->language->lang('TABLE_PREFIX_SAME', $src_table_prefix);
     }
     if (!$connect_test) {
         $error[] = $this->language->lang('INST_ERR_DB_CONNECT');
     }
     $src_dbms = $this->config_php_file->convert_30_dbms_to_31($src_dbms);
     // Check table prefix
     if (empty($error)) {
         // initiate database connection to old db if old and new db differ
         global $src_db, $same_db;
         $src_db = $same_db = false;
         if ($src_dbms != $dbms || $src_dbhost != $dbhost || $src_dbport != $dbport || $src_dbname != $dbname || $src_dbuser != $dbuser) {
             /** @var \phpbb\db\driver\driver_interface $src_db */
             $src_db = new $src_dbms();
             $src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true);
             $same_db = false;
         } else {
             $src_db = $this->db;
             $same_db = true;
         }
         $src_db->sql_return_on_error(true);
         $this->db->sql_return_on_error(true);
         // Try to select one row from the first table to see if the prefix is OK
         $result = $src_db->sql_query_limit('SELECT * FROM ' . $src_table_prefix . $tables[0], 1);
         if (!$result) {
             $prefixes = array();
             $db_tools_factory = new \phpbb\db\tools\factory();
             $db_tools = $db_tools_factory->get($src_db);
             $tables_existing = $db_tools->sql_list_tables();
             $tables_existing = array_map('strtolower', $tables_existing);
             foreach ($tables_existing as $table_name) {
                 compare_table($tables, $table_name, $prefixes);
             }
             unset($tables_existing);
             foreach ($prefixes as $prefix => $count) {
                 if ($count >= sizeof($tables)) {
                     $possible_prefix = $prefix;
                     break;
                 }
             }
             $msg = '';
             if (!empty($convertor_data['table_prefix'])) {
                 $msg .= $this->language->lang_array('DEFAULT_PREFIX_IS', array($convertor_data['forum_name'], $convertor_data['table_prefix']));
             }
             if (!empty($possible_prefix)) {
                 $msg .= '<br />';
                 $msg .= $possible_prefix == '*' ? $this->language->lang('BLANK_PREFIX_FOUND') : $this->language->lang_array('PREFIX_FOUND', array($possible_prefix));
                 $src_table_prefix = $possible_prefix == '*' ? '' : $possible_prefix;
             }
             $error[] = $msg;
         }
         $src_db->sql_freeresult($result);
         $src_db->sql_return_on_error(false);
     }
     if (empty($error)) {
         // Save convertor Status
         $this->config->set('convert_progress', serialize(array('step' => '', 'table_prefix' => $src_table_prefix, 'tag' => $convertor)), false);
         $this->config->set('convert_db_server', serialize(array('dbms' => $src_dbms, 'dbhost' => $src_dbhost, 'dbport' => $src_dbport, 'dbname' => $src_dbname)), false);
         $this->config->set('convert_db_user', serialize(array('dbuser' => $src_dbuser, 'dbpasswd' => $src_dbpasswd)), false);
         // Save options
         $this->config->set('convert_options', serialize(array('forum_path' => $this->phpbb_root_path . $forum_path, 'refresh' => $refresh)), false);
         $url = $this->controller_helper->route('phpbb_convert_convert', array('converter' => $convertor));
         $this->iohandler->redirect($url);
         $this->iohandler->send_response(true);
     } else {
         $this->render_settings_form($error);
     }
 }
Exemple #15
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $module_classes = array('acp', 'mcp', 'ucp');
     $total = sizeof($module_classes);
     $i = $this->config->get('module_class_index', 0);
     $module_classes = array_slice($module_classes, $i);
     foreach ($module_classes as $module_class) {
         $categories = $this->config->get('module_categories_array', array());
         $k = $this->config->get('module_categories_index', 0);
         $module_categories = array_slice($this->module_categories[$module_class], $k);
         $timed_out = false;
         foreach ($module_categories 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'];
                 }
             }
             $k++;
             // Stop execution if resource limit is reached
             if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) {
                 $timed_out = true;
                 break;
             }
         }
         $this->config->set('module_categories_array', $categories);
         $this->config->set('module_categories_index', $k);
         if ($timed_out) {
             throw new resource_limit_reached_exception();
         }
         // Get the modules we want to add... returned sorted by name
         $module_info = $this->module_manager->get_module_infos($module_class);
         $k = $this->config->get('module_info_index', 0);
         $module_info = array_slice($module_info, $k);
         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']);
                     }
                 }
             }
             $k++;
             // Stop execution if resource limit is reached
             if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) {
                 $timed_out = true;
                 break;
             }
         }
         $this->config->set('module_info_index', $k);
         // Stop execution if resource limit is reached
         if ($timed_out) {
             throw new resource_limit_reached_exception();
         }
         // Move some of the modules around since the code above will put them in the wrong place
         if (!$this->config->get('modules_ordered', false)) {
             $this->order_modules($module_class);
             $this->config->set('modules_ordered', true);
             // Stop execution if resource limit is reached
             if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) {
                 throw new resource_limit_reached_exception();
             }
         }
         // 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])) {
             $this->add_module_extras($module_class);
         }
         $this->module_manager->remove_cache_file($module_class);
         $i++;
         $this->config->set('module_class_index', $i);
         $this->config->set('module_categories_index', 0);
         $this->config->set('module_info_index', 0);
         $this->config->set('added_extra_modules', false);
         $this->config->set('modules_ordered', false);
         $this->config->set('module_categories_array', array());
         // Stop execution if resource limit is reached
         if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) {
             break;
         }
     }
     if ($i < $total) {
         throw new resource_limit_reached_exception();
     }
 }
Exemple #16
0
    /**
     * {@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);
        }
    }