install/install_convert.php
changeset 8 c9487b1e7ffc
parent 7 a0100cde92ff
child 9 e5e5221fa5e1
     1.1 --- a/install/install_convert.php	Wed Mar 07 23:10:55 2012 +0400
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,2113 +0,0 @@
     1.4 -<?php
     1.5 -/**
     1.6 -*
     1.7 -* @package install
     1.8 -* @version $Id$
     1.9 -* @copyright (c) 2006 phpBB Group
    1.10 -* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 -*
    1.12 -*/
    1.13 -
    1.14 -/**
    1.15 -*/
    1.16 -
    1.17 -if (!defined('IN_INSTALL'))
    1.18 -{
    1.19 -	// Someone has tried to access the file direct. This is not a good idea, so exit
    1.20 -	exit;
    1.21 -}
    1.22 -
    1.23 -if (!empty($setmodules))
    1.24 -{
    1.25 -	$module[] = array(
    1.26 -		'module_type'		=> 'install',
    1.27 -		'module_title'		=> 'CONVERT',
    1.28 -		'module_filename'	=> substr(basename(__FILE__), 0, -strlen($phpEx)-1),
    1.29 -		'module_order'		=> 20,
    1.30 -		'module_subs'		=> '',
    1.31 -		'module_stages'		=> array('INTRO', 'SETTINGS', 'IN_PROGRESS', 'FINAL'),
    1.32 -		'module_reqs'		=> ''
    1.33 -	);
    1.34 -}
    1.35 -
    1.36 -/**
    1.37 -* Class holding all convertor-specific details.
    1.38 -* @package install
    1.39 -*/
    1.40 -class convert
    1.41 -{
    1.42 -	var $options = array();
    1.43 -
    1.44 -	var $convertor_tag = '';
    1.45 -	var $src_dbms = '';
    1.46 -	var $src_dbhost = '';
    1.47 -	var $src_dbport = '';
    1.48 -	var $src_dbuser = '';
    1.49 -	var $src_dbpasswd = '';
    1.50 -	var $src_dbname = '';
    1.51 -	var $src_table_prefix = '';
    1.52 -
    1.53 -	var $convertor_data = array();
    1.54 -	var $tables = array();
    1.55 -	var $config_schema = array();
    1.56 -	var $convertor = array();
    1.57 -	var $src_truncate_statement = 'DELETE FROM ';
    1.58 -	var $truncate_statement = 'DELETE FROM ';
    1.59 -
    1.60 -	var $fulltext_search;
    1.61 -
    1.62 -	// Batch size, can be adjusted by the conversion file
    1.63 -	// For big boards a value of 6000 seems to be optimal
    1.64 -	var $batch_size = 2000;
    1.65 -	// Number of rows to be inserted at once (extended insert) if supported
    1.66 -	// For installations having enough memory a value of 60 may be good.
    1.67 -	var $num_wait_rows = 20;
    1.68 -
    1.69 -	// Mysqls internal recoding engine messing up with our (better) functions? We at least support more encodings than mysql so should use it in favor.
    1.70 -	var $mysql_convert = false;
    1.71 -
    1.72 -	var $p_master;
    1.73 -
    1.74 -	function convert(&$p_master)
    1.75 -	{
    1.76 -		$this->p_master = &$p_master;
    1.77 -	}
    1.78 -}
    1.79 -
    1.80 -/**
    1.81 -* Convert class for conversions
    1.82 -* @package install
    1.83 -*/
    1.84 -class install_convert extends module
    1.85 -{
    1.86 -	/**
    1.87 -	* Variables used while converting, they are accessible from the global variable $convert
    1.88 -	*/
    1.89 -	function install_convert(&$p_master)
    1.90 -	{
    1.91 -		$this->p_master = &$p_master;
    1.92 -	}
    1.93 -
    1.94 -	function main($mode, $sub)
    1.95 -	{
    1.96 -		global $lang, $template, $phpbb_root_path, $phpEx, $cache, $config, $language, $table_prefix;
    1.97 -		global $convert;
    1.98 -
    1.99 -		$this->tpl_name = 'install_convert';
   1.100 -		$this->mode = $mode;
   1.101 -
   1.102 -		$convert = new convert($this->p_master);
   1.103 -
   1.104 -		switch ($sub)
   1.105 -		{
   1.106 -			case 'intro':
   1.107 -				// Try opening config file
   1.108 -				// @todo If phpBB is not installed, we need to do a cut-down installation here
   1.109 -				// For now, we redirect to the installation script instead
   1.110 -				if (@file_exists($phpbb_root_path . 'config.' . $phpEx))
   1.111 -				{
   1.112 -					include($phpbb_root_path . 'config.' . $phpEx);
   1.113 -				}
   1.114 -
   1.115 -				if (!defined('PHPBB_INSTALLED'))
   1.116 -				{
   1.117 -					$template->assign_vars(array(
   1.118 -						'S_NOT_INSTALLED'		=> true,
   1.119 -						'TITLE'					=> $lang['BOARD_NOT_INSTALLED'],
   1.120 -						'BODY'					=> sprintf($lang['BOARD_NOT_INSTALLED_EXPLAIN'], append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=install&amp;language=' . $language)),
   1.121 -					));
   1.122 -
   1.123 -					return;
   1.124 -				}
   1.125 -
   1.126 -				require($phpbb_root_path . 'config.' . $phpEx);
   1.127 -				require($phpbb_root_path . 'includes/constants.' . $phpEx);
   1.128 -				require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
   1.129 -				require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
   1.130 -
   1.131 -				$db = new $sql_db();
   1.132 -				$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
   1.133 -				unset($dbpasswd);
   1.134 -
   1.135 -				// We need to fill the config to let internal functions correctly work
   1.136 -				$sql = 'SELECT *
   1.137 -					FROM ' . CONFIG_TABLE;
   1.138 -				$result = $db->sql_query($sql);
   1.139 -
   1.140 -				$config = array();
   1.141 -				while ($row = $db->sql_fetchrow($result))
   1.142 -				{
   1.143 -					$config[$row['config_name']] = $row['config_value'];
   1.144 -				}
   1.145 -				$db->sql_freeresult($result);
   1.146 -
   1.147 -				// Detect if there is already a conversion in progress at this point and offer to resume
   1.148 -				// It's quite possible that the user will get disconnected during a large conversion so they need to be able to resume it
   1.149 -				$new_conversion = request_var('new_conv', 0);
   1.150 -
   1.151 -				if ($new_conversion)
   1.152 -				{
   1.153 -					$config['convert_progress'] = '';
   1.154 -					$config['convert_db_server'] = '';
   1.155 -					$config['convert_db_user'] = '';
   1.156 -					$db->sql_query('DELETE FROM ' . CONFIG_TABLE . "
   1.157 -						WHERE config_name = 'convert_progress'
   1.158 -							OR config_name = 'convert_db_server'
   1.159 -							OR config_name = 'convert_db_user'"
   1.160 -					);
   1.161 -				}
   1.162 -
   1.163 -				// Let's see if there is a conversion in the works...
   1.164 -				$options = array();
   1.165 -				if (!empty($config['convert_progress']) && !empty($config['convert_db_server']) && !empty($config['convert_db_user']) && !empty($config['convert_options']))
   1.166 -				{
   1.167 -					$options = unserialize($config['convert_progress']);
   1.168 -					$options = array_merge($options, unserialize($config['convert_db_server']), unserialize($config['convert_db_user']), unserialize($config['convert_options']));
   1.169 -				}
   1.170 -
   1.171 -				// This information should have already been checked once, but do it again for safety
   1.172 -				if (!empty($options) && !empty($options['tag']) &&
   1.173 -					isset($options['dbms']) &&
   1.174 -					isset($options['dbhost']) &&
   1.175 -					isset($options['dbport']) &&
   1.176 -					isset($options['dbuser']) &&
   1.177 -					isset($options['dbpasswd']) &&
   1.178 -					isset($options['dbname']) &&
   1.179 -					isset($options['table_prefix']))
   1.180 -				{
   1.181 -					$this->page_title = $lang['CONTINUE_CONVERT'];
   1.182 -
   1.183 -					$template->assign_vars(array(
   1.184 -						'TITLE'			=> $lang['CONTINUE_CONVERT'],
   1.185 -						'BODY'			=> $lang['CONTINUE_CONVERT_BODY'],
   1.186 -						'L_NEW'			=> $lang['CONVERT_NEW_CONVERSION'],
   1.187 -						'L_CONTINUE'	=> $lang['CONTINUE_OLD_CONVERSION'],
   1.188 -						'S_CONTINUE'	=> true,
   1.189 -
   1.190 -						'U_NEW_ACTION'		=> $this->p_master->module_url . "?mode={$this->mode}&amp;sub=intro&amp;new_conv=1&amp;language=$language",
   1.191 -						'U_CONTINUE_ACTION'	=> $this->p_master->module_url . "?mode={$this->mode}&amp;sub=in_progress&amp;tag={$options['tag']}{$options['step']}&amp;language=$language",
   1.192 -					));
   1.193 -
   1.194 -					return;
   1.195 -				}
   1.196 -
   1.197 -				$this->list_convertors($sub);
   1.198 -
   1.199 -			break;
   1.200 -
   1.201 -			case 'settings':
   1.202 -				$this->get_convert_settings($sub);
   1.203 -			break;
   1.204 -
   1.205 -			case 'in_progress':
   1.206 -				$this->convert_data($sub);
   1.207 -			break;
   1.208 -
   1.209 -			case 'final':
   1.210 -				$this->page_title = $lang['CONVERT_COMPLETE'];
   1.211 -
   1.212 -				$template->assign_vars(array(
   1.213 -					'TITLE'		=> $lang['CONVERT_COMPLETE'],
   1.214 -					'BODY'		=> $lang['CONVERT_COMPLETE_EXPLAIN'],
   1.215 -				));
   1.216 -
   1.217 -				// If we reached this step (conversion completed) we want to purge the cache and log the user out.
   1.218 -				// This is for making sure the session get not screwed due to the 3.0.x users table being completely new.
   1.219 -				$cache->purge();
   1.220 -
   1.221 -				require($phpbb_root_path . 'config.' . $phpEx);
   1.222 -				require($phpbb_root_path . 'includes/constants.' . $phpEx);
   1.223 -				require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
   1.224 -				require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
   1.225 -
   1.226 -				$db = new $sql_db();
   1.227 -				$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
   1.228 -				unset($dbpasswd);
   1.229 -
   1.230 -				$sql = 'SELECT config_value
   1.231 -					FROM ' . CONFIG_TABLE . '
   1.232 -					WHERE config_name = \'search_type\'';
   1.233 -				$result = $db->sql_query($sql);
   1.234 -
   1.235 -				if ($db->sql_fetchfield('config_value') != 'fulltext_mysql')
   1.236 -				{
   1.237 -					$template->assign_vars(array(
   1.238 -						'S_ERROR_BOX'	=> true,
   1.239 -						'ERROR_TITLE'	=> $lang['SEARCH_INDEX_UNCONVERTED'],
   1.240 -						'ERROR_MSG'		=> $lang['SEARCH_INDEX_UNCONVERTED_EXPLAIN'],
   1.241 -					));
   1.242 -				}
   1.243 -
   1.244 -				switch ($db->sql_layer)
   1.245 -				{
   1.246 -					case 'sqlite':
   1.247 -					case 'firebird':
   1.248 -						$db->sql_query('DELETE FROM ' . SESSIONS_KEYS_TABLE);
   1.249 -						$db->sql_query('DELETE FROM ' . SESSIONS_TABLE);
   1.250 -					break;
   1.251 -
   1.252 -					default:
   1.253 -						$db->sql_query('TRUNCATE TABLE ' . SESSIONS_KEYS_TABLE);
   1.254 -						$db->sql_query('TRUNCATE TABLE ' . SESSIONS_TABLE);
   1.255 -					break;
   1.256 -				}
   1.257 -
   1.258 -			break;
   1.259 -		}
   1.260 -	}
   1.261 -
   1.262 -	/**
   1.263 -	* Generate a list of all available conversion modules
   1.264 -	*/
   1.265 -	function list_convertors($sub)
   1.266 -	{
   1.267 -		global $lang, $language, $template, $phpbb_root_path, $phpEx;
   1.268 -
   1.269 -		$this->page_title = $lang['SUB_INTRO'];
   1.270 -
   1.271 -		$template->assign_vars(array(
   1.272 -			'TITLE'		=> $lang['CONVERT_INTRO'],
   1.273 -			'BODY'		=> $lang['CONVERT_INTRO_BODY'],
   1.274 -
   1.275 -			'L_AUTHOR'					=> $lang['AUTHOR'],
   1.276 -			'L_AVAILABLE_CONVERTORS'	=> $lang['AVAILABLE_CONVERTORS'],
   1.277 -			'L_CONVERT'					=> $lang['CONVERT'],
   1.278 -			'L_NO_CONVERTORS'			=> $lang['NO_CONVERTORS'],
   1.279 -			'L_OPTIONS'					=> $lang['CONVERT_OPTIONS'],
   1.280 -			'L_SOFTWARE'				=> $lang['SOFTWARE'],
   1.281 -			'L_VERSION'					=> $lang['VERSION'],
   1.282 -
   1.283 -			'S_LIST'	=> true,
   1.284 -		));
   1.285 -
   1.286 -		$convertors = $sort = array();
   1.287 -		$get_info = true;
   1.288 -
   1.289 -		$handle = @opendir('./convertors/');
   1.290 -
   1.291 -		if (!$handle)
   1.292 -		{
   1.293 -			$this->error('Unable to access the convertors directory', __LINE__, __FILE__);
   1.294 -		}
   1.295 -
   1.296 -		while ($entry = readdir($handle))
   1.297 -		{
   1.298 -			if (preg_match('/^convert_([a-z0-9_]+).' . $phpEx . '$/i', $entry, $m))
   1.299 -			{
   1.300 -				include('./convertors/' . $entry);
   1.301 -				if (isset($convertor_data))
   1.302 -				{
   1.303 -					$sort[strtolower($convertor_data['forum_name'])] = sizeof($convertors);
   1.304 -
   1.305 -					$convertors[] = array(
   1.306 -						'tag'			=>	$m[1],
   1.307 -						'forum_name'	=>	$convertor_data['forum_name'],
   1.308 -						'version'		=>	$convertor_data['version'],
   1.309 -						'dbms'			=>	$convertor_data['dbms'],
   1.310 -						'dbhost'		=>	$convertor_data['dbhost'],
   1.311 -						'dbport'		=>	$convertor_data['dbport'],
   1.312 -						'dbuser'		=>	$convertor_data['dbuser'],
   1.313 -						'dbpasswd'		=>	$convertor_data['dbpasswd'],
   1.314 -						'dbname'		=>	$convertor_data['dbname'],
   1.315 -						'table_prefix'	=>	$convertor_data['table_prefix'],
   1.316 -						'author'		=>	$convertor_data['author']
   1.317 -					);
   1.318 -				}
   1.319 -				unset($convertor_data);
   1.320 -			}
   1.321 -		}
   1.322 -		closedir($handle);
   1.323 -
   1.324 -		@ksort($sort);
   1.325 -
   1.326 -		foreach ($sort as $void => $index)
   1.327 -		{
   1.328 -			$template->assign_block_vars('convertors', array(
   1.329 -				'AUTHOR'	=> $convertors[$index]['author'],
   1.330 -				'SOFTWARE'	=> $convertors[$index]['forum_name'],
   1.331 -				'VERSION'	=> $convertors[$index]['version'],
   1.332 -
   1.333 -				'U_CONVERT'	=> $this->p_master->module_url . "?mode={$this->mode}&amp;language=$language&amp;sub=settings&amp;tag=" . $convertors[$index]['tag'],
   1.334 -			));
   1.335 -		}
   1.336 -	}
   1.337 -
   1.338 -	/**
   1.339 -	*/
   1.340 -	function get_convert_settings($sub)
   1.341 -	{
   1.342 -		global $lang, $language, $template, $db, $phpbb_root_path, $phpEx, $config, $cache;
   1.343 -
   1.344 -		require($phpbb_root_path . 'config.' . $phpEx);
   1.345 -		require($phpbb_root_path . 'includes/constants.' . $phpEx);
   1.346 -		require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
   1.347 -		require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
   1.348 -
   1.349 -		$db = new $sql_db();
   1.350 -		$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
   1.351 -		unset($dbpasswd);
   1.352 -
   1.353 -		$this->page_title = $lang['STAGE_SETTINGS'];
   1.354 -
   1.355 -		// We need to fill the config to let internal functions correctly work
   1.356 -		$sql = 'SELECT *
   1.357 -			FROM ' . CONFIG_TABLE;
   1.358 -		$result = $db->sql_query($sql);
   1.359 -
   1.360 -		$config = array();
   1.361 -		while ($row = $db->sql_fetchrow($result))
   1.362 -		{
   1.363 -			$config[$row['config_name']] = $row['config_value'];
   1.364 -		}
   1.365 -		$db->sql_freeresult($result);
   1.366 -
   1.367 -		$convertor_tag = request_var('tag', '');
   1.368 -
   1.369 -		if (empty($convertor_tag))
   1.370 -		{
   1.371 -			$this->p_master->error($lang['NO_CONVERT_SPECIFIED'], __LINE__, __FILE__);
   1.372 -		}
   1.373 -		$get_info = true;
   1.374 -
   1.375 -		// check security implications of direct inclusion
   1.376 -		$convertor_tag = basename($convertor_tag);
   1.377 -		if (!file_exists('./convertors/convert_' . $convertor_tag . '.' . $phpEx))
   1.378 -		{
   1.379 -			$this->p_master->error($lang['CONVERT_NOT_EXIST'], __LINE__, __FILE__);
   1.380 -		}
   1.381 -
   1.382 -		include('./convertors/convert_' . $convertor_tag . '.' . $phpEx);
   1.383 -
   1.384 -		// The test_file is a file that should be present in the location of the old board.
   1.385 -		if (!isset($test_file))
   1.386 -		{
   1.387 -			$this->p_master->error($lang['DEV_NO_TEST_FILE'], __LINE__, __FILE__);
   1.388 -		}
   1.389 -
   1.390 -		$submit = (isset($_POST['submit'])) ? true : false;
   1.391 -
   1.392 -		$src_dbms			= request_var('src_dbms', $convertor_data['dbms']);
   1.393 -		$src_dbhost			= request_var('src_dbhost', $convertor_data['dbhost']);
   1.394 -		$src_dbport			= request_var('src_dbport', $convertor_data['dbport']);
   1.395 -		$src_dbuser			= request_var('src_dbuser', $convertor_data['dbuser']);
   1.396 -		$src_dbpasswd		= request_var('src_dbpasswd', $convertor_data['dbpasswd']);
   1.397 -		$src_dbname			= request_var('src_dbname', $convertor_data['dbname']);
   1.398 -		$src_table_prefix	= request_var('src_table_prefix', $convertor_data['table_prefix']);
   1.399 -		$forum_path			= request_var('forum_path', $convertor_data['forum_path']);
   1.400 -		$refresh			= request_var('refresh', 1);
   1.401 -
   1.402 -		// Default URL of the old board
   1.403 -		// @todo Are we going to use this for attempting to convert URL references in posts, or should we remove it?
   1.404 -		//		-> We should convert old urls to the new relative urls format
   1.405 -		// $src_url = request_var('src_url', 'Not in use at the moment');
   1.406 -
   1.407 -		// strip trailing slash from old forum path
   1.408 -		$forum_path = (strlen($forum_path) && $forum_path[strlen($forum_path) - 1] == '/') ? substr($forum_path, 0, -1) : $forum_path;
   1.409 -
   1.410 -		$error = array();
   1.411 -		if ($submit)
   1.412 -		{
   1.413 -			if (!@file_exists('./../' . $forum_path . '/' . $test_file))
   1.414 -			{
   1.415 -				$error[] = sprintf($lang['COULD_NOT_FIND_PATH'], $forum_path);
   1.416 -			}
   1.417 -
   1.418 -			$connect_test = false;
   1.419 -			$available_dbms = get_available_dbms(false, true, true);
   1.420 -
   1.421 -			if (!isset($available_dbms[$src_dbms]) || !$available_dbms[$src_dbms]['AVAILABLE'])
   1.422 -			{
   1.423 -				$error['db'][] = $lang['INST_ERR_NO_DB'];
   1.424 -				$connect_test = false;
   1.425 -			}
   1.426 -			else
   1.427 -			{
   1.428 -				$connect_test = connect_check_db(true, $error, $available_dbms[$src_dbms], $src_table_prefix, $src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, true, ($src_dbms == $dbms) ? false : true, false);
   1.429 -			}
   1.430 -
   1.431 -			// The forum prefix of the old and the new forum can only be the same if two different databases are used.
   1.432 -			if ($src_table_prefix == $table_prefix && $src_dbms == $dbms && $src_dbhost == $dbhost && $src_dbport == $dbport && $src_dbname == $dbname)
   1.433 -			{
   1.434 -				$error[] = sprintf($lang['TABLE_PREFIX_SAME'], $src_table_prefix);
   1.435 -			}
   1.436 -
   1.437 -			// Check table prefix
   1.438 -			if (!sizeof($error))
   1.439 -			{
   1.440 -				// initiate database connection to old db if old and new db differ
   1.441 -				global $src_db, $same_db;
   1.442 -				$src_db = $same_db = false;
   1.443 -
   1.444 -				if ($src_dbms != $dbms || $src_dbhost != $dbhost || $src_dbport != $dbport || $src_dbname != $dbname || $src_dbuser != $dbuser)
   1.445 -				{
   1.446 -					$sql_db = 'dbal_' . $src_dbms;
   1.447 -					$src_db = new $sql_db();
   1.448 -					$src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true);
   1.449 -					$same_db = false;
   1.450 -				}
   1.451 -				else
   1.452 -				{
   1.453 -					$src_db = $db;
   1.454 -					$same_db = true;
   1.455 -				}
   1.456 -
   1.457 -				$src_db->sql_return_on_error(true);
   1.458 -				$db->sql_return_on_error(true);
   1.459 -
   1.460 -				// Try to select one row from the first table to see if the prefix is OK
   1.461 -				$result = $src_db->sql_query_limit('SELECT * FROM ' . $src_table_prefix . $tables[0], 1);
   1.462 -
   1.463 -				if (!$result)
   1.464 -				{
   1.465 -					$prefixes = array();
   1.466 -
   1.467 -					$tables_existing = get_tables($src_db);
   1.468 -					$tables_existing = array_map('strtolower', $tables_existing);
   1.469 -					foreach ($tables_existing as $table_name)
   1.470 -					{
   1.471 -						compare_table($tables, $table_name, $prefixes);
   1.472 -					}
   1.473 -					unset($tables_existing);
   1.474 -
   1.475 -					foreach ($prefixes as $prefix => $count)
   1.476 -					{
   1.477 -						if ($count >= sizeof($tables))
   1.478 -						{
   1.479 -							$possible_prefix = $prefix;
   1.480 -							break;
   1.481 -						}
   1.482 -					}
   1.483 -
   1.484 -					$msg = '';
   1.485 -					if (!empty($convertor_data['table_prefix']))
   1.486 -					{
   1.487 -						$msg .= sprintf($lang['DEFAULT_PREFIX_IS'], $convertor_data['forum_name'], $convertor_data['table_prefix']);
   1.488 -					}
   1.489 -
   1.490 -					if (!empty($possible_prefix))
   1.491 -					{
   1.492 -						$msg .= '<br />';
   1.493 -						$msg .= ($possible_prefix == '*') ? $lang['BLANK_PREFIX_FOUND'] : sprintf($lang['PREFIX_FOUND'], $possible_prefix);
   1.494 -						$src_table_prefix = ($possible_prefix == '*') ? '' : $possible_prefix;
   1.495 -					}
   1.496 -
   1.497 -					$error[] = $msg;
   1.498 -				}
   1.499 -				$src_db->sql_freeresult($result);
   1.500 -				$src_db->sql_return_on_error(false);
   1.501 -			}
   1.502 -
   1.503 -			if (!sizeof($error))
   1.504 -			{
   1.505 -				// Save convertor Status
   1.506 -				set_config('convert_progress', serialize(array(
   1.507 -					'step'			=> '',
   1.508 -					'table_prefix'	=> $src_table_prefix,
   1.509 -					'tag'			=> $convertor_tag,
   1.510 -				)), true);
   1.511 -				set_config('convert_db_server', serialize(array(
   1.512 -					'dbms'			=> $src_dbms,
   1.513 -					'dbhost'		=> $src_dbhost,
   1.514 -					'dbport'		=> $src_dbport,
   1.515 -					'dbname'		=> $src_dbname,
   1.516 -				)), true);
   1.517 -				set_config('convert_db_user', serialize(array(
   1.518 -					'dbuser'		=> $src_dbuser,
   1.519 -					'dbpasswd'		=> $src_dbpasswd,
   1.520 -				)), true);
   1.521 -
   1.522 -				// Save options
   1.523 -				set_config('convert_options', serialize(array('forum_path' => './../' . $forum_path, 'refresh' => $refresh)), true);
   1.524 -
   1.525 -				$template->assign_block_vars('checks', array(
   1.526 -					'TITLE'		=> $lang['VERIFY_OPTIONS'],
   1.527 -					'RESULT'	=> $lang['CONVERT_SETTINGS_VERIFIED'],
   1.528 -				));
   1.529 -
   1.530 -				$template->assign_vars(array(
   1.531 -					'L_SUBMIT'	=> $lang['BEGIN_CONVERT'],
   1.532 -//					'S_HIDDEN'	=> $s_hidden_fields,
   1.533 -					'U_ACTION'	=> $this->p_master->module_url . "?mode={$this->mode}&amp;sub=in_progress&amp;tag=$convertor_tag&amp;language=$language",
   1.534 -				));
   1.535 -
   1.536 -				return;
   1.537 -			}
   1.538 -			else
   1.539 -			{
   1.540 -				$template->assign_block_vars('checks', array(
   1.541 -					'TITLE'		=> $lang['VERIFY_OPTIONS'],
   1.542 -					'RESULT'	=> '<b style="color:red">' . implode('<br />', $error) . '</b>',
   1.543 -				));
   1.544 -			}
   1.545 -		} // end submit
   1.546 -
   1.547 -		foreach ($this->convert_options as $config_key => $vars)
   1.548 -		{
   1.549 -			if (!is_array($vars) && strpos($config_key, 'legend') === false)
   1.550 -			{
   1.551 -				continue;
   1.552 -			}
   1.553 -
   1.554 -			if (strpos($config_key, 'legend') !== false)
   1.555 -			{
   1.556 -				$template->assign_block_vars('options', array(
   1.557 -					'S_LEGEND'		=> true,
   1.558 -					'LEGEND'		=> $lang[$vars])
   1.559 -				);
   1.560 -
   1.561 -				continue;
   1.562 -			}
   1.563 -
   1.564 -			$options = isset($vars['options']) ? $vars['options'] : '';
   1.565 -
   1.566 -			$template->assign_block_vars('options', array(
   1.567 -				'KEY'			=> $config_key,
   1.568 -				'TITLE'			=> $lang[$vars['lang']],
   1.569 -				'S_EXPLAIN'		=> $vars['explain'],
   1.570 -				'S_LEGEND'		=> false,
   1.571 -				'TITLE_EXPLAIN'	=> ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '',
   1.572 -				'CONTENT'		=> $this->p_master->input_field($config_key, $vars['type'], $$config_key, $options),
   1.573 -				)
   1.574 -			);
   1.575 -		}
   1.576 -
   1.577 -		$template->assign_vars(array(
   1.578 -			'TITLE'		=> $lang['STAGE_SETTINGS'],
   1.579 -			'BODY'		=> $lang['CONV_OPTIONS_BODY'],
   1.580 -			'L_SUBMIT'	=> $lang['BEGIN_CONVERT'],
   1.581 -			'U_ACTION'	=> $this->p_master->module_url . "?mode={$this->mode}&amp;sub=settings&amp;tag=$convertor_tag&amp;language=$language",
   1.582 -		));
   1.583 -	}
   1.584 -
   1.585 -	/**
   1.586 -	* The function which does the actual work (or dispatches it to the relevant places)
   1.587 -	*/
   1.588 -	function convert_data($sub)
   1.589 -	{
   1.590 -		global $template, $user, $phpbb_root_path, $phpEx, $db, $lang, $config, $cache;
   1.591 -		global $convert, $convert_row, $message_parser, $skip_rows, $language;
   1.592 -
   1.593 -		require($phpbb_root_path . 'config.' . $phpEx);
   1.594 -		require($phpbb_root_path . 'includes/constants.' . $phpEx);
   1.595 -		require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
   1.596 -		require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
   1.597 -
   1.598 -		$db = new $sql_db();
   1.599 -		$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
   1.600 -		unset($dbpasswd);
   1.601 -
   1.602 -		$sql = 'SELECT *
   1.603 -			FROM ' . CONFIG_TABLE;
   1.604 -		$result = $db->sql_query($sql);
   1.605 -
   1.606 -		$config = array();
   1.607 -		while ($row = $db->sql_fetchrow($result))
   1.608 -		{
   1.609 -			$config[$row['config_name']] = $row['config_value'];
   1.610 -		}
   1.611 -		$db->sql_freeresult($result);
   1.612 -
   1.613 -		// Override a couple of config variables for the duration
   1.614 -		$config['max_quote_depth'] = 0;
   1.615 -
   1.616 -		// @todo Need to confirm that max post length in source is <= max post length in destination or there may be interesting formatting issues
   1.617 -		$config['max_post_chars'] = $config['min_post_chars'] = 0;
   1.618 -
   1.619 -		// Set up a user as well. We _should_ have enough of a database here at this point to do this
   1.620 -		// and it helps for any core code we call
   1.621 -		$user->session_begin();
   1.622 -		$user->page = $user->extract_current_page($phpbb_root_path);
   1.623 -
   1.624 -		// This is a little bit of a fudge, but it allows the language entries to be available to the
   1.625 -		// core code without us loading them again
   1.626 -		$user->lang = &$lang;
   1.627 -
   1.628 -		$this->page_title = $user->lang['STAGE_IN_PROGRESS'];
   1.629 -
   1.630 -		$convert->options = array();
   1.631 -		if (isset($config['convert_progress']))
   1.632 -		{
   1.633 -			$convert->options = unserialize($config['convert_progress']);
   1.634 -			$convert->options = array_merge($convert->options, unserialize($config['convert_db_server']), unserialize($config['convert_db_user']), unserialize($config['convert_options']));
   1.635 -		}
   1.636 -
   1.637 -		// This information should have already been checked once, but do it again for safety
   1.638 -		if (empty($convert->options) || empty($convert->options['tag']) ||
   1.639 -			!isset($convert->options['dbms']) ||
   1.640 -			!isset($convert->options['dbhost']) ||
   1.641 -			!isset($convert->options['dbport']) ||
   1.642 -			!isset($convert->options['dbuser']) ||
   1.643 -			!isset($convert->options['dbpasswd']) ||
   1.644 -			!isset($convert->options['dbname']) ||
   1.645 -			!isset($convert->options['table_prefix']))
   1.646 -		{
   1.647 -			$this->p_master->error($user->lang['NO_CONVERT_SPECIFIED'], __LINE__, __FILE__);
   1.648 -		}
   1.649 -
   1.650 -		// Make some short variables accessible, for easier referencing
   1.651 -		$convert->convertor_tag = basename($convert->options['tag']);
   1.652 -		$convert->src_dbms = $convert->options['dbms'];
   1.653 -		$convert->src_dbhost = $convert->options['dbhost'];
   1.654 -		$convert->src_dbport = $convert->options['dbport'];
   1.655 -		$convert->src_dbuser = $convert->options['dbuser'];
   1.656 -		$convert->src_dbpasswd = $convert->options['dbpasswd'];
   1.657 -		$convert->src_dbname = $convert->options['dbname'];
   1.658 -		$convert->src_table_prefix = $convert->options['table_prefix'];
   1.659 -
   1.660 -		// initiate database connection to old db if old and new db differ
   1.661 -		global $src_db, $same_db;
   1.662 -		$src_db = $same_db = null;
   1.663 -		if ($convert->src_dbms != $dbms || $convert->src_dbhost != $dbhost || $convert->src_dbport != $dbport || $convert->src_dbname != $dbname || $convert->src_dbuser != $dbuser)
   1.664 -		{
   1.665 -			if ($convert->src_dbms != $dbms)
   1.666 -			{
   1.667 -				require($phpbb_root_path . 'includes/db/' . $convert->src_dbms . '.' . $phpEx);
   1.668 -			}
   1.669 -			$sql_db = 'dbal_' . $convert->src_dbms;
   1.670 -			$src_db = new $sql_db();
   1.671 -			$src_db->sql_connect($convert->src_dbhost, $convert->src_dbuser, htmlspecialchars_decode($convert->src_dbpasswd), $convert->src_dbname, $convert->src_dbport, false, true);
   1.672 -			$same_db = false;
   1.673 -		}
   1.674 -		else
   1.675 -		{
   1.676 -			$src_db = $db;
   1.677 -			$same_db = true;
   1.678 -		}
   1.679 -
   1.680 -		$convert->mysql_convert = false;
   1.681 -		switch ($src_db->sql_layer)
   1.682 -		{
   1.683 -			case 'sqlite':
   1.684 -			case 'firebird':
   1.685 -				$convert->src_truncate_statement = 'DELETE FROM ';
   1.686 -			break;
   1.687 -
   1.688 -			// Thanks MySQL, for silently converting...
   1.689 -			case 'mysql':
   1.690 -			case 'mysql4':
   1.691 -				if (version_compare($src_db->sql_server_info(true, false), '4.1.3', '>='))
   1.692 -				{
   1.693 -					$convert->mysql_convert = true;
   1.694 -				}
   1.695 -				$convert->src_truncate_statement = 'TRUNCATE TABLE ';
   1.696 -			break;
   1.697 -
   1.698 -			case 'mysqli':
   1.699 -				$convert->mysql_convert = true;
   1.700 -				$convert->src_truncate_statement = 'TRUNCATE TABLE ';
   1.701 -			break;
   1.702 -
   1.703 -			default:
   1.704 -				$convert->src_truncate_statement = 'TRUNCATE TABLE ';
   1.705 -			break;
   1.706 -		}
   1.707 -
   1.708 -		if ($convert->mysql_convert && !$same_db)
   1.709 -		{
   1.710 -			$src_db->sql_query("SET NAMES 'binary'");
   1.711 -		}
   1.712 -
   1.713 -		switch ($db->sql_layer)
   1.714 -		{
   1.715 -			case 'sqlite':
   1.716 -			case 'firebird':
   1.717 -				$convert->truncate_statement = 'DELETE FROM ';
   1.718 -			break;
   1.719 -
   1.720 -			default:
   1.721 -				$convert->truncate_statement = 'TRUNCATE TABLE ';
   1.722 -			break;
   1.723 -		}
   1.724 -
   1.725 -		$get_info = false;
   1.726 -
   1.727 -		// check security implications of direct inclusion
   1.728 -		if (!file_exists('./convertors/convert_' . $convert->convertor_tag . '.' . $phpEx))
   1.729 -		{
   1.730 -			$this->p_master->error($user->lang['CONVERT_NOT_EXIST'], __LINE__, __FILE__);
   1.731 -		}
   1.732 -
   1.733 -		if (file_exists('./convertors/functions_' . $convert->convertor_tag . '.' . $phpEx))
   1.734 -		{
   1.735 -			include('./convertors/functions_' . $convert->convertor_tag . '.' . $phpEx);
   1.736 -		}
   1.737 -
   1.738 -		$get_info = true;
   1.739 -		include('./convertors/convert_' . $convert->convertor_tag . '.' . $phpEx);
   1.740 -
   1.741 -		// Map some variables...
   1.742 -		$convert->convertor_data = $convertor_data;
   1.743 -		$convert->tables = $tables;
   1.744 -		$convert->config_schema = $config_schema;
   1.745 -
   1.746 -		// Now include the real data
   1.747 -		$get_info = false;
   1.748 -		include('./convertors/convert_' . $convert->convertor_tag . '.' . $phpEx);
   1.749 -
   1.750 -		$convert->convertor_data = $convertor_data;
   1.751 -		$convert->tables = $tables;
   1.752 -		$convert->config_schema = $config_schema;
   1.753 -		$convert->convertor = $convertor;
   1.754 -
   1.755 -		// The test_file is a file that should be present in the location of the old board.
   1.756 -		if (!file_exists($convert->options['forum_path'] . '/' . $test_file))
   1.757 -		{
   1.758 -			$this->p_master->error(sprintf($user->lang['COULD_NOT_FIND_PATH'], $convert->options['forum_path']), __LINE__, __FILE__);
   1.759 -		}
   1.760 -
   1.761 -		$search_type = basename(trim($config['search_type']));
   1.762 -
   1.763 -		// For conversions we are a bit less strict and set to a search backend we know exist...
   1.764 -		if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
   1.765 -		{
   1.766 -			$search_type = 'fulltext_native';
   1.767 -			set_config('search_type', $search_type);
   1.768 -		}
   1.769 -
   1.770 -		if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
   1.771 -		{
   1.772 -			trigger_error('NO_SUCH_SEARCH_MODULE');
   1.773 -		}
   1.774 -
   1.775 -		require($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx);
   1.776 -
   1.777 -		$error = false;
   1.778 -		$convert->fulltext_search = new $search_type($error);
   1.779 -
   1.780 -		if ($error)
   1.781 -		{
   1.782 -			trigger_error($error);
   1.783 -		}
   1.784 -
   1.785 -		include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
   1.786 -		$message_parser = new parse_message();
   1.787 -
   1.788 -		$jump = request_var('jump', 0);
   1.789 -		$final_jump = request_var('final_jump', 0);
   1.790 -		$sync_batch = request_var('sync_batch', -1);
   1.791 -		$last_statement = request_var('last', 0);
   1.792 -
   1.793 -		// We are running sync...
   1.794 -		if ($sync_batch >= 0)
   1.795 -		{
   1.796 -			$this->sync_forums($sync_batch);
   1.797 -			return;
   1.798 -		}
   1.799 -
   1.800 -		if ($jump)
   1.801 -		{
   1.802 -			$this->jump($jump, $last_statement);
   1.803 -			return;
   1.804 -		}
   1.805 -
   1.806 -		if ($final_jump)
   1.807 -		{
   1.808 -			$this->final_jump($final_jump);
   1.809 -			return;
   1.810 -		}
   1.811 -
   1.812 -		$current_table = request_var('current_table', 0);
   1.813 -		$old_current_table = min(-1, $current_table - 1);
   1.814 -		$skip_rows = request_var('skip_rows', 0);
   1.815 -
   1.816 -		if (!$current_table && !$skip_rows)
   1.817 -		{
   1.818 -			if (empty($_REQUEST['confirm']))
   1.819 -			{
   1.820 -				// If avatars / ranks / smilies folders are specified make sure they are writable
   1.821 -				$bad_folders = array();
   1.822 -
   1.823 -				$local_paths = array(
   1.824 -					'avatar_path'			=> path($config['avatar_path']),
   1.825 -					'avatar_gallery_path'	=> path($config['avatar_gallery_path']),
   1.826 -					'icons_path'			=> path($config['icons_path']),
   1.827 -					'ranks_path'			=> path($config['ranks_path']),
   1.828 -					'smilies_path'			=> path($config['smilies_path'])
   1.829 -				);
   1.830 -
   1.831 -				foreach ($local_paths as $folder => $local_path)
   1.832 -				{
   1.833 -					if (isset($convert->convertor[$folder]))
   1.834 -					{
   1.835 -						if (empty($convert->convertor['test_file']))
   1.836 -						{
   1.837 -							// test_file is mandantory at the moment so this should never be reached, but just in case...
   1.838 -							$this->p_master->error($user->lang['DEV_NO_TEST_FILE'], __LINE__, __FILE__);
   1.839 -						}
   1.840 -
   1.841 -						if (!$local_path || !phpbb_is_writable($phpbb_root_path . $local_path))
   1.842 -						{
   1.843 -							if (!$local_path)
   1.844 -							{
   1.845 -								$bad_folders[] = sprintf($user->lang['CONFIG_PHPBB_EMPTY'], $folder);
   1.846 -							}
   1.847 -							else
   1.848 -							{
   1.849 -								$bad_folders[] = $local_path;
   1.850 -							}
   1.851 -						}
   1.852 -					}
   1.853 -				}
   1.854 -
   1.855 -				if (sizeof($bad_folders))
   1.856 -				{
   1.857 -					$msg = (sizeof($bad_folders) == 1) ? $user->lang['MAKE_FOLDER_WRITABLE'] : $user->lang['MAKE_FOLDERS_WRITABLE'];
   1.858 -					sort($bad_folders);
   1.859 -					$this->p_master->error(sprintf($msg, implode('<br />', $bad_folders)), __LINE__, __FILE__, true);
   1.860 -
   1.861 -					$template->assign_vars(array(
   1.862 -						'L_SUBMIT'	=> $user->lang['INSTALL_TEST'],
   1.863 -						'U_ACTION'	=> $this->p_master->module_url . "?mode={$this->mode}&amp;sub=in_progress&amp;tag={$convert->convertor_tag}&amp;language=$language",
   1.864 -					));
   1.865 -					return;
   1.866 -				}
   1.867 -
   1.868 -				// Grab all the tables used in convertor
   1.869 -				$missing_tables = $tables_list = $aliases = array();
   1.870 -
   1.871 -				foreach ($convert->convertor['schema'] as $schema)
   1.872 -				{
   1.873 -					// Skip those not used (because of addons/plugins not detected)
   1.874 -					if (!$schema['target'])
   1.875 -					{
   1.876 -						continue;
   1.877 -					}
   1.878 -
   1.879 -					foreach ($schema as $key => $val)
   1.880 -					{
   1.881 -						// we're dealing with an array like:
   1.882 -						// array('forum_status',			'forums.forum_status',				'is_item_locked')
   1.883 -						if (is_int($key) && !empty($val[1]))
   1.884 -						{
   1.885 -							$temp_data = $val[1];
   1.886 -							if (!is_array($temp_data))
   1.887 -							{
   1.888 -								$temp_data = array($temp_data);
   1.889 -							}
   1.890 -
   1.891 -							foreach ($temp_data as $val)
   1.892 -							{
   1.893 -								if (preg_match('/([a-z0-9_]+)\.([a-z0-9_]+)\)* ?A?S? ?([a-z0-9_]*?)\.?([a-z0-9_]*)$/i', $val, $m))
   1.894 -								{
   1.895 -									$table = $convert->src_table_prefix . $m[1];
   1.896 -									$tables_list[$table] = $table;
   1.897 -
   1.898 -									if (!empty($m[3]))
   1.899 -									{
   1.900 -										$aliases[] = $convert->src_table_prefix . $m[3];
   1.901 -									}
   1.902 -								}
   1.903 -							}
   1.904 -						}
   1.905 -						// 'left_join'		=> 'topics LEFT JOIN vote_desc ON topics.topic_id = vote_desc.topic_id AND topics.topic_vote = 1'
   1.906 -						else if ($key == 'left_join')
   1.907 -						{
   1.908 -							// Convert the value if it wasn't an array already.
   1.909 -							if (!is_array($val))
   1.910 -							{
   1.911 -								$val = array($val);
   1.912 -							}
   1.913 -
   1.914 -							for ($j = 0; $j < sizeof($val); ++$j)
   1.915 -							{
   1.916 -								if (preg_match('/LEFT JOIN ([a-z0-9_]+) AS ([a-z0-9_]+)/i', $val[$j], $m))
   1.917 -								{
   1.918 -									$table = $convert->src_table_prefix . $m[1];
   1.919 -									$tables_list[$table] = $table;
   1.920 -
   1.921 -									if (!empty($m[2]))
   1.922 -									{
   1.923 -										$aliases[] = $convert->src_table_prefix . $m[2];
   1.924 -									}
   1.925 -								}
   1.926 -							}
   1.927 -						}
   1.928 -					}
   1.929 -				}
   1.930 -
   1.931 -				// Remove aliased tables from $tables_list
   1.932 -				foreach ($aliases as $alias)
   1.933 -				{
   1.934 -					unset($tables_list[$alias]);
   1.935 -				}
   1.936 -
   1.937 -				// Check if the tables that we need exist
   1.938 -				$src_db->sql_return_on_error(true);
   1.939 -				foreach ($tables_list as $table => $null)
   1.940 -				{
   1.941 -					$sql = 'SELECT 1 FROM ' . $table;
   1.942 -					$_result = $src_db->sql_query_limit($sql, 1);
   1.943 -
   1.944 -					if (!$_result)
   1.945 -					{
   1.946 -						$missing_tables[] = $table;
   1.947 -					}
   1.948 -					$src_db->sql_freeresult($_result);
   1.949 -				}
   1.950 -				$src_db->sql_return_on_error(false);
   1.951 -
   1.952 -				// Throw an error if some tables are missing
   1.953 -				// We used to do some guessing here, but since we have a suggestion of possible values earlier, I don't see it adding anything here to do it again
   1.954 -
   1.955 -				if (sizeof($missing_tables) == sizeof($tables_list))
   1.956 -				{
   1.957 -					$this->p_master->error($user->lang['NO_TABLES_FOUND'] . ' ' . $user->lang['CHECK_TABLE_PREFIX'], __LINE__, __FILE__);
   1.958 -				}
   1.959 -				else if (sizeof($missing_tables))
   1.960 -				{
   1.961 -					$this->p_master->error(sprintf($user->lang['TABLES_MISSING'], implode(', ', $missing_tables)) . '<br /><br />' . $user->lang['CHECK_TABLE_PREFIX'], __LINE__, __FILE__);
   1.962 -				}
   1.963 -
   1.964 -				$url = $this->save_convert_progress('&amp;confirm=1');
   1.965 -				$msg = $user->lang['PRE_CONVERT_COMPLETE'];
   1.966 -
   1.967 -				if ($convert->convertor_data['author_notes'])
   1.968 -				{
   1.969 -					$msg .= '</p><p>' . sprintf($user->lang['AUTHOR_NOTES'], $convert->convertor_data['author_notes']);
   1.970 -				}
   1.971 -
   1.972 -				$template->assign_vars(array(
   1.973 -					'L_SUBMIT'		=> $user->lang['CONTINUE_CONVERT'],
   1.974 -					'L_MESSAGE'		=> $msg,
   1.975 -					'U_ACTION'		=> $url,
   1.976 -				));
   1.977 -
   1.978 -				return;
   1.979 -			} // if (empty($_REQUEST['confirm']))
   1.980 -
   1.981 -			$template->assign_block_vars('checks', array(
   1.982 -				'S_LEGEND'		=> true,
   1.983 -				'LEGEND'		=> $user->lang['STARTING_CONVERT'],
   1.984 -			));
   1.985 -
   1.986 -			// Convert the config table and load the settings of the old board
   1.987 -			if (!empty($convert->config_schema))
   1.988 -			{
   1.989 -				restore_config($convert->config_schema);
   1.990 -
   1.991 -				// Override a couple of config variables for the duration
   1.992 -				$config['max_quote_depth'] = 0;
   1.993 -
   1.994 -				// @todo Need to confirm that max post length in source is <= max post length in destination or there may be interesting formatting issues
   1.995 -				$config['max_post_chars'] = $config['min_post_chars'] = 0;
   1.996 -			}
   1.997 -
   1.998 -			$template->assign_block_vars('checks', array(
   1.999 -				'TITLE'		=> $user->lang['CONFIG_CONVERT'],
  1.1000 -				'RESULT'	=> $user->lang['DONE'],
  1.1001 -			));
  1.1002 -
  1.1003 -			// Now process queries and execute functions that have to be executed prior to the conversion
  1.1004 -			if (!empty($convert->convertor['execute_first']))
  1.1005 -			{
  1.1006 -				eval($convert->convertor['execute_first']);
  1.1007 -			}
  1.1008 -
  1.1009 -			if (!empty($convert->convertor['query_first']))
  1.1010 -			{
  1.1011 -				if (!is_array($convert->convertor['query_first']))
  1.1012 -				{
  1.1013 -					$convert->convertor['query_first'] = array('target', array($convert->convertor['query_first']));
  1.1014 -				}
  1.1015 -				else if (!is_array($convert->convertor['query_first'][0]))
  1.1016 -				{
  1.1017 -					$convert->convertor['query_first'] = array(array($convert->convertor['query_first'][0], $convert->convertor['query_first'][1]));
  1.1018 -				}
  1.1019 -
  1.1020 -				foreach ($convert->convertor['query_first'] as $query_first)
  1.1021 -				{
  1.1022 -					if ($query_first[0] == 'src')
  1.1023 -					{
  1.1024 -						if ($convert->mysql_convert && $same_db)
  1.1025 -						{
  1.1026 -							$src_db->sql_query("SET NAMES 'binary'");
  1.1027 -						}
  1.1028 -
  1.1029 -						$src_db->sql_query($query_first[1]);
  1.1030 -
  1.1031 -						if ($convert->mysql_convert && $same_db)
  1.1032 -						{
  1.1033 -							$src_db->sql_query("SET NAMES 'utf8'");
  1.1034 -						}
  1.1035 -					}
  1.1036 -					else
  1.1037 -					{
  1.1038 -						$db->sql_query($query_first[1]);
  1.1039 -					}
  1.1040 -				}
  1.1041 -			}
  1.1042 -
  1.1043 -			$template->assign_block_vars('checks', array(
  1.1044 -				'TITLE'		=> $user->lang['PREPROCESS_STEP'],
  1.1045 -				'RESULT'	=> $user->lang['DONE'],
  1.1046 -			));
  1.1047 -		} // if (!$current_table && !$skip_rows)
  1.1048 -
  1.1049 -		$template->assign_block_vars('checks', array(
  1.1050 -			'S_LEGEND'		=> true,
  1.1051 -			'LEGEND'		=> $user->lang['FILLING_TABLES'],
  1.1052 -		));
  1.1053 -
  1.1054 -		// This loop takes one target table and processes it
  1.1055 -		while ($current_table < sizeof($convert->convertor['schema']))
  1.1056 -		{
  1.1057 -			$schema = $convert->convertor['schema'][$current_table];
  1.1058 -
  1.1059 -			// The target table isn't set, this can be because a module (for example the attachement mod) is taking care of this.
  1.1060 -			if (empty($schema['target']))
  1.1061 -			{
  1.1062 -				$current_table++;
  1.1063 -				continue;
  1.1064 -			}
  1.1065 -
  1.1066 -			$template->assign_block_vars('checks', array(
  1.1067 -				'TITLE'	=> sprintf($user->lang['FILLING_TABLE'], $schema['target']),
  1.1068 -			));
  1.1069 -
  1.1070 -			// This is only the case when we first start working on the tables.
  1.1071 -			if (!$skip_rows)
  1.1072 -			{
  1.1073 -				// process execute_first and query_first for this table...
  1.1074 -				if (!empty($schema['execute_first']))
  1.1075 -				{
  1.1076 -					eval($schema['execute_first']);
  1.1077 -				}
  1.1078 -
  1.1079 -				if (!empty($schema['query_first']))
  1.1080 -				{
  1.1081 -					if (!is_array($schema['query_first']))
  1.1082 -					{
  1.1083 -						$schema['query_first'] = array('target', array($schema['query_first']));
  1.1084 -					}
  1.1085 -					else if (!is_array($schema['query_first'][0]))
  1.1086 -					{
  1.1087 -						$schema['query_first'] = array(array($schema['query_first'][0], $schema['query_first'][1]));
  1.1088 -					}
  1.1089 -
  1.1090 -					foreach ($schema['query_first'] as $query_first)
  1.1091 -					{
  1.1092 -						if ($query_first[0] == 'src')
  1.1093 -						{
  1.1094 -							if ($convert->mysql_convert && $same_db)
  1.1095 -							{
  1.1096 -								$src_db->sql_query("SET NAMES 'binary'");
  1.1097 -							}
  1.1098 -							$src_db->sql_query($query_first[1]);
  1.1099 -							if ($convert->mysql_convert && $same_db)
  1.1100 -							{
  1.1101 -								$src_db->sql_query("SET NAMES 'utf8'");
  1.1102 -							}
  1.1103 -						}
  1.1104 -						else
  1.1105 -						{
  1.1106 -							$db->sql_query($query_first[1]);
  1.1107 -						}
  1.1108 -					}
  1.1109 -				}
  1.1110 -
  1.1111 -				if (!empty($schema['autoincrement']))
  1.1112 -				{
  1.1113 -					switch ($db->sql_layer)
  1.1114 -					{
  1.1115 -						case 'postgres':
  1.1116 -							$db->sql_query("SELECT SETVAL('" . $schema['target'] . "_seq',(select case when max(" . $schema['autoincrement'] . ")>0 then max(" . $schema['autoincrement'] . ")+1 else 1 end from " . $schema['target'] . '));');
  1.1117 -						break;
  1.1118 -
  1.1119 -						case 'oracle':
  1.1120 -							$result = $db->sql_query('SELECT MAX(' . $schema['autoincrement'] . ') as max_id FROM ' . $schema['target']);
  1.1121 -							$row = $db->sql_fetchrow($result);
  1.1122 -							$db->sql_freeresult($result);
  1.1123 -
  1.1124 -							$largest_id = (int) $row['max_id'];
  1.1125 -
  1.1126 -							if ($largest_id)
  1.1127 -							{
  1.1128 -								$db->sql_query('DROP SEQUENCE ' . $schema['target'] . '_seq');
  1.1129 -								$db->sql_query('CREATE SEQUENCE ' . $schema['target'] . '_seq START WITH ' . ($largest_id + 1));
  1.1130 -							}
  1.1131 -						break;
  1.1132 -					}
  1.1133 -				}
  1.1134 -			}
  1.1135 -
  1.1136 -			// Process execute_always for this table
  1.1137 -			// This is for code which needs to be executed on every pass of this table if
  1.1138 -			// it gets split because of time restrictions
  1.1139 -			if (!empty($schema['execute_always']))
  1.1140 -			{
  1.1141 -				eval($schema['execute_always']);
  1.1142 -			}
  1.1143 -
  1.1144 -			//
  1.1145 -			// Set up some variables
  1.1146 -			//
  1.1147 -			// $waiting_rows	holds rows for multirows insertion (MySQL only)
  1.1148 -			// $src_tables		holds unique tables with aliases to select from
  1.1149 -			// $src_fields		will quickly refer source fields (or aliases) corresponding to the current index
  1.1150 -			// $select_fields	holds the names of the fields to retrieve
  1.1151 -			//
  1.1152 -
  1.1153 -			$sql_data = array(
  1.1154 -				'source_fields'		=> array(),
  1.1155 -				'target_fields'		=> array(),
  1.1156 -				'source_tables'		=> array(),
  1.1157 -				'select_fields'		=> array(),
  1.1158 -			);
  1.1159 -
  1.1160 -			// This statement is building the keys for later insertion.
  1.1161 -			$insert_query = $this->build_insert_query($schema, $sql_data, $current_table);
  1.1162 -
  1.1163 -			// If no source table is affected, we skip the table
  1.1164 -			if (empty($sql_data['source_tables']))
  1.1165 -			{
  1.1166 -				$skip_rows = 0;
  1.1167 -				$current_table++;
  1.1168 -				continue;
  1.1169 -			}
  1.1170 -
  1.1171 -			$distinct = (!empty($schema['distinct'])) ? 'DISTINCT ' : '';
  1.1172 -
  1.1173 -			$sql = 'SELECT ' . $distinct . implode(', ', $sql_data['select_fields']) . " \nFROM " . implode(', ', $sql_data['source_tables']);
  1.1174 -
  1.1175 -			// Where
  1.1176 -			$sql .= (!empty($schema['where'])) ? "\nWHERE (" . $schema['where'] . ')' : '';
  1.1177 -
  1.1178 -			// Group By
  1.1179 -			if (!empty($schema['group_by']))
  1.1180 -			{
  1.1181 -				$schema['group_by'] = array($schema['group_by']);
  1.1182 -				foreach ($sql_data['select_fields'] as $select)
  1.1183 -				{
  1.1184 -					$alias = strpos(strtolower($select), ' as ');
  1.1185 -					$select = ($alias) ? substr($select, 0, $alias) : $select;
  1.1186 -					if (!in_array($select, $schema['group_by']))
  1.1187 -					{
  1.1188 -						$schema['group_by'][] = $select;
  1.1189 -					}
  1.1190 -				}
  1.1191 -			}
  1.1192 -			$sql .= (!empty($schema['group_by'])) ? "\nGROUP BY " . implode(', ', $schema['group_by']) : '';
  1.1193 -
  1.1194 -			// Having
  1.1195 -			$sql .= (!empty($schema['having'])) ? "\nHAVING " . $schema['having'] : '';
  1.1196 -
  1.1197 -			// Order By
  1.1198 -			if (empty($schema['order_by']) && !empty($schema['primary']))
  1.1199 -			{
  1.1200 -				$schema['order_by'] = $schema['primary'];
  1.1201 -			}
  1.1202 -			$sql .= (!empty($schema['order_by'])) ? "\nORDER BY " . $schema['order_by'] : '';
  1.1203 -
  1.1204 -			// Counting basically holds the amount of rows processed.
  1.1205 -			$counting = -1;
  1.1206 -			$batch_time = 0;
  1.1207 -
  1.1208 -			while ($counting === -1 || ($counting >= $convert->batch_size && still_on_time()))
  1.1209 -			{
  1.1210 -				$old_current_table = $current_table;
  1.1211 -
  1.1212 -				$rows = '';
  1.1213 -				$waiting_rows = array();
  1.1214 -
  1.1215 -				if (!empty($batch_time))
  1.1216 -				{
  1.1217 -					$mtime = explode(' ', microtime());
  1.1218 -					$mtime = $mtime[0] + $mtime[1];
  1.1219 -					$rows = ceil($counting/($mtime - $batch_time)) . " rows/s ($counting rows) | ";
  1.1220 -				}
  1.1221 -
  1.1222 -				$template->assign_block_vars('checks', array(
  1.1223 -					'TITLE'		=> "skip_rows = $skip_rows",
  1.1224 -					'RESULT'	=> $rows . ((defined('DEBUG_EXTRA') && function_exists('memory_get_usage')) ? ceil(memory_get_usage()/1024) . ' ' . $user->lang['KIB'] : ''),
  1.1225 -				));
  1.1226 -
  1.1227 -				$mtime = explode(' ', microtime());
  1.1228 -				$batch_time = $mtime[0] + $mtime[1];
  1.1229 -
  1.1230 -				if ($convert->mysql_convert && $same_db)
  1.1231 -				{
  1.1232 -					$src_db->sql_query("SET NAMES 'binary'");
  1.1233 -				}
  1.1234 -
  1.1235 -				// Take skip rows into account and only fetch batch_size amount of rows
  1.1236 -				$___result = $src_db->sql_query_limit($sql, $convert->batch_size, $skip_rows);
  1.1237 -
  1.1238 -				if ($convert->mysql_convert && $same_db)
  1.1239 -				{
  1.1240 -					$src_db->sql_query("SET NAMES 'utf8'");
  1.1241 -				}
  1.1242 -
  1.1243 -				// This loop processes each row
  1.1244 -				$counting = 0;
  1.1245 -
  1.1246 -				$convert->row = $convert_row = array();
  1.1247 -
  1.1248 -				if (!empty($schema['autoincrement']))
  1.1249 -				{
  1.1250 -					switch ($db->sql_layer)
  1.1251 -					{
  1.1252 -						case 'mssql':
  1.1253 -						case 'mssql_odbc':
  1.1254 -						case 'mssqlnative':
  1.1255 -							$db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' ON');
  1.1256 -						break;
  1.1257 -					}
  1.1258 -				}
  1.1259 -
  1.1260 -				// Now handle the rows until time is over or no more rows to process...
  1.1261 -				while ($counting === 0 || still_on_time())
  1.1262 -				{
  1.1263 -					$convert_row = $src_db->sql_fetchrow($___result);
  1.1264 -
  1.1265 -					if (!$convert_row)
  1.1266 -					{
  1.1267 -						// move to the next batch or table
  1.1268 -						break;
  1.1269 -					}
  1.1270 -
  1.1271 -					// With this we are able to always save the last state
  1.1272 -					$convert->row = $convert_row;
  1.1273 -
  1.1274 -					// Increment the counting variable, it stores the number of rows we have processed
  1.1275 -					$counting++;
  1.1276 -
  1.1277 -					$insert_values = array();
  1.1278 -
  1.1279 -					$sql_flag = $this->process_row($schema, $sql_data, $insert_values);
  1.1280 -
  1.1281 -					if ($sql_flag === true)
  1.1282 -					{
  1.1283 -						switch ($db->sql_layer)
  1.1284 -						{
  1.1285 -							// If MySQL, we'll wait to have num_wait_rows rows to submit at once
  1.1286 -							case 'mysql':
  1.1287 -							case 'mysql4':
  1.1288 -							case 'mysqli':
  1.1289 -								$waiting_rows[] = '(' . implode(', ', $insert_values) . ')';
  1.1290 -
  1.1291 -								if (sizeof($waiting_rows) >= $convert->num_wait_rows)
  1.1292 -								{
  1.1293 -									$errored = false;
  1.1294 -
  1.1295 -									$db->sql_return_on_error(true);
  1.1296 -
  1.1297 -									if (!$db->sql_query($insert_query . implode(', ', $waiting_rows)))
  1.1298 -									{
  1.1299 -										$errored = true;
  1.1300 -									}
  1.1301 -									$db->sql_return_on_error(false);
  1.1302 -
  1.1303 -									if ($errored)
  1.1304 -									{
  1.1305 -										$db->sql_return_on_error(true);
  1.1306 -
  1.1307 -										// Because it errored out we will try to insert the rows one by one... most of the time this
  1.1308 -										// is caused by duplicate entries - but we also do not want to miss one...
  1.1309 -										foreach ($waiting_rows as $waiting_sql)
  1.1310 -										{
  1.1311 -											if (!$db->sql_query($insert_query . $waiting_sql))
  1.1312 -											{
  1.1313 -												$this->p_master->db_error($user->lang['DB_ERR_INSERT'], htmlspecialchars($insert_query . $waiting_sql) . '<br /><br />' . htmlspecialchars(print_r($db->_sql_error(), true)), __LINE__, __FILE__, true);
  1.1314 -											}
  1.1315 -										}
  1.1316 -
  1.1317 -										$db->sql_return_on_error(false);
  1.1318 -									}
  1.1319 -
  1.1320 -									$waiting_rows = array();
  1.1321 -								}
  1.1322 -
  1.1323 -							break;
  1.1324 -
  1.1325 -							default:
  1.1326 -								$insert_sql = $insert_query . '(' . implode(', ', $insert_values) . ')';
  1.1327 -
  1.1328 -								$db->sql_return_on_error(true);
  1.1329 -
  1.1330 -								if (!$db->sql_query($insert_sql))
  1.1331 -								{
  1.1332 -									$this->p_master->db_error($user->lang['DB_ERR_INSERT'], htmlspecialchars($insert_sql) . '<br /><br />' . htmlspecialchars(print_r($db->_sql_error(), true)), __LINE__, __FILE__, true);
  1.1333 -								}
  1.1334 -								$db->sql_return_on_error(false);
  1.1335 -
  1.1336 -								$waiting_rows = array();
  1.1337 -
  1.1338 -							break;
  1.1339 -						}
  1.1340 -					}
  1.1341 -
  1.1342 -					$skip_rows++;
  1.1343 -				}
  1.1344 -				$src_db->sql_freeresult($___result);
  1.1345 -
  1.1346 -				// We might still have some rows waiting
  1.1347 -				if (sizeof($waiting_rows))
  1.1348 -				{
  1.1349 -					$errored = false;
  1.1350 -					$db->sql_return_on_error(true);
  1.1351 -
  1.1352 -					if (!$db->sql_query($insert_query . implode(', ', $waiting_rows)))
  1.1353 -					{
  1.1354 -						$errored = true;
  1.1355 -					}
  1.1356 -					$db->sql_return_on_error(false);
  1.1357 -
  1.1358 -					if ($errored)
  1.1359 -					{
  1.1360 -						$db->sql_return_on_error(true);
  1.1361 -
  1.1362 -						// Because it errored out we will try to insert the rows one by one... most of the time this
  1.1363 -						// is caused by duplicate entries - but we also do not want to miss one...
  1.1364 -						foreach ($waiting_rows as $waiting_sql)
  1.1365 -						{
  1.1366 -							$db->sql_query($insert_query . $waiting_sql);
  1.1367 -							$this->p_master->db_error($user->lang['DB_ERR_INSERT'], htmlspecialchars($insert_query . $waiting_sql) . '<br /><br />' . htmlspecialchars(print_r($db->_sql_error(), true)), __LINE__, __FILE__, true);
  1.1368 -						}
  1.1369 -
  1.1370 -						$db->sql_return_on_error(false);
  1.1371 -					}
  1.1372 -
  1.1373 -					$waiting_rows = array();
  1.1374 -				}
  1.1375 -
  1.1376 -				if (!empty($schema['autoincrement']))
  1.1377 -				{
  1.1378 -					switch ($db->sql_layer)
  1.1379 -					{
  1.1380 -						case 'mssql':
  1.1381 -						case 'mssql_odbc':
  1.1382 -						case 'mssqlnative':
  1.1383 -							$db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' OFF');
  1.1384 -						break;
  1.1385 -
  1.1386 -						case 'postgres':
  1.1387 -							$db->sql_query("SELECT SETVAL('" . $schema['target'] . "_seq',(select case when max(" . $schema['autoincrement'] . ")>0 then max(" . $schema['autoincrement'] . ")+1 else 1 end from " . $schema['target'] . '));');
  1.1388 -						break;
  1.1389 -
  1.1390 -						case 'oracle':
  1.1391 -							$result = $db->sql_query('SELECT MAX(' . $schema['autoincrement'] . ') as max_id FROM ' . $schema['target']);
  1.1392 -							$row = $db->sql_fetchrow($result);
  1.1393 -							$db->sql_freeresult($result);
  1.1394 -
  1.1395 -							$largest_id = (int) $row['max_id'];
  1.1396 -
  1.1397 -							if ($largest_id)
  1.1398 -							{
  1.1399 -								$db->sql_query('DROP SEQUENCE ' . $schema['target'] . '_seq');
  1.1400 -								$db->sql_query('CREATE SEQUENCE ' . $schema['target'] . '_seq START WITH ' . ($largest_id + 1));
  1.1401 -							}
  1.1402 -						break;
  1.1403 -					}
  1.1404 -				}
  1.1405 -			}
  1.1406 -
  1.1407 -			// When we reach this point, either the current table has been processed or we're running out of time.
  1.1408 -			if (still_on_time() && $counting < $convert->batch_size/* && !defined('DEBUG_EXTRA')*/)
  1.1409 -			{
  1.1410 -				$skip_rows = 0;
  1.1411 -				$current_table++;
  1.1412 -			}
  1.1413 -			else
  1.1414 -			{/*
  1.1415 -				if (still_on_time() && $counting < $convert->batch_size)
  1.1416 -				{
  1.1417 -					$skip_rows = 0;
  1.1418 -					$current_table++;
  1.1419 -				}*/
  1.1420 -
  1.1421 -				// Looks like we ran out of time.
  1.1422 -				$url = $this->save_convert_progress('&amp;current_table=' . $current_table . '&amp;skip_rows=' . $skip_rows);
  1.1423 -
  1.1424 -				$current_table++;
  1.1425 -//				$percentage = ($skip_rows == 0) ? 0 : floor(100 / ($total_rows / $skip_rows));
  1.1426 -
  1.1427 -				$msg = sprintf($user->lang['STEP_PERCENT_COMPLETED'], $current_table, sizeof($convert->convertor['schema']));
  1.1428 -
  1.1429 -				$template->assign_vars(array(
  1.1430 -					'L_MESSAGE'		=> $msg,
  1.1431 -					'L_SUBMIT'		=> $user->lang['CONTINUE_CONVERT'],
  1.1432 -					'U_ACTION'		=> $url,
  1.1433 -				));
  1.1434 -
  1.1435 -				$this->meta_refresh($url);
  1.1436 -				return;
  1.1437 -			}
  1.1438 -		}
  1.1439 -
  1.1440 -		// Process execute_last then we'll be done
  1.1441 -		$url = $this->save_convert_progress('&amp;jump=1');
  1.1442 -
  1.1443 -		$template->assign_vars(array(
  1.1444 -			'L_SUBMIT'		=> $user->lang['FINAL_STEP'],
  1.1445 -			'U_ACTION'		=> $url,
  1.1446 -		));
  1.1447 -
  1.1448 -		$this->meta_refresh($url);
  1.1449 -		return;
  1.1450 -	}
  1.1451 -
  1.1452 -	/**
  1.1453 -	* Sync function being executed at the middle, some functions need to be executed after a successful sync.
  1.1454 -	*/
  1.1455 -	function sync_forums($sync_batch)
  1.1456 -	{
  1.1457 -		global $template, $user, $db, $phpbb_root_path, $phpEx, $config, $cache;
  1.1458 -		global $convert;
  1.1459 -
  1.1460 -		$template->assign_block_vars('checks', array(
  1.1461 -			'S_LEGEND'	=> true,
  1.1462 -			'LEGEND'	=> $user->lang['SYNC_TOPICS'],
  1.1463 -		));
  1.1464 -
  1.1465 -		$batch_size = $convert->batch_size;
  1.1466 -
  1.1467 -		$sql = 'SELECT MIN(topic_id) as min_value, MAX(topic_id) AS max_value
  1.1468 -			FROM ' . TOPICS_TABLE;
  1.1469 -		$result = $db->sql_query($sql);
  1.1470 -		$row = $db->sql_fetchrow($result);
  1.1471 -		$db->sql_freeresult($result);
  1.1472 -
  1.1473 -		// Set values of minimum/maximum primary value for this table.
  1.1474 -		$primary_min = $row['min_value'];
  1.1475 -		$primary_max = $row['max_value'];
  1.1476 -
  1.1477 -		if ($sync_batch == 0)
  1.1478 -		{
  1.1479 -			$sync_batch = (int) $primary_min;
  1.1480 -		}
  1.1481 -
  1.1482 -		if ($sync_batch == 0)
  1.1483 -		{
  1.1484 -			$sync_batch = 1;
  1.1485 -		}
  1.1486 -
  1.1487 -		// Fetch a batch of rows, process and insert them.
  1.1488 -		while ($sync_batch <= $primary_max && still_on_time())
  1.1489 -		{
  1.1490 -			$end = ($sync_batch + $batch_size - 1);
  1.1491 -
  1.1492 -			// Sync all topics in batch mode...
  1.1493 -			sync('topic_approved', 'range', 'topic_id BETWEEN ' . $sync_batch . ' AND ' . $end, true, false);
  1.1494 -			sync('topic', 'range', 'topic_id BETWEEN ' . $sync_batch . ' AND ' . $end, true, true);
  1.1495 -
  1.1496 -			$template->assign_block_vars('checks', array(
  1.1497 -				'TITLE'		=> sprintf($user->lang['SYNC_TOPIC_ID'], $sync_batch, ($sync_batch + $batch_size)) . ((defined('DEBUG_EXTRA') && function_exists('memory_get_usage')) ? ' [' . ceil(memory_get_usage()/1024) . ' ' . $user->lang['KIB'] . ']' : ''),
  1.1498 -				'RESULT'	=> $user->lang['DONE'],
  1.1499 -			));
  1.1500 -
  1.1501 -			$sync_batch += $batch_size;
  1.1502 -		}
  1.1503 -
  1.1504 -		if ($sync_batch >= $primary_max)
  1.1505 -		{
  1.1506 -			$url = $this->save_convert_progress('&amp;final_jump=1');
  1.1507 -
  1.1508 -			$template->assign_vars(array(
  1.1509 -				'L_SUBMIT'		=> $user->lang['CONTINUE_CONVERT'],
  1.1510 -				'U_ACTION'		=> $url,
  1.1511 -			));
  1.1512 -
  1.1513 -			$this->meta_refresh($url);
  1.1514 -			return;
  1.1515 -		}
  1.1516 -		else
  1.1517 -		{
  1.1518 -			$sync_batch--;
  1.1519 -		}
  1.1520 -
  1.1521 -		$url = $this->save_convert_progress('&amp;sync_batch=' . $sync_batch);
  1.1522 -
  1.1523 -		$template->assign_vars(array(
  1.1524 -			'L_SUBMIT'		=> $user->lang['CONTINUE_CONVERT'],
  1.1525 -			'U_ACTION'		=> $url,
  1.1526 -		));
  1.1527 -
  1.1528 -		$this->meta_refresh($url);
  1.1529 -		return;
  1.1530 -	}
  1.1531 -
  1.1532 -	/**
  1.1533 -	* Save the convertor status
  1.1534 -	*/
  1.1535 -	function save_convert_progress($step)
  1.1536 -	{
  1.1537 -		global $convert, $language;
  1.1538 -
  1.1539 -		// Save convertor Status
  1.1540 -		set_config('convert_progress', serialize(array(
  1.1541 -			'step'			=> $step,
  1.1542 -			'table_prefix'	=> $convert->src_table_prefix,
  1.1543 -			'tag'			=> $convert->convertor_tag,
  1.1544 -		)), true);
  1.1545 -
  1.1546 -		set_config('convert_db_server', serialize(array(
  1.1547 -			'dbms'			=> $convert->src_dbms,
  1.1548 -			'dbhost'		=> $convert->src_dbhost,
  1.1549 -			'dbport'		=> $convert->src_dbport,
  1.1550 -			'dbname'		=> $convert->src_dbname,
  1.1551 -		)), true);
  1.1552 -
  1.1553 -		set_config('convert_db_user', serialize(array(
  1.1554 -			'dbuser'		=> $convert->src_dbuser,
  1.1555 -			'dbpasswd'		=> $convert->src_dbpasswd,
  1.1556 -		)), true);
  1.1557 -
  1.1558 -		return $this->p_master->module_url . "?mode={$this->mode}&amp;sub=in_progress&amp;tag={$convert->convertor_tag}$step&amp;language=$language";
  1.1559 -	}
  1.1560 -
  1.1561 -	/**
  1.1562 -	* Finish conversion, the last function to be called.
  1.1563 -	*/
  1.1564 -	function finish_conversion()
  1.1565 -	{
  1.1566 -		global $db, $phpbb_root_path, $phpEx, $convert, $config, $language, $user, $template;
  1.1567 -
  1.1568 -		$db->sql_query('DELETE FROM ' . CONFIG_TABLE . "
  1.1569 -			WHERE config_name = 'convert_progress'
  1.1570 -				OR config_name = 'convert_options'
  1.1571 -				OR config_name = 'convert_db_server'
  1.1572 -				OR config_name = 'convert_db_user'");
  1.1573 -		$db->sql_query('DELETE FROM ' . SESSIONS_TABLE);
  1.1574 -
  1.1575 -		@unlink($phpbb_root_path . 'cache/data_global.' . $phpEx);
  1.1576 -		cache_moderators();
  1.1577 -
  1.1578 -		// And finally, add a note to the log
  1.1579 -		add_log('admin', 'LOG_INSTALL_CONVERTED', $convert->convertor_data['forum_name'], $config['version']);
  1.1580 -
  1.1581 -		$url = $this->p_master->module_url . "?mode={$this->mode}&amp;sub=final&amp;language=$language";
  1.1582 -
  1.1583 -		$template->assign_vars(array(
  1.1584 -			'L_SUBMIT'		=> $user->lang['FINAL_STEP'],
  1.1585 -			'U_ACTION'		=> $url,
  1.1586 -		));
  1.1587 -
  1.1588 -		$this->meta_refresh($url);
  1.1589 -		return;
  1.1590 -	}
  1.1591 -
  1.1592 -	/**
  1.1593 -	* This function marks the steps after syncing
  1.1594 -	*/
  1.1595 -	function final_jump($final_jump)
  1.1596 -	{
  1.1597 -		global $template, $user, $src_db, $same_db, $db, $phpbb_root_path, $phpEx, $config, $cache;
  1.1598 -		global $convert;
  1.1599 -
  1.1600 -		$template->assign_block_vars('checks', array(
  1.1601 -			'S_LEGEND'	=> true,
  1.1602 -			'LEGEND'	=> $user->lang['PROCESS_LAST'],
  1.1603 -		));
  1.1604 -
  1.1605 -		if ($final_jump == 1)
  1.1606 -		{
  1.1607 -			$db->sql_return_on_error(true);
  1.1608 -
  1.1609 -			update_topics_posted();
  1.1610 -
  1.1611 -			$template->assign_block_vars('checks', array(
  1.1612 -				'TITLE'		=> $user->lang['UPDATE_TOPICS_POSTED'],
  1.1613 -				'RESULT'	=> $user->lang['DONE'],
  1.1614 -			));
  1.1615 -
  1.1616 -			if ($db->sql_error_triggered)
  1.1617 -			{
  1.1618 -				$template->assign_vars(array(
  1.1619 -					'S_ERROR_BOX'	=> true,
  1.1620 -					'ERROR_TITLE'	=> $user->lang['UPDATE_TOPICS_POSTED'],
  1.1621 -					'ERROR_MSG'		=> $user->lang['UPDATE_TOPICS_POSTED_ERR'],
  1.1622 -				));
  1.1623 -			}
  1.1624 -			$db->sql_return_on_error(false);
  1.1625 -
  1.1626 -			$this->finish_conversion();
  1.1627 -			return;
  1.1628 -		}
  1.1629 -	}
  1.1630 -
  1.1631 -	/**
  1.1632 -	* This function marks the steps before syncing (jump=1)
  1.1633 -	*/
  1.1634 -	function jump($jump, $last_statement)
  1.1635 -	{
  1.1636 -		global $template, $user, $src_db, $same_db, $db, $phpbb_root_path, $phpEx, $config, $cache;
  1.1637 -		global $convert;
  1.1638 -
  1.1639 -		$template->assign_block_vars('checks', array(
  1.1640 -			'S_LEGEND'	=> true,
  1.1641 -			'LEGEND'	=> $user->lang['PROCESS_LAST'],
  1.1642 -		));
  1.1643 -
  1.1644 -		if ($jump == 1)
  1.1645 -		{
  1.1646 -			// Execute 'last' statements/queries
  1.1647 -			if (!empty($convert->convertor['execute_last']))
  1.1648 -			{
  1.1649 -				if (!is_array($convert->convertor['execute_last']))
  1.1650 -				{
  1.1651 -					eval($convert->convertor['execute_last']);
  1.1652 -				}
  1.1653 -				else
  1.1654 -				{
  1.1655 -					while ($last_statement < sizeof($convert->convertor['execute_last']))
  1.1656 -					{
  1.1657 -						eval($convert->convertor['execute_last'][$last_statement]);
  1.1658 -
  1.1659 -						$template->assign_block_vars('checks', array(
  1.1660 -							'TITLE'		=> $convert->convertor['execute_last'][$last_statement],
  1.1661 -							'RESULT'	=> $user->lang['DONE'],
  1.1662 -						));
  1.1663 -
  1.1664 -						$last_statement++;
  1.1665 -						$url = $this->save_convert_progress('&amp;jump=1&amp;last=' . $last_statement);
  1.1666 -
  1.1667 -						$percentage = ($last_statement == 0) ? 0 : floor(100 / (sizeof($convert->convertor['execute_last']) / $last_statement));
  1.1668 -						$msg = sprintf($user->lang['STEP_PERCENT_COMPLETED'], $last_statement, sizeof($convert->convertor['execute_last']), $percentage);
  1.1669 -
  1.1670 -						$template->assign_vars(array(
  1.1671 -							'L_SUBMIT'		=> $user->lang['CONTINUE_LAST'],
  1.1672 -							'L_MESSAGE'		=> $msg,
  1.1673 -							'U_ACTION'		=> $url,
  1.1674 -						));
  1.1675 -
  1.1676 -						$this->meta_refresh($url);
  1.1677 -						return;
  1.1678 -					}
  1.1679 -				}
  1.1680 -			}
  1.1681 -
  1.1682 -			if (!empty($convert->convertor['query_last']))
  1.1683 -			{
  1.1684 -				if (!is_array($convert->convertor['query_last']))
  1.1685 -				{
  1.1686 -					$convert->convertor['query_last'] = array('target', array($convert->convertor['query_last']));
  1.1687 -				}
  1.1688 -				else if (!is_array($convert->convertor['query_last'][0]))
  1.1689 -				{
  1.1690 -					$convert->convertor['query_last'] = array(array($convert->convertor['query_last'][0], $convert->convertor['query_last'][1]));
  1.1691 -				}
  1.1692 -
  1.1693 -				foreach ($convert->convertor['query_last'] as $query_last)
  1.1694 -				{
  1.1695 -					if ($query_last[0] == 'src')
  1.1696 -					{
  1.1697 -						if ($convert->mysql_convert && $same_db)
  1.1698 -						{
  1.1699 -							$src_db->sql_query("SET NAMES 'binary'");
  1.1700 -						}
  1.1701 -
  1.1702 -						$src_db->sql_query($query_last[1]);
  1.1703 -
  1.1704 -						if ($convert->mysql_convert && $same_db)
  1.1705 -						{
  1.1706 -							$src_db->sql_query("SET NAMES 'utf8'");
  1.1707 -						}
  1.1708 -					}
  1.1709 -					else
  1.1710 -					{
  1.1711 -						$db->sql_query($query_last[1]);
  1.1712 -					}
  1.1713 -				}
  1.1714 -			}
  1.1715 -
  1.1716 -			// Sanity check
  1.1717 -			$db->sql_return_on_error(false);
  1.1718 -			$src_db->sql_return_on_error(false);
  1.1719 -
  1.1720 -			fix_empty_primary_groups();
  1.1721 -
  1.1722 -			$sql = 'SELECT MIN(user_regdate) AS board_startdate
  1.1723 -				FROM ' . USERS_TABLE;
  1.1724 -			$result = $db->sql_query($sql);
  1.1725 -			$row = $db->sql_fetchrow($result);
  1.1726 -			$db->sql_freeresult($result);
  1.1727 -
  1.1728 -			if (!isset($config['board_startdate']) || ($row['board_startdate'] < $config['board_startdate'] && $row['board_startdate'] > 0))
  1.1729 -			{
  1.1730 -				set_config('board_startdate', $row['board_startdate']);
  1.1731 -				$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_regdate = ' . $row['board_startdate'] . ' WHERE user_id = ' . ANONYMOUS);
  1.1732 -			}
  1.1733 -
  1.1734 -			update_dynamic_config();
  1.1735 -
  1.1736 -			$template->assign_block_vars('checks', array(
  1.1737 -				'TITLE'		=> $user->lang['CLEAN_VERIFY'],
  1.1738 -				'RESULT'	=> $user->lang['DONE'],
  1.1739 -			));
  1.1740 -
  1.1741 -			$url = $this->save_convert_progress('&amp;jump=2');
  1.1742 -
  1.1743 -			$template->assign_vars(array(
  1.1744 -				'L_SUBMIT'		=> $user->lang['CONTINUE_CONVERT'],
  1.1745 -				'U_ACTION'		=> $url,
  1.1746 -			));
  1.1747 -
  1.1748 -			$this->meta_refresh($url);
  1.1749 -			return;
  1.1750 -		}
  1.1751 -
  1.1752 -		if ($jump == 2)
  1.1753 -		{
  1.1754 -			$db->sql_query('UPDATE ' . USERS_TABLE . " SET user_permissions = ''");
  1.1755 -
  1.1756 -			// TODO: sync() is likely going to bomb out on forums with a considerable amount of topics.
  1.1757 -			// TODO: the sync function is able to handle FROM-TO values, we should use them here (batch processing)
  1.1758 -			sync('forum', '', '', false, true);
  1.1759 -			$cache->destroy('sql', FORUMS_TABLE);
  1.1760 -
  1.1761 -			$template->assign_block_vars('checks', array(
  1.1762 -				'TITLE'		=> $user->lang['SYNC_FORUMS'],
  1.1763 -				'RESULT'	=> $user->lang['DONE'],
  1.1764 -			));
  1.1765 -
  1.1766 -			// Continue with synchronizing the forums...
  1.1767 -			$url = $this->save_convert_progress('&amp;sync_batch=0');
  1.1768 -
  1.1769 -			$template->assign_vars(array(
  1.1770 -				'L_SUBMIT'		=> $user->lang['CONTINUE_CONVERT'],
  1.1771 -				'U_ACTION'		=> $url,
  1.1772 -			));
  1.1773 -
  1.1774 -			$this->meta_refresh($url);
  1.1775 -			return;
  1.1776 -		}
  1.1777 -	}
  1.1778 -
  1.1779 -	function build_insert_query(&$schema, &$sql_data, $current_table)
  1.1780 -	{
  1.1781 -		global $db, $user;
  1.1782 -		global $convert;
  1.1783 -
  1.1784 -		// Can we use IGNORE with this DBMS?
  1.1785 -		$sql_ignore = (strpos($db->sql_layer, 'mysql') === 0 && !defined('DEBUG_EXTRA')) ? 'IGNORE ' : '';
  1.1786 -		$insert_query = 'INSERT ' . $sql_ignore . 'INTO ' . $schema['target'] . ' (';
  1.1787 -
  1.1788 -		$aliases = array();
  1.1789 -
  1.1790 -		$sql_data = array(
  1.1791 -			'source_fields'		=> array(),
  1.1792 -			'target_fields'		=> array(),
  1.1793 -			'source_tables'		=> array(),
  1.1794 -			'select_fields'		=> array(),
  1.1795 -		);
  1.1796 -
  1.1797 -		foreach ($schema as $key => $val)
  1.1798 -		{
  1.1799 -			// Example: array('group_name',				'extension_groups.group_name',		'htmlspecialchars'),
  1.1800 -			if (is_int($key))
  1.1801 -			{
  1.1802 -				if (!empty($val[0]))
  1.1803 -				{
  1.1804 -					// Target fields
  1.1805 -					$sql_data['target_fields'][$val[0]] = $key;
  1.1806 -					$insert_query .= $val[0] . ', ';
  1.1807 -				}
  1.1808 -
  1.1809 -				if (!is_array($val[1]))
  1.1810 -				{
  1.1811 -					$val[1] = array($val[1]);
  1.1812 -				}
  1.1813 -
  1.1814 -				foreach ($val[1] as $valkey => $value_1)
  1.1815 -				{
  1.1816 -					// This should cover about any case:
  1.1817 -					//
  1.1818 -					// table.field					=> SELECT table.field				FROM table
  1.1819 -					// table.field AS alias			=> SELECT table.field	AS alias	FROM table
  1.1820 -					// table.field AS table2.alias	=> SELECT table2.field	AS alias	FROM table table2
  1.1821 -					// table.field AS table2.field	=> SELECT table2.field				FROM table table2
  1.1822 -					//
  1.1823 -					if (preg_match('/^([a-z0-9_]+)\.([a-z0-9_]+)( +AS +(([a-z0-9_]+?)\.)?([a-z0-9_]+))?$/i', $value_1, $m))
  1.1824 -					{
  1.1825 -						// There is 'AS ...' in the field names
  1.1826 -						if (!empty($m[3]))
  1.1827 -						{
  1.1828 -							$value_1 = ($m[2] == $m[6]) ? $m[1] . '.' . $m[2] : $m[1] . '.' . $m[2] . ' AS ' . $m[6];
  1.1829 -
  1.1830 -							// Table alias: store it then replace the source table with it
  1.1831 -							if (!empty($m[5]) && $m[5] != $m[1])
  1.1832 -							{
  1.1833 -								$aliases[$m[5]] = $m[1];
  1.1834 -								$value_1 = str_replace($m[1] . '.' . $m[2], $m[5] . '.' . $m[2], $value_1);
  1.1835 -							}
  1.1836 -						}
  1.1837 -						else
  1.1838 -						{
  1.1839 -							// No table alias
  1.1840 -							$sql_data['source_tables'][$m[1]] = (empty($convert->src_table_prefix)) ? $m[1] : $convert->src_table_prefix . $m[1] . ' ' . $m[1];
  1.1841 -						}
  1.1842 -
  1.1843 -						$sql_data['select_fields'][$value_1] = $value_1;
  1.1844 -						$sql_data['source_fields'][$key][$valkey] = (!empty($m[6])) ? $m[6] : $m[2];
  1.1845 -					}
  1.1846 -				}
  1.1847 -			}
  1.1848 -			else if ($key == 'where' || $key == 'group_by' || $key == 'order_by' || $key == 'having')
  1.1849 -			{
  1.1850 -				if (@preg_match_all('/([a-z0-9_]+)\.([a-z0-9_]+)/i', $val, $m))
  1.1851 -				{
  1.1852 -					foreach ($m[1] as $value)
  1.1853 -					{
  1.1854 -						$sql_data['source_tables'][$value] = (empty($convert->src_table_prefix)) ? $value : $convert->src_table_prefix . $value . ' ' . $value;
  1.1855 -					}
  1.1856 -				}
  1.1857 -			}
  1.1858 -		}
  1.1859 -
  1.1860 -		// Add the aliases to the list of tables
  1.1861 -		foreach ($aliases as $alias => $table)
  1.1862 -		{
  1.1863 -			$sql_data['source_tables'][$alias] = $convert->src_table_prefix . $table . ' ' . $alias;
  1.1864 -		}
  1.1865 -
  1.1866 -		// 'left_join'		=> 'forums LEFT JOIN forum_prune ON forums.forum_id = forum_prune.forum_id',
  1.1867 -		if (!empty($schema['left_join']))
  1.1868 -		{
  1.1869 -			if (!is_array($schema['left_join']))
  1.1870 -			{
  1.1871 -				$schema['left_join'] = array($schema['left_join']);
  1.1872 -			}
  1.1873 -
  1.1874 -			foreach ($schema['left_join'] as $left_join)
  1.1875 -			{
  1.1876 -				// This won't handle concatened LEFT JOINs
  1.1877 -				if (!preg_match('/([a-z0-9_]+) LEFT JOIN ([a-z0-9_]+) A?S? ?([a-z0-9_]*?) ?(ON|USING)(.*)/i', $left_join, $m))
  1.1878 -				{
  1.1879 -					$this->p_master->error(sprintf($user->lang['NOT_UNDERSTAND'], 'LEFT JOIN', $left_join, $current_table, $schema['target']), __LINE__, __FILE__);
  1.1880 -				}
  1.1881 -
  1.1882 -				if (!empty($aliases[$m[2]]))
  1.1883 -				{
  1.1884 -					if (!empty($m[3]))
  1.1885 -					{
  1.1886 -						$this->p_master->error(sprintf($user->lang['NAMING_CONFLICT'], $m[2], $m[3], $schema['left_join']), __LINE__, __FILE__);
  1.1887 -					}
  1.1888 -
  1.1889 -					$m[2] = $aliases[$m[2]];
  1.1890 -					$m[3] = $m[2];
  1.1891 -				}
  1.1892 -
  1.1893 -				$right_table = $convert->src_table_prefix . $m[2];
  1.1894 -				if (!empty($m[3]))
  1.1895 -				{
  1.1896 -					unset($sql_data['source_tables'][$m[3]]);
  1.1897 -				}
  1.1898 -				else if ($m[2] != $m[1])
  1.1899 -				{
  1.1900 -					unset($sql_data['source_tables'][$m[2]]);
  1.1901 -				}
  1.1902 -
  1.1903 -				if (strpos($sql_data['source_tables'][$m[1]], "\nLEFT JOIN") !== false)
  1.1904 -				{
  1.1905 -					$sql_data['source_tables'][$m[1]] = '(' . $sql_data['source_tables'][$m[1]] . ")\nLEFT JOIN $right_table";
  1.1906 -				}
  1.1907 -				else
  1.1908 -				{
  1.1909 -					$sql_data['source_tables'][$m[1]] .= "\nLEFT JOIN $right_table";
  1.1910 -				}
  1.1911 -
  1.1912 -				if (!empty($m[3]))
  1.1913 -				{
  1.1914 -					unset($sql_data['source_tables'][$m[3]]);
  1.1915 -					$sql_data['source_tables'][$m[1]] .= ' AS ' . $m[3];
  1.1916 -				}
  1.1917 -				else if (!empty($convert->src_table_prefix))
  1.1918 -				{
  1.1919 -					$sql_data['source_tables'][$m[1]] .= ' AS ' . $m[2];
  1.1920 -				}
  1.1921 -				$sql_data['source_tables'][$m[1]] .= ' ' . $m[4] . $m[5];
  1.1922 -			}
  1.1923 -		}
  1.1924 -
  1.1925 -		// Remove ", " from the end of the insert query
  1.1926 -		$insert_query = substr($insert_query, 0, -2) . ') VALUES ';
  1.1927 -
  1.1928 -		return $insert_query;
  1.1929 -	}
  1.1930 -
  1.1931 -	/**
  1.1932 -	* Function for processing the currently handled row
  1.1933 -	*/
  1.1934 -	function process_row(&$schema, &$sql_data, &$insert_values)
  1.1935 -	{
  1.1936 -		global $template, $user, $phpbb_root_path, $phpEx, $db, $lang, $config, $cache;
  1.1937 -		global $convert, $convert_row;
  1.1938 -
  1.1939 -		$sql_flag = false;
  1.1940 -
  1.1941 -		foreach ($schema as $key => $fields)
  1.1942 -		{
  1.1943 -			// We are only interested in the lines with:
  1.1944 -			// array('comment', 'attachments_desc.comment', 'htmlspecialchars'),
  1.1945 -			if (is_int($key))
  1.1946 -			{
  1.1947 -				if (!is_array($fields[1]))
  1.1948 -				{
  1.1949 -					$fields[1] = array($fields[1]);
  1.1950 -				}
  1.1951 -
  1.1952 -				$firstkey_set = false;
  1.1953 -				$firstkey = 0;
  1.1954 -
  1.1955 -				foreach ($fields[1] as $inner_key => $inner_value)
  1.1956 -				{
  1.1957 -					if (!$firstkey_set)
  1.1958 -					{
  1.1959 -						$firstkey = $inner_key;
  1.1960 -						$firstkey_set = true;
  1.1961 -					}
  1.1962 -
  1.1963 -					$src_field = isset($sql_data['source_fields'][$key][$inner_key]) ? $sql_data['source_fields'][$key][$inner_key] : '';
  1.1964 -
  1.1965 -					if (!empty($src_field))
  1.1966 -					{
  1.1967 -						$fields[1][$inner_key] = $convert->row[$src_field];
  1.1968 -					}
  1.1969 -				}
  1.1970 -
  1.1971 -				if (!empty($fields[0]))
  1.1972 -				{
  1.1973 -					// We have a target field, if we haven't set $sql_flag yet it will be set to TRUE.
  1.1974 -					// If a function has already set it to FALSE it won't change it.
  1.1975 -					if ($sql_flag === false)
  1.1976 -					{
  1.1977 -						$sql_flag = true;
  1.1978 -					}
  1.1979 -
  1.1980 -					// No function assigned?
  1.1981 -					if (empty($fields[2]))
  1.1982 -					{
  1.1983 -						$value = $fields[1][$firstkey];
  1.1984 -					}
  1.1985 -					else if (is_array($fields[2]))
  1.1986 -					{
  1.1987 -						// Execute complex function/eval/typecast
  1.1988 -						$value = $fields[1];
  1.1989 -
  1.1990 -						foreach ($fields[2] as $type => $execution)
  1.1991 -						{
  1.1992 -							if (strpos($type, 'typecast') === 0)
  1.1993 -							{
  1.1994 -								if (!is_array($value))
  1.1995 -								{
  1.1996 -									$value = array($value);
  1.1997 -								}
  1.1998 -								$value = $value[0];
  1.1999 -								settype($value, $execution);
  1.2000 -							}
  1.2001 -							else if (strpos($type, 'function') === 0)
  1.2002 -							{
  1.2003 -								if (!is_array($value))
  1.2004 -								{
  1.2005 -									$value = array($value);
  1.2006 -								}
  1.2007 -
  1.2008 -								$value = call_user_func_array($execution, $value);
  1.2009 -							}
  1.2010 -							else if (strpos($type, 'execute') === 0)
  1.2011 -							{
  1.2012 -								if (!is_array($value))
  1.2013 -								{
  1.2014 -									$value = array($value);
  1.2015 -								}
  1.2016 -
  1.2017 -								$execution = str_replace('{RESULT}', '$value', $execution);
  1.2018 -								$execution = str_replace('{VALUE}', '$value', $execution);
  1.2019 -								eval($execution);
  1.2020 -							}
  1.2021 -						}
  1.2022 -					}
  1.2023 -					else
  1.2024 -					{
  1.2025 -						$value = call_user_func_array($fields[2], $fields[1]);
  1.2026 -					}
  1.2027 -
  1.2028 -					if (is_null($value))
  1.2029 -					{
  1.2030 -						$value = '';
  1.2031 -					}
  1.2032 -
  1.2033 -					$insert_values[] = $db->_sql_validate_value($value);
  1.2034 -				}
  1.2035 -				else if (!empty($fields[2]))
  1.2036 -				{
  1.2037 -					if (is_array($fields[2]))
  1.2038 -					{
  1.2039 -						// Execute complex function/eval/typecast
  1.2040 -						$value = '';
  1.2041 -
  1.2042 -						foreach ($fields[2] as $type => $execution)
  1.2043 -						{
  1.2044 -							if (strpos($type, 'typecast') === 0)
  1.2045 -							{
  1.2046 -								$value = settype($value, $execution);
  1.2047 -							}
  1.2048 -							else if (strpos($type, 'function') === 0)
  1.2049 -							{
  1.2050 -								if (!is_array($value))
  1.2051 -								{
  1.2052 -									$value = array($value);
  1.2053 -								}
  1.2054 -
  1.2055 -								$value = call_user_func_array($execution, $value);
  1.2056 -							}
  1.2057 -							else if (strpos($type, 'execute') === 0)
  1.2058 -							{
  1.2059 -								if (!is_array($value))
  1.2060 -								{
  1.2061 -									$value = array($value);
  1.2062 -								}
  1.2063 -
  1.2064 -								$execution = str_replace('{RESULT}', '$value', $execution);
  1.2065 -								$execution = str_replace('{VALUE}', '$value', $execution);
  1.2066 -								eval($execution);
  1.2067 -							}
  1.2068 -						}
  1.2069 -					}
  1.2070 -					else
  1.2071 -					{
  1.2072 -						call_user_func_array($fields[2], $fields[1]);
  1.2073 -					}
  1.2074 -				}
  1.2075 -			}
  1.2076 -		}
  1.2077 -
  1.2078 -		return $sql_flag;
  1.2079 -	}
  1.2080 -
  1.2081 -	/**
  1.2082 -	* Own meta refresh function to be able to change the global time used
  1.2083 -	*/
  1.2084 -	function meta_refresh($url)
  1.2085 -	{
  1.2086 -		global $convert, $template;
  1.2087 -
  1.2088 -		if ($convert->options['refresh'])
  1.2089 -		{
  1.2090 -			// Because we should not rely on correct settings, we simply use the relative path here directly.
  1.2091 -			$template->assign_vars(array(
  1.2092 -				'S_REFRESH'	=> true,
  1.2093 -				'META'		=> '<meta http-equiv="refresh" content="5;url=' . $url . '" />')
  1.2094 -			);
  1.2095 -		}
  1.2096 -	}
  1.2097 -
  1.2098 -	/**
  1.2099 -	* The information below will be used to build the input fields presented to the user
  1.2100 -	*/
  1.2101 -	var $convert_options = array(
  1.2102 -		'legend1'			=> 'SPECIFY_OPTIONS',
  1.2103 -		'src_dbms'			=> array('lang' => 'DBMS',			'type' => 'select', 'options' => 'dbms_select(\'{VALUE}\', true)', 'explain' => false),
  1.2104 -		'src_dbhost'		=> array('lang' => 'DB_HOST',		'type' => 'text:25:100', 'explain' => true),
  1.2105 -		'src_dbport'		=> array('lang' => 'DB_PORT',		'type' => 'text:25:100', 'explain' => true),
  1.2106 -		'src_dbname'		=> array('lang' => 'DB_NAME',		'type' => 'text:25:100', 'explain' => false),
  1.2107 -		'src_dbuser'		=> array('lang' => 'DB_USERNAME',	'type' => 'text:25:100', 'explain' => false),
  1.2108 -		'src_dbpasswd'		=> array('lang' => 'DB_PASSWORD',	'type' => 'password:25:100', 'explain' => false),
  1.2109 -		'src_table_prefix'	=> array('lang' => 'TABLE_PREFIX',	'type' => 'text:25:100', 'explain' => false),
  1.2110 -		//'src_url'			=> array('lang' => 'FORUM_ADDRESS',	'type' => 'text:50:100', 'explain' => true),
  1.2111 -		'forum_path'		=> array('lang' => 'FORUM_PATH',	'type' => 'text:25:100', 'explain' => true),
  1.2112 -		'refresh'			=> array('lang' => 'REFRESH_PAGE',	'type' => 'radio:yes_no', 'explain' => true),
  1.2113 -	);
  1.2114 -}
  1.2115 -
  1.2116 -?>
  1.2117 \ No newline at end of file