diff options
Diffstat (limited to 'phpBB/install/database_update.php')
| -rw-r--r-- | phpBB/install/database_update.php | 325 | 
1 files changed, 297 insertions, 28 deletions
| diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index a167e79308..4c588f49cd 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2,13 +2,12 @@  /**  *  * @package install -* @version $Id$  * @copyright (c) 2006 phpBB Group  * @license http://opensource.org/licenses/gpl-license.php GNU Public License  *  */ -define('UPDATES_TO_VERSION', '3.0.10-dev'); +define('UPDATES_TO_VERSION', '3.1.0-dev');  // Enter any version to update from to test updates. The version within the db will not be updated.  define('DEBUG_FROM_VERSION', false); @@ -84,9 +83,7 @@ if (!empty($load_extensions) && function_exists('dl'))  }  // Include files -require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx); -require($phpbb_root_path . 'includes/cache.' . $phpEx); -require($phpbb_root_path . 'includes/template.' . $phpEx); +require($phpbb_root_path . 'includes/class_loader.' . $phpEx);  require($phpbb_root_path . 'includes/session.' . $phpEx);  require($phpbb_root_path . 'includes/auth.' . $phpEx); @@ -108,10 +105,21 @@ if (!defined('LOGIN_ATTEMPT_TABLE'))  	define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts');  } +$class_loader = new phpbb_class_loader($phpbb_root_path, '.' . $phpEx); +$class_loader->register(); + +// set up caching +$cache_factory = new phpbb_cache_factory($acm_type); +$cache = $cache_factory->get_service(); +$class_loader->set_cache($cache->get_driver()); + +$request = new phpbb_request();  $user = new user(); -$cache = new cache();  $db = new $sql_db(); +// make sure request_var uses this request instance +request_var('', 0, false, false, $request); // "dependency injection" for a function +  // Add own hook handler, if present. :o  if (file_exists($phpbb_root_path . 'includes/hooks/index.' . $phpEx))  { @@ -134,8 +142,11 @@ $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);  // We do not need this any longer, unset for safety purposes  unset($dbpasswd); -$user->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : ''; -$user->ip = (stripos($user->ip, '::ffff:') === 0) ? substr($user->ip, 7) : $user->ip; +$user->ip = ''; +if ($request->server('REMOTE_ADDR')) +{ +	$user->ip = (function_exists('phpbb_ip_normalise')) ? phpbb_ip_normalise($request->server('REMOTE_ADDR')) : $request->server('REMOTE_ADDR'); +}  $sql = "SELECT config_value  	FROM " . CONFIG_TABLE . " @@ -168,17 +179,9 @@ include($phpbb_root_path . 'language/' . $language . '/install.' . $phpEx);  $inline_update = (request_var('type', 0)) ? true : false;  // To let set_config() calls succeed, we need to make the config array available globally -$config = array(); - -$sql = 'SELECT * -	FROM ' . CONFIG_TABLE; -$result = $db->sql_query($sql); - -while ($row = $db->sql_fetchrow($result)) -{ -	$config[$row['config_name']] = $row['config_value']; -} -$db->sql_freeresult($result); +$config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE); +set_config(null, null, null, $config); +set_config_count(null, null, null, $config);  // phpbb_db_tools will be taken from new files (under install/update/new)  // if possible, falling back to the board's copy. @@ -189,17 +192,72 @@ $database_update_info = database_update_info();  $error_ary = array();  $errored = false; +$sql = 'SELECT topic_id +	FROM ' . TOPICS_TABLE . ' +	WHERE forum_id = 0 +		AND topic_type = ' . POST_GLOBAL; +$result = $db->sql_query_limit($sql, 1); +$has_global = (int) $db->sql_fetchfield('topic_id'); +$db->sql_freeresult($result); +$ga_forum_id = request_var('ga_forum_id', 0); + +if ($has_global && !$ga_forum_id) +{ +	?> +	<!DOCTYPE html> +	<html dir="<?php echo $lang['DIRECTION']; ?>" lang="<?php echo $lang['USER_LANG']; ?>"> +	<head> +	<meta charset="utf-8"> + +	<title><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></title> + +	<link href="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" /> + +	</head> + +	<body> +	<div id="wrap"> +		<div id="page-header"> </div> + +		<div id="page-body"> +			<div id="acp"> +			<div class="panel"> +				<span class="corners-top"><span></span></span> +					<div id="content"> +						<div id="main" class="install-body"> + +		<h1><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></h1> + +		<br /> + +		<form action="" method="post" id="select_ga_forum_id"> +			<?php +				if (isset($lang['SELECT_FORUM_GA'])) +				{ +					// Language string is available: +					echo $lang['SELECT_FORUM_GA']; +				} +				else +				{ +					echo 'In phpBB 3.1 the global announcements are linked to forums. Select a forum for your current global announcements (can be moved later):'; +				} +			?> +			<select id="ga_forum_id" name="ga_forum_id"><?php echo make_forum_select(false, false, true, true) ?></select> + +			<input type="submit" name="post" value="<?php echo $lang['SUBMIT']; ?>" class="button1" /> +		</form> +	<?php +	_print_footer(); +	exit; +} +  header('Content-type: text/html; charset=UTF-8');  ?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $lang['DIRECTION']; ?>" lang="<?php echo $lang['USER_LANG']; ?>" xml:lang="<?php echo $lang['USER_LANG']; ?>"> +<!DOCTYPE html> +<html dir="<?php echo $lang['DIRECTION']; ?>" lang="<?php echo $lang['USER_LANG']; ?>">  <head> - -<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> -<meta http-equiv="content-language" content="<?php echo $lang['USER_LANG']; ?>" /> -<meta http-equiv="content-style-type" content="text/css" /> -<meta http-equiv="imagetoolbar" content="no" /> +<meta charset="utf-8">  <title><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></title> @@ -987,6 +1045,41 @@ function database_update_info()  		'3.0.9-RC4'     => array(),  		/** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.10-RC1 */ + +		// Changes from 3.1.0-dev to 3.1.0-A1 +		'3.1.0-dev'		=> array( +			'add_columns'		=> array( +				GROUPS_TABLE		=> array( +					'group_teampage'	=> array('UINT', 0, 'after' => 'group_legend'), +				), +				PROFILE_FIELDS_TABLE	=> array( +					'field_show_on_pm'		=> array('BOOL', 0), +				), +			), +			'change_columns'	=> array( +				GROUPS_TABLE		=> array( +					'group_legend'		=> array('UINT', 0), +				), +			), +			'drop_columns'      => array( +			    STYLES_TABLE		    => array( +			        'imageset_id', +                ), +				STYLES_TEMPLATE_TABLE	=> array( +					'template_storedb', +				), +				STYLES_THEME_TABLE		=> array( +					'theme_storedb', +					'theme_mtime', +					'theme_data', +				), +            ), +            'drop_tables'       => array( +                STYLES_IMAGESET_TABLE, +                STYLES_IMAGESET_DATA_TABLE, +                STYLES_TEMPLATE_DATA_TABLE, +            ), +		),  	);  } @@ -1994,7 +2087,183 @@ function change_database_data(&$no_updates, $version)  		// No changes from 3.0.9-RC4 to 3.0.9  		case '3.0.9-RC4':  		break; + +		// Changes from 3.1.0-dev to 3.1.0-A1 +		case '3.1.0-dev': +			set_config('load_jquery_cdn', 0); +			set_config('load_jquery_url', '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'); + +			if (!isset($config['use_system_cron'])) +			{ +				set_config('use_system_cron', 0); +			} + +			$sql = 'SELECT group_teampage +				FROM ' . GROUPS_TABLE . ' +				WHERE group_teampage > 0'; +			$result = $db->sql_query_limit($sql, 1); +			$added_groups_teampage = (bool) $db->sql_fetchfield('group_teampage'); +			$db->sql_freeresult($result); + +			if (!$added_groups_teampage) +			{ +				$sql = 'UPDATE ' . GROUPS_TABLE . ' +					SET group_teampage = 1 +					WHERE group_type = ' . GROUP_SPECIAL . " +						AND group_name = 'ADMINISTRATORS'"; +				_sql($sql, $errored, $error_ary); + +				$sql = 'UPDATE ' . GROUPS_TABLE . ' +					SET group_teampage = 2 +					WHERE group_type = ' . GROUP_SPECIAL . " +						AND group_name = 'GLOBAL_MODERATORS'"; +				_sql($sql, $errored, $error_ary); +			} + +			if (!isset($config['use_system_cron'])) +			{ +				set_config('legend_sort_groupname', '0'); +				set_config('teampage_multiple', '1'); +				set_config('teampage_forums', '1'); +			} + +			$sql = 'SELECT group_legend +				FROM ' . GROUPS_TABLE . ' +				WHERE group_teampage > 1'; +			$result = $db->sql_query_limit($sql, 1); +			$updated_group_legend = (bool) $db->sql_fetchfield('group_teampage'); +			$db->sql_freeresult($result); + +			if (!$updated_group_legend) +			{ +				$sql = 'SELECT group_id +					FROM ' . GROUPS_TABLE . ' +					WHERE group_legend = 1 +					ORDER BY group_name ASC'; +				$result = $db->sql_query($sql); + +				$next_legend = 1; +				while ($row = $db->sql_fetchrow($result)) +				{ +					$sql = 'UPDATE ' . GROUPS_TABLE . ' +						SET group_legend = ' . $next_legend . ' +						WHERE group_id = ' . (int) $row['group_id']; +					_sql($sql, $errored, $error_ary); + +					$next_legend++; +				} +				$db->sql_freeresult($result); +				unset($next_legend); +			} + +			// Install modules +			$modules_to_install = array( +				'position'	=> array( +					'base'		=> 'groups', +					'class'		=> 'acp', +					'title'		=> 'ACP_GROUPS_POSITION', +					'auth'		=> 'acl_a_group', +					'cat'		=> 'ACP_GROUPS', +				), +				'manage'	=> array( +					'base'		=> 'attachments', +					'class'		=> 'acp', +					'title'		=> 'ACP_MANAGE_ATTACHMENTS', +					'auth'		=> 'acl_a_attach', +					'cat'		=> 'ACP_ATTACHMENTS', +				), +			); + +			_add_modules($modules_to_install); +			 +			$sql = 'DELETE FROM ' . MODULES_TABLE . " +			    WHERE module_basename = 'styles' AND module_mode = 'imageset'"; +			_sql($sql, $errored, $error_ary); + +			// Localise Global Announcements +			$sql = 'SELECT topic_id, topic_approved, (topic_replies + 1) AS topic_posts, topic_last_post_id, topic_last_post_subject, topic_last_post_time, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour +				FROM ' . TOPICS_TABLE . ' +				WHERE forum_id = 0 +					AND topic_type = ' . POST_GLOBAL; +			$result = $db->sql_query($sql); + +			$global_announcements = $update_lastpost_data = array(); +			$update_lastpost_data['forum_last_post_time'] = 0; +			$update_forum_data = array( +				'forum_posts'		=> 0, +				'forum_topics'		=> 0, +				'forum_topics_real'	=> 0, +			); + +			while ($row = $db->sql_fetchrow($result)) +			{ +				$global_announcements[] = (int) $row['topic_id']; + +				$update_forum_data['forum_posts'] += (int) $row['topic_posts']; +				$update_forum_data['forum_topics_real']++; +				if ($row['topic_approved']) +				{ +					$update_forum_data['forum_topics']++; +				} + +				if ($update_lastpost_data['forum_last_post_time'] < $row['topic_last_post_time']) +				{ +					$update_lastpost_data = array( +						'forum_last_post_id'		=> (int) $row['topic_last_post_id'], +						'forum_last_post_subject'	=> $row['topic_last_post_subject'], +						'forum_last_post_time'		=> (int) $row['topic_last_post_time'], +						'forum_last_poster_id'		=> (int) $row['topic_last_poster_id'], +						'forum_last_poster_name'	=> $row['topic_last_poster_name'], +						'forum_last_poster_colour'	=> $row['topic_last_poster_colour'], +					); +				} +			} +			$db->sql_freeresult($result); + +			if (!empty($global_announcements)) +			{ +				// Update the post/topic-count for the forum and the last-post if needed +				$ga_forum_id = request_var('ga_forum_id', 0); + +				$sql = 'SELECT forum_last_post_time +					FROM ' . FORUMS_TABLE . ' +					WHERE forum_id = ' . $ga_forum_id; +				$result = $db->sql_query($sql); +				$lastpost = (int) $db->sql_fetchfield('forum_last_post_time'); +				$db->sql_freeresult($result); + +				$sql_update = 'forum_posts = forum_posts + ' . $update_forum_data['forum_posts'] . ', '; +				$sql_update .= 'forum_topics_real = forum_topics_real + ' . $update_forum_data['forum_topics_real'] . ', '; +				$sql_update .= 'forum_topics = forum_topics + ' . $update_forum_data['forum_topics']; +				if ($lastpost < $update_lastpost_data['forum_last_post_time']) +				{ +					$sql_update .= ', ' . $db->sql_build_array('UPDATE', $update_lastpost_data); +				} + +				$sql = 'UPDATE ' . FORUMS_TABLE . ' +					SET ' . $sql_update . ' +					WHERE forum_id = ' . $ga_forum_id; +				_sql($sql, $errored, $error_ary); + +				// Update some forum_ids +				$table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE); +				foreach ($table_ary as $table) +				{ +					$sql = "UPDATE $table +						SET forum_id = $ga_forum_id +						WHERE " . $db->sql_in_set('topic_id', $global_announcements); +					_sql($sql, $errored, $error_ary); +				} +				unset($table_ary); +			} + +			// Allow custom profile fields in pm templates +			if (!isset($config['load_cpf_pm'])) +			{ +				set_config('load_cpf_pm', '0'); +			} + +			$no_updates = false; +		break;  	}  } - -?> | 
