aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/develop/convert_privmsgs.php
blob: df4f662c8ea01d39ccee916d0b60f6424d06a4cc (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?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);

//
// Alter table ...
//
echo "Alter tables  ... ";

echo $sql = "ALTER TABLE " . PRIVMSGS_TABLE . " 
	ADD privmsgs_enable_bbcode TINYINT(1) DEFAULT '1' NOT NULL, 
	ADD privmsgs_enable_html TINYINT(1) DEFAULT '0' NOT NULL, 
	ADD privmsgs_enable_smilies TINYINT(1) DEFAULT '1' NOT NULL, 
	ADD privmsgs_attach_sig TINYINT(1) DEFAULT '1' NOT NULL";
if( !$result = $db->sql_query($sql) )
{
	die("Couldn't alter privmsgs table");
}
echo $sql = "ALTER TABLE " . PRIVMSGS_TEXT_TABLE . " 
	ADD privmsgs_bbcode_uid CHAR(10) AFTER privmsgs_text_id";
if( !$result = $db->sql_query($sql) )
{
	die("Couldn't alter privmsgs text table");
}
echo "COMPLETE<BR>";

//
// Move bbcode ...
//
echo "Move bbcode uid's ... ";

$sql = "SELECT privmsgs_id, privmsgs_bbcode_uid 
	FROM " . PRIVMSGS_TABLE;
if( $result = $db->sql_query($sql) )
{
	$rowset = $db->sql_fetchrowset($result);

	for($i = 0; $i < count($rowset); $i++)
	{
		$sql = "UPDATE " . PRIVMSGS_TEXT_TABLE . " 
			SET privmsgs_bbcode_uid = '" . $rowset[$i]['privmsgs_bbcode_uid'] . "' 
			WHERE privmsgs_text_id = " . $rowset[$i]['privmsgs_id'];
		if( !$result = $db->sql_query($sql) )
		{
			die("Couldn't update privmsgs text bbcode - " . $i);
		}
	}

	$sql = "ALTER TABLE " . PRIVMSGS_TABLE . " 
		DROP privmsgs_bbcode_uid";
	if( !$result = $db->sql_query($sql) )
	{
		die("Couldn't alter privmsgs table - drop privmsgs_bbcode_uid");
	}
}

echo "COMPLETE<BR>";

//
// Stripslashes from titles
//
echo "Strip subject slashes ... ";

$sql = "SELECT privmsgs_subject , privmsgs_id, privmsgs_to_userid, privmsgs_from_userid   
	FROM " . PRIVMSGS_TABLE;
if( $result = $db->sql_query($sql) )
{
	$rowset = $db->sql_fetchrowset($result);

	for($i = 0; $i < count($rowset); $i++)
	{
		$sql = "UPDATE " . PRIVMSGS_TABLE . " 
			SET privmsgs_subject = '" . addslashes(stripslashes($rowset[$i]['privmsgs_subject'])) . "'  
			WHERE privmsgs_id = " . $rowset[$i]['privmsgs_id'];
		if( !$result = $db->sql_query($sql) )
		{
			die("Couldn't update subjects - $i");
		}
	}
}
echo "COMPLETE<BR>";				

//
// Update sigs
//
echo "Remove [addsig], stripslashes and update privmsgs table sig enable ...";

$sql = "SELECT privmsgs_text_id , privmsgs_text 
	FROM " . PRIVMSGS_TEXT_TABLE;
if( $result = $db->sql_query($sql) )
{
	$rowset = $db->sql_fetchrowset($result);

	$attach_sql = "";
	$non_attach_sql = "";

	for($i = 0; $i < count($rowset); $i++)
	{
		if( ereg("\[addsig]$", $rowset[$i]['privmsgs_text']))
		{
			if( $attach_sql != "" )
			{
				$attach_sql .= ", ";
			}
			$attach_sql .= $rowset[$i]['privmsgs_text_id'];

			$sql = "UPDATE " . PRIVMSGS_TEXT_TABLE . " 
				SET privmsgs_text = '" . addslashes(preg_replace("/\[addsig\]/is", "", stripslashes($rowset[$i]['privmsgs_text']))) . "'  
				WHERE privmsgs_text_id = " . $rowset[$i]['privmsgs_text_id'];
			if( !$result = $db->sql_query($sql) )
			{
				die("Couldn't update privmsgs text - " . $i);
			}

		}
		else
		{
			$sql = "UPDATE " . PRIVMSGS_TEXT_TABLE . " 
				SET privmsgs_text = '" . addslashes(stripslashes($rowset[$i]['privmsgs_text'])) . "'  
				WHERE privmsgs_text_id = " . $rowset[$i]['privmsgs_text_id'];
			if( !$result = $db->sql_query($sql) )
			{
				die("Couldn't update privmsgs text - " . $i);
			}

			if( $non_attach_sql != "" )
			{
				$non_attach_sql .= ", ";
			}
			$non_attach_sql .= $rowset[$i]['privmsgs_text_id'];
		}
	}

	if( $attach_sql != "" )
	{
		$sql = "UPDATE " . PRIVMSGS_TABLE . " 
			SET privmsgs_attach_sig = 1 
			WHERE privmsgs_id IN ($attach_sql)";
		if( !$result = $db->sql_query($sql) )
		{
			die("Couldn't update privmsgs table attach_sig - ");
		}
	}

	if( $non_attach_sql != "" )
	{
		$sql = "UPDATE " . PRIVMSGS_TABLE . " 
			SET privmsgs_attach_sig = 0 
			WHERE privmsgs_id IN ($non_attach_sql)";
		if( !$result = $db->sql_query($sql) )
		{
			die("Couldn't update privmsgs table non_attach_sig - ");
		}
	}

}

echo "COMPLETE<BR>";

$db->sql_close();

?>