⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upgrade.php

📁 这是php编的论坛的原代码
💻 PHP
📖 第 1 页 / 共 4 页
字号:
					$size = $definition['size'];

					$default = isset($definition['default']) ? "DEFAULT " . $definition['default'] : '';

					$notnull = $definition['notnull'] == 1 ? 'NOT NULL' : '';

					$auto_increment = $definition['auto_increment'] == 1 ? 'auto_increment' : '';

					$oldfield = isset($rename[$table][$field]) ? $rename[$table][$field] : $field;

					if ( !inarray($field, $current_fields) && $oldfield == $field )
					{
						// If the current is not a key of $current_def and it is not a field that is 
						// to be renamed then the field doesn't currently exist.
						$changes[] = " ADD $field " . $create_def[$table][$field];
					}
					else
					{
						$changes[] = " CHANGE $oldfield $field " . $create_def[$table][$field];
					}
				}
				
				$alter_sql .= join(',', $changes);
				unset($changes);
				unset($current_fields);
				
				$sql = "SHOW INDEX 
					FROM $table";
				$result = query($sql, "Couldn't get list of indices for table $table");

				unset($indices);

				while( $row = $db->sql_fetchrow($result) )
				{
					$indices[] = $row['Key_name'];
				}
				
				while ( list($key_name, $key_field) = each($key_def[$table]) )
				{
					if ( !inarray($key_name, $indices) )
					{
						$alter_sql .= ($key_name == 'PRIMARY') ? ", ADD PRIMARY KEY ($key_field)" : ", ADD INDEX $key_name ($key_field)";
					}
				}
				query($alter_sql, "Couldn't alter table $table");

				print "<span class=\"ok\"><b>OK</b></span><br />\n";
				flush();
			}

			end_step('convert_forums');

		case 'convert_forums':
			$sql = "SELECT * 
				FROM " . FORUMS_TABLE;
			$result = query($sql, "Couldn't get list with all forums");

			while( $row = $db->sql_fetchrow($result) )
			{
				print " * Converting forum '" . $row['forum_name'] . "' :: ";
				flush();

				// forum_access: (only concerns posting)
				//		1 = Registered users only
				//		2 = Anonymous Posting
				//		3 = Moderators/Administrators only
				switch( $row['forum_access'] )
				{
					case 1:
						// Public forum, no anonymous posting
						$auth_view			= AUTH_ALL;
						$auth_read			= AUTH_ALL;
						$auth_post			= AUTH_REG;
						$auth_reply			= AUTH_REG;
						$auth_edit			= AUTH_REG;
						$auth_delete		= AUTH_REG;
						$auth_vote			= AUTH_REG;
						$auth_pollcreate	= AUTH_REG;
						$auth_sticky		= AUTH_MOD;
						$auth_announce		= AUTH_MOD;
						break;
					case 2:
						$auth_post			= AUTH_ALL;
						$auth_reply			= AUTH_ALL;
						$auth_edit			= AUTH_REG;
						$auth_delete		= AUTH_REG;
						$auth_vote			= AUTH_ALL;
						$auth_pollcreate	= AUTH_ALL;
						$auth_sticky		= AUTH_MOD;
						$auth_announce		= AUTH_MOD;
						break;
					default:
						$auth_post			= AUTH_MOD;
						$auth_reply			= AUTH_MOD;
						$auth_edit			= AUTH_MOD;
						$auth_delete		= AUTH_MOD;
						$auth_vote			= AUTH_MOD;
						$auth_pollcreate	= AUTH_MOD;
						$auth_sticky		= AUTH_MOD;
						$auth_announce		= AUTH_MOD;
						break;
				}
				
				// Old auth structure:
				// forum_type: (only concerns viewing)
				//		0 = Public
				//		1 = Private
				switch( $row['forum_type'] )
				{
					case 0:
						$auth_view			= AUTH_ALL;
						$auth_read			= AUTH_ALL;
						break;
					default:
						//
						// Make it really private ... 
						//
						$auth_view			= AUTH_ACL;
						$auth_read			= AUTH_ACL;
						$auth_post			= AUTH_ACL;
						$auth_reply			= AUTH_ACL;
						$auth_edit			= AUTH_ACL;
						$auth_delete		= AUTH_ACL;
						$auth_vote			= AUTH_ACL;
						$auth_pollcreate	= AUTH_ACL;
						$auth_sticky		= AUTH_ACL;
						$auth_announce		= AUTH_MOD;
						break;
				}

				$sql = "UPDATE " . FORUMS_TABLE . " SET
					auth_view = $auth_view,
					auth_read = $auth_read,
					auth_post = $auth_post,
					auth_reply = $auth_reply,
					auth_edit = $auth_edit,
					auth_delete = $auth_delete,
					auth_vote = $auth_vote,
					auth_pollcreate = $auth_pollcreate,
					auth_sticky = $auth_sticky,
					auth_announce = $auth_announce
					WHERE forum_id = ". $row['forum_id'];
				query($sql, "Was unable to update forum permissions!");

				print "<span class=\"ok\"><b>OK</b></span><br />\n";
			}

			end_step('insert_themes');

		case 'insert_themes':
			print " * Inserting new values into themes table :: ";

			@reset($inserts);
			while( list($table, $inserts_table) = each($inserts) )
			{
				if ( $table == THEMES_TABLE )
				{
					$per_pct = ceil( count($inserts_table) / 40 );
					$inc = 0;

					while( list($nr, $insert) = each($inserts_table) )
					{
						query($insert, "Couldn't insert value into " . THEMES_TABLE);

						$inc++;
						if ( $inc == $per_pct )
						{
							print ".";
							flush();
							$inc = 0;
						}
					}
				}
			}

			print " <span class=\"ok\"><b>OK</b></span><br />\n";
			end_step('update_topics');

		case 'update_topics':
			$sql = "SELECT MAX(topic_id) AS max_topic 
				FROM " . TOPICS_TABLE;
			$result = query($sql, "Couldn't get max topic id");

			$row = $db->sql_fetchrow($result);

			$maxid = $row['max_topic'];

			lock_tables(1, array(TOPICS_TABLE, POSTS_TABLE));

			$batchsize = 1000;
			for($i = 0; $i <= $maxid; $i += $batchsize)
			{
				$batchstart = $i + 1;
				$batchend = $i + $batchsize;
				
				print " * Setting topic first post_id ( $batchstart to $batchend ) :: ";
				flush();

				$sql = "SELECT MIN(post_id) AS first_post_id, topic_id
					FROM " . POSTS_TABLE . "
					WHERE topic_id 
						BETWEEN $batchstart 
							AND $batchend 
					GROUP BY topic_id 
					ORDER BY topic_id ASC";
				$result = query($sql, "Couldn't get post id data");

				$per_pct = ceil( $db->sql_numrows($result) / 40 );
				$inc = 0;

				if ( $row = $db->sql_fetchrow($result) )
				{
					do
					{
						$sql = "UPDATE " . TOPICS_TABLE . " 
							SET topic_first_post_id = " . $row['first_post_id'] . " 
							WHERE topic_id = " . $row['topic_id'];
						query($sql, "Couldn't update topic first post id in topic :: $topic_id");

						$inc++;
						if ( $inc == $per_pct )
						{
							print ".";
							flush();
							$inc = 0;
						}
					}
					while ( $row = $db->sql_fetchrow($result) );
				}

				print " <span class=\"ok\"><b>OK</b></span><br />\n";
			}

			lock_tables(0);
			end_step('final_configuration');

		case 'final_configuration':
			//
			// Update forum last post information
			//
			$sql = "SELECT forum_id, forum_name 
				FROM " . FORUMS_TABLE;
			$f_result = query($sql, "Couldn't obtain forum_ids");

			while( $forum_row = $db->sql_fetchrow($f_result) )
			{
				print " * Updating '" . $forum_row['forum_name'] . "' post info :: ";
				flush();

				$id = $forum_row['forum_id'];

				$sql = "SELECT MIN(p.post_id) AS first_post, MAX(p.post_id) AS last_post
					FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
					WHERE p.forum_id = $id
						AND p.topic_id = t.topic_id";
				$result = query($sql, "Could not get post ID forum post information :: $id");

				if ( $row = $db->sql_fetchrow($result) )
				{
					$first_post = ( $row['first_post'] ) ? $row['first_post'] : 0;
					$last_post = ($row['last_post']) ? $row['last_post'] : 0;
				}
				else
				{
					$first_post = 0;
					$last_post = 0;
				}

				$sql = "SELECT COUNT(post_id) AS total
					FROM " . POSTS_TABLE . "
					WHERE forum_id = $id";
				$result = query($sql, "Could not get post count forum post information :: $id");

				if ( $row = $db->sql_fetchrow($result) )
				{
					$total_posts = ($row['total']) ? $row['total'] : 0;
				}
				else
				{
					$total_posts = 0;
				}

				$sql = "SELECT COUNT(topic_id) AS total
					FROM " . TOPICS_TABLE . "
					WHERE forum_id = $id 
						AND topic_status <> " . TOPIC_MOVED;
				$result = query($sql, "Could not get topic count forum post information :: $id");

				if ( $row = $db->sql_fetchrow($result) )
				{
					$total_topics = ($row['total']) ? $row['total'] : 0;
				}
				else
				{
					$total_topics = 0;
				}

				$sql = "UPDATE " . FORUMS_TABLE . "
					SET forum_last_post_id = $last_post, forum_posts = $total_posts, forum_topics = $total_topics
					WHERE forum_id = $id";
				query($sql, "Could not update forum post information :: $id");

				print "<span class=\"ok\"><b>OK</b></span><br />\n";
			}

			print "<br />\n * Update default user and finalise configuration :: ";
			flush();

			//
			// Update the default admin user with their information.
			//
			$sql = "SELECT MIN(user_regdate) AS oldest_time 
				FROM " . USERS_TABLE . " 
				WHERE user_regdate > 0 AND user_id > 0";
			$result = query($sql, "Couldn't obtain oldest post time");

			$row = $db->sql_fetchrow($result);

			$sql = "INSERT INTO " . $table_prefix . "config (config_name, config_value) 
				VALUES ('board_startdate', " . $row['oldest_time']  . ")";
			query($sql, "Couldn't insert board_startdate");

			$sql = "UPDATE " . $table_prefix . "config 
				SET config_value = '" . $server_name . "' 
				WHERE config_name = 'server_name' 
					OR config_name = 'cookie_domain'";
			query($sql, "Couldn't insert Board Server domain");

			$sql = "UPDATE " . $table_prefix . "config 
				SET config_value = '" . $server_port . "'
				WHERE config_name = 'server_port'";
			query($sql, "Couldn't insert Board server port");
			
			$sql = "UPDATE " . $table_prefix . "config 
				SET config_value = '" . $board_email . "'
				WHERE config_name = 'board_email'";
			query($sql, "Couldn't insert Board admin email");
			
			$sql = "UPDATE " . $table_prefix . "config 
				SET config_value = '" . $script_path . "'
				WHERE config_name = 'script_path'";
			query($sql, "Couldn't insert Board script path");
			
			//
			// Change session table to HEAP if MySQL version matches
			//
			$sql = "SELECT VERSION() AS mysql_version";
			$result = query($sql, "Couldn't obtain MySQL Version");

			$row = $db->sql_fetchrow($result);

			$version = $row['mysql_version'];

			if ( preg_match("/^(3\.23)|(4\.)/", $version) )
			{
				$sql = "ALTER TABLE " . $table_prefix . "sessions 
					TYPE=HEAP MAX_ROWS=500";
				$db->sql_query($sql);
			}

			echo "<span class=\"ok\"><b>OK</b></span><br />\n";
			end_step('drop_fields');

		case 'drop_fields':
			$fields = array(
				BANLIST_TABLE => array("ban_start", "ban_end", "ban_time_type"),
				FORUMS_TABLE => array("forum_access", "forum_moderator", "forum_type"), 
				PRIVMSGS_TABLE => array("msg_text"), 
				RANKS_TABLE => array("rank_max"), 
				SMILIES_TABLE => array("emotion"),
				TOPICS_TABLE => array("topic_notify")
			);

			while( list($table, $field_data) = each($fields) )
			{
				for($i = 0; $i < count($field_data); $i++)
				{
					print " * Drop field '" . $field_data[$i] . "' in '$table' :: ";
					flush();

					$sql = "ALTER TABLE $table 
						DROP COLUMN " . $field_data[$i];
					query($sql, "Couldn't drop field :: " . $field_data[$i] . " from table :: $table");

					print "<span class=\"ok\"><b>OK</b></span><br />\n";

				}
			}

			end_step('drop_tables');

		case 'drop_tables':
			$drop_tables = array('access', 'forum_access', 'forum_mods', 'headermetafooter', 'whosonline', $table_prefix . 'old_config');

			for($i = 0; $i < count($drop_tables); $i++)
			{
				print " * Dropping table '" . $drop_tables[$i] . "' :: ";
				flush();

				$sql = "DROP TABLE " . $drop_tables[$i];
				query($sql, "Couldn't drop table :: " . $drop_tables[$i]);

				print "<span class=\"ok\"><b>OK</b></span><br />\n";
			}

			end_step('fulltext_search_indexing');

		case 'fulltext_search_indexing':
			//
			// Generate search word list
			//
			// Fetch a batch of posts_text entries
			//
			$sql = "SELECT COUNT(*) as total, MAX(post_id) as max_post_id 
				FROM " . POSTS_TEXT_TABLE;
			$result = query($sql, "Couldn't get post count totals");

			$max_post_id = $db->sql_fetchrow($result);

			$totalposts = $max_post_id['total'];
			$max_post_id = $max_post_id['max_post_id'];
			$per_percent = round(( $totalposts / 500 ) * 10);

			$postcounter = ( !isset($HTTP_GET_VARS['batchstart']) ) ? 0 : $HTTP_GET_VARS['batchstart'];

			$batchsize = 150; // Process this many posts per loop
			$batchcount = 0;
			$total_percent = 0;

			for(;$postcounter <= $max_post_id; $postcounter += $batchsize)
			{
				$batchstart = $postcounter + 1;
				$batchend = $postcounter + $batchsize;
				$batchcount++;

				print " * Fulltext Indexing ( $batchstart to $batchend ) :: ";
				flush();
				
				$sql = "SELECT *
					FROM " . POSTS_TEXT_TABLE ."
					WHERE post_id 
						BETWEEN $batchstart 
							AND $batchend";
				$posts_result = query($sql, "Couldn't obtain post_text");

				$per_pct = ceil( $db->sql_numrows($posts_result) / 40 );
				$inc = 0;

				if ( $row = $db->sql_fetchrow($posts_result) )
				{ 
					do
					{
						add_search_words('global', $row['post_id'], $row['post_text'], $row['post_subject']);

						$inc++;
						if ( $inc == $per_pct )
						{
							print ".";
							flush();
							$inc = 0;
						}
					}
					while( $row = $db->sql_fetchrow($posts_result) );
				}

				$db->sql_freeresult($posts_result);
				
				// Remove common words after the first 2 batches and after every 4th batch after that.
				if ( $batchcount % 4 == 3 )
				{
					remove_common('global', 0.4);
				}

				print " <span class=\"ok\"><b>OK</b></span><br />\n";
			}

			echo "\n<br /><br />\n\n<font size=\"+3\"><b>UPGRADE COMPLETED</b></font><br />\n";
	}
}

print "<br />If the upgrade completed without error you may click <a href=\"index.$phpEx\">Here</a> to proceed to the index<br />";

common_footer();

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -