aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/develop/convert_bbcodeuid.php
blob: 4a2a223e206e1bcda19310aee863524c45cf3e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php

//
// Security message:
//
// This script is potentially dangerous.
// Remove or comment the next line (die(".... ) to enable this script.
// Do NOT FORGET to either remove this script or disable it after you have used it.
//
die("Please read the first lines of this script for instructions on how to enable it");

//
// Do not change anything below this line.
//


$phpbb_root_path = "../";

include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'config.'.$phpEx);
include($phpbb_root_path . 'includes/constants.'.$phpEx);
include($phpbb_root_path . 'includes/db.'.$phpEx);

function query($sql, $errormsg)
{
	global $db;
	if(!$result = $db->sql_query($sql))
	{
		print "<br><font color=\"red\">\n";
		print "$errormsg<br>";
		$sql_error = $db->sql_error();
		print $sql_error['code'] .": ". $sql_error['message']. "<br>\n";
		print "<pre>$sql</pre>";
		print "</font>\n";
		return FALSE;
	}
	else
	{
		return $result;
	}
}

if($HTTP_GET_VARS['delete'] == 'true')
{
	$sql = "ALTER TABLE ".POSTS_TABLE."
		DROP bbcode_uid";
	query($sql, "Didn't manage to drop the bbcode_uid table in ".POSTS_TABLE);
	print "All done now. Deleted the bbcode_uid column from the posts table.<p>";
	exit;
}


$sql = "ALTER TABLE ".POSTS_TEXT_TABLE." 
	ADD bbcode_uid char(10) NOT NULL";
print "Adding bbcode_uid field to ".POSTS_TEXT_TABLE.".<br>\n";
$result = query($sql, "Couldn't get add bbcode_uid field to ".POSTS_TEXT_TABLE.".");

$sql = "
	SELECT 
		count(*) as total,
		max(post_id) as maxid 
	FROM ". POSTS_TABLE;
$result = query($sql, "Couldn't get max post_id.");
$maxid = $db->sql_fetchrow($result);
$totalposts = $maxid['total'];
$maxid = $maxid['maxid'];

$batchsize = 200;
print "Going to convert BBcode in posts with $batchsize messages at a time and $totalposts in total.<br>\n";
for($i = 0; $i <= $maxid; $i += $batchsize)
{
	$batchstart = $i + 1;
	$batchend = $i + $batchsize;
	
	print "Moving BBcode UID in post number $batchstart to $batchend<br>\n";
	flush();
	$sql = "
		SELECT 
			post_id,
			bbcode_uid
		FROM "
			.POSTS_TABLE."
		WHERE
			post_id BETWEEN $batchstart AND $batchend";
	$result = query($sql, "Couldn't get ". POSTS_TABLE .".post_id $batchstart to $batchend");
	while($row = mysql_fetch_array($result))
	{
		query("UPDATE ".POSTS_TEXT_TABLE." set bbcode_uid = '". $row['bbcode_uid']. "' WHERE post_id = ".$row['post_id'], "Was unable to update the posts text table with the BBcode_uid");
	}
}

echo "Click <a href=\"$PHP_SELF?delete=true\">HERE</a> to remove the bbcode_uid table from the POSTS table (if you didn't get any serious error messages).<p>";

$db->sql_close();

?>