root / tags / release_2_0_2 / phpBB / upgrade.php

View | Annotate | Download (55.5 KB)

1 1242 bartvb
<?php
2 1242 bartvb
/***************************************************************************
3 1242 bartvb
*                                  upgrade.php
4 1242 bartvb
*                              -------------------
5 1242 bartvb
*     begin                : Wed Sep 05 2001
6 1242 bartvb
*     copyright            : (C) 2001 The phpBB Group
7 1242 bartvb
*     email                : support@phpbb.com
8 1242 bartvb
*
9 1753 psotfx
*     $Id$
10 1242 bartvb
*
11 1242 bartvb
****************************************************************************/
12 1242 bartvb
13 1242 bartvb
/***************************************************************************
14 1242 bartvb
 *
15 1242 bartvb
 *   This program is free software; you can redistribute it and/or modify
16 1242 bartvb
 *   it under the terms of the GNU General Public License as published by
17 1242 bartvb
 *   the Free Software Foundation; either version 2 of the License, or
18 1242 bartvb
 *   (at your option) any later version.
19 1242 bartvb
 *
20 1242 bartvb
 ***************************************************************************/
21 1752 psotfx
22 2305 psotfx
define('IN_PHPBB', true);
23 2305 psotfx
24 1299 the_systech
if ( !defined('INSTALLING') )
25 1299 the_systech
{
26 2093 psotfx
        error_reporting  (E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
27 2093 psotfx
        set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
28 2093 psotfx
29 1299 the_systech
        //
30 1299 the_systech
        // If we are being called from the install script then we don't need these
31 1299 the_systech
        // as they are already included.
32 1299 the_systech
        //
33 1299 the_systech
        include('extension.inc');
34 1299 the_systech
        include('config.'.$phpEx);
35 1299 the_systech
        include('includes/constants.'.$phpEx);
36 1558 bartvb
        include('includes/functions.'.$phpEx);
37 2088 psotfx
38 2088 psotfx
        if( defined("PHPBB_INSTALLED") )
39 2088 psotfx
        {
40 2575 psotfx
                $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
41 2575 psotfx
                header($header_location . " index.$phpEx");
42 2088 psotfx
                exit;
43 2088 psotfx
        }
44 1299 the_systech
}
45 1752 psotfx
46 1752 psotfx
//
47 1438 bartvb
// Force the DB type to be MySQL
48 1752 psotfx
//
49 1438 bartvb
$dbms = 'mysql';
50 1752 psotfx
51 1242 bartvb
include('includes/db.'.$phpEx);
52 1242 bartvb
include('includes/bbcode.'.$phpEx);
53 2305 psotfx
include('includes/functions_search.'.$phpEx);
54 1242 bartvb
55 1438 bartvb
set_time_limit(0); // Unlimited execution time
56 1242 bartvb
57 1242 bartvb
$months = array(
58 1242 bartvb
        'Jan' => 1,
59 1242 bartvb
        'Feb' => 2,
60 1242 bartvb
        'Mar' => 3,
61 1242 bartvb
        'Apr' => 4,
62 1242 bartvb
        'May' => 5,
63 1242 bartvb
        'Jun' => 6,
64 1242 bartvb
        'Jul' => 7,
65 1242 bartvb
        'Aug' => 8,
66 1242 bartvb
        'Sep' => 9,
67 1242 bartvb
        'Sept' => 9,
68 1242 bartvb
        'Oct' => 10,
69 1242 bartvb
        'Nov' => 11,
70 1242 bartvb
        'Dec' => 12
71 1752 psotfx
);
72 1242 bartvb
73 1752 psotfx
// ---------------
74 1752 psotfx
// Begin functions
75 1752 psotfx
//
76 1242 bartvb
function common_header()
77 1242 bartvb
{
78 1242 bartvb
?>
79 2093 psotfx
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
80 2093 psotfx
<html>
81 2093 psotfx
<head>
82 2093 psotfx
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
83 2093 psotfx
<meta http-equiv="Content-Style-Type" content="text/css">
84 2093 psotfx
<style type="text/css">
85 2093 psotfx
<!--
86 2093 psotfx
/* Specifiy background images for selected styles
87 2093 psotfx
   This can't be done within the external style sheet as NS4 sees image paths relative to
88 2093 psotfx
   the page which called the style sheet (i.e. this page in the root phpBB directory)
89 2093 psotfx
   whereas all other browsers see image paths relative to the style sheet. Stupid NS again!
90 2093 psotfx
*/
91 2093 psotfx
TH                        { background-image: url(templates/subSilver/images/cellpic3.gif) }
92 2093 psotfx
TD.cat                { background-image: url(templates/subSilver/images/cellpic1.gif) }
93 2093 psotfx
TD.rowpic        { background-image: url(templates/subSilver/images/cellpic2.jpg); background-repeat: repeat-y }
94 2093 psotfx
td.icqback        { background-image: url(templates/subSilver/images/icon_icq_add.gif); background-repeat: no-repeat }
95 2093 psotfx
TD.catHead,TD.catSides,TD.catLeft,TD.catRight,TD.catBottom { background-image: url(templates/subSilver/images/cellpic1.gif) }
96 2093 psotfx
97 2093 psotfx
font,th,td,p,body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11pt }
98 2093 psotfx
a:link,a:active,a:visited { font-family: Verdana, Arial, Helvetica, sans-serif; color : #006699; font-size:11pt }
99 2093 psotfx
a:hover                { font-family: Verdana, Arial, Helvetica, sans-serif;  text-decoration: underline; color : #DD6900; font-size:11pt }
100 2093 psotfx
hr        { height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;}
101 2093 psotfx
102 2093 psotfx
.maintitle,h1,h2        {font-weight: bold; font-size: 22px; font-family: "Trebuchet MS",Verdana, Arial, Helvetica, sans-serif; text-decoration: none; line-height : 120%; color : #000000;}
103 2093 psotfx
104 2093 psotfx
.ok {color:green}
105 2093 psotfx
106 2093 psotfx
/* Import the fancy styles for IE only (NS4.x doesn't use the @import function) */
107 2093 psotfx
@import url("templates/subSilver/formIE.css");
108 2093 psotfx
-->
109 2093 psotfx
</style>
110 2093 psotfx
</head>
111 2093 psotfx
<body bgcolor="#FFFFFF" text="#000000" link="#006699" vlink="#5584AA">
112 2093 psotfx
113 2093 psotfx
<table width="100%" border="0" cellspacing="0" cellpadding="10" align="center">
114 2093 psotfx
        <tr>
115 2093 psotfx
                <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
116 2093 psotfx
                        <tr>
117 2093 psotfx
                                <td><img src="templates/subSilver/images/logo_phpBB.gif" border="0" alt="Forum Home" vspace="1" /></td>
118 2093 psotfx
                                <td align="center" width="100%" valign="middle"><span class="maintitle">Upgrading to phpBB 2.0</span></td>
119 2093 psotfx
                        </tr>
120 2093 psotfx
                </table></td>
121 2093 psotfx
        </tr>
122 2093 psotfx
</table>
123 2093 psotfx
124 2093 psotfx
<br clear="all" />
125 2093 psotfx
126 1242 bartvb
<?
127 1242 bartvb
        return;
128 1242 bartvb
}
129 1242 bartvb
130 1752 psotfx
function common_footer()
131 1752 psotfx
{
132 1752 psotfx
?>
133 2093 psotfx
134 2093 psotfx
<br clear="all" />
135 2093 psotfx
136 2093 psotfx
</body>
137 2093 psotfx
</html>
138 1752 psotfx
<?
139 1752 psotfx
        return;
140 1752 psotfx
}
141 1752 psotfx
142 1242 bartvb
function query($sql, $errormsg)
143 1242 bartvb
{
144 1242 bartvb
        global $db;
145 2093 psotfx
146 2093 psotfx
        if ( !($result = $db->sql_query($sql)) )
147 1242 bartvb
        {
148 1242 bartvb
                print "<br><font color=\"red\">\n";
149 1242 bartvb
                print "$errormsg<br>";
150 2093 psotfx
151 1242 bartvb
                $sql_error = $db->sql_error();
152 1242 bartvb
                print $sql_error['code'] .": ". $sql_error['message']. "<br>\n";
153 2093 psotfx
154 1242 bartvb
                print "<pre>$sql</pre>";
155 1242 bartvb
                print "</font>\n";
156 2093 psotfx
157 1242 bartvb
                return FALSE;
158 1242 bartvb
        }
159 1242 bartvb
        else
160 1242 bartvb
        {
161 1242 bartvb
                return $result;
162 1242 bartvb
        }
163 1242 bartvb
}
164 1242 bartvb
165 2511 psotfx
function smiley_replace($text = '')
166 1558 bartvb
{
167 1558 bartvb
        global $db;
168 1558 bartvb
169 1752 psotfx
        static $search, $replace;
170 1558 bartvb
171 1558 bartvb
        // Did we get the smiley info in a previous call?
172 2093 psotfx
        if ( !is_array($search) )
173 1558 bartvb
        {
174 1752 psotfx
                $sql = "SELECT code, smile_url
175 1752 psotfx
                        FROM smiles";
176 1558 bartvb
                $result = query($sql, "Unable to get list of smilies from the DB");
177 1752 psotfx
178 1752 psotfx
                $smilies = $db->sql_fetchrowset($result);
179 2093 psotfx
                @usort($smilies, 'smiley_sort');
180 1752 psotfx
181 1752 psotfx
                $search = array();
182 1752 psotfx
                $replace = array();
183 1752 psotfx
                for($i = 0; $i < count($smilies); $i++)
184 1558 bartvb
                {
185 1752 psotfx
                        $search[] = '/<IMG SRC=".*?\/' . phpbb_preg_quote($smilies[$i]['smile_url'], '/') .'">/i';
186 1752 psotfx
                        $replace[] = $smilies[$i]['code'];
187 1558 bartvb
                }
188 1558 bartvb
        }
189 1752 psotfx
190 2511 psotfx
        return ( $text != '' ) ? preg_replace($search, $replace, $text) : '';
191 1558 bartvb
192 1558 bartvb
}
193 1558 bartvb
194 1242 bartvb
function get_schema()
195 1242 bartvb
{
196 1438 bartvb
        global $table_prefix;
197 1752 psotfx
198 1438 bartvb
        $schemafile = file('db/schemas/mysql_schema.sql');
199 1242 bartvb
        $tabledata = 0;
200 1752 psotfx
201 1242 bartvb
        for($i=0; $i < count($schemafile); $i++)
202 1242 bartvb
        {
203 1242 bartvb
                $line = $schemafile[$i];
204 1752 psotfx
205 2511 psotfx
                if ( preg_match('/^CREATE TABLE (\w+)/i', $line, $matches) )
206 1242 bartvb
                {
207 1438 bartvb
                        // Start of a new table definition, set some variables and go to the next line.
208 1242 bartvb
                        $tabledata = 1;
209 1438 bartvb
                        // Replace the 'phpbb_' prefix by the user defined prefix.
210 2511 psotfx
                        $table = str_replace('phpbb_', $table_prefix, $matches[1]);
211 1438 bartvb
                        $table_def[$table] = "CREATE TABLE $table (\n";
212 1242 bartvb
                        continue;
213 1242 bartvb
                }
214 1752 psotfx
215 2511 psotfx
                if ( preg_match('/^\);/', $line) )
216 1242 bartvb
                {
217 1438 bartvb
                        // End of the table definition
218 1438 bartvb
                        // After this we will skip everything until the next 'CREATE' line
219 1242 bartvb
                        $tabledata = 0;
220 2511 psotfx
                        $table_def[$table] .= ')'; // We don't need the closing semicolon
221 1242 bartvb
                }
222 1752 psotfx
223 2093 psotfx
                if ( $tabledata == 1 )
224 1242 bartvb
                {
225 1438 bartvb
                        // We are inside a table definition, parse this line.
226 1438 bartvb
                        // Add the current line to the complete table definition:
227 1242 bartvb
                        $table_def[$table] .= $line;
228 2511 psotfx
                        if ( preg_match('/^\s*(\w+)\s+(\w+)\(([\d,]+)\)(.*)$/', $line, $matches) )
229 1438 bartvb
                        {
230 1438 bartvb
                                // This is a column definition
231 1438 bartvb
                                $field = $matches[1];
232 1438 bartvb
                                $type = $matches[2];
233 1438 bartvb
                                $size = $matches[3];
234 2093 psotfx
235 2511 psotfx
                                preg_match('/DEFAULT (NULL|\'.*?\')[,\s](.*)$/i', $matches[4], $match);
236 1438 bartvb
                                $default = $match[1];
237 2093 psotfx
238 2511 psotfx
                                $notnull = ( preg_match('/NOT NULL/i', $matches[4]) ) ? 1 : 0;
239 2511 psotfx
                                $auto_increment = ( preg_match('/auto_increment/i', $matches[4]) ) ? 1 : 0;
240 2093 psotfx
241 1438 bartvb
                                $field_def[$table][$field] = array(
242 1438 bartvb
                                        'type' => $type,
243 1438 bartvb
                                        'size' => $size,
244 1438 bartvb
                                        'default' => $default,
245 1438 bartvb
                                        'notnull' => $notnull,
246 1438 bartvb
                                        'auto_increment' => $auto_increment
247 1438 bartvb
                                );
248 1242 bartvb
                        }
249 1438 bartvb
250 2511 psotfx
                        if ( preg_match('/\s*PRIMARY\s+KEY\s*\((.*)\).*/', $line, $matches) )
251 1242 bartvb
                        {
252 1438 bartvb
                                // Primary key
253 1438 bartvb
                                $key_def[$table]['PRIMARY'] = $matches[1];
254 1242 bartvb
                        }
255 2511 psotfx
                        else if ( preg_match('/\s*KEY\s+(\w+)\s*\((.*)\)/', $line, $matches) )
256 1242 bartvb
                        {
257 1438 bartvb
                                // Normal key
258 1438 bartvb
                                $key_def[$table][$matches[1]] = $matches[2];
259 1242 bartvb
                        }
260 2511 psotfx
                        else if ( preg_match('/^\s*(\w+)\s*(.*?),?\s*$/', $line, $matches) )
261 1438 bartvb
                        {
262 1438 bartvb
                                // Column definition
263 1438 bartvb
                                $create_def[$table][$matches[1]] = $matches[2];
264 1438 bartvb
                        }
265 1438 bartvb
                        else
266 1438 bartvb
                        {
267 1438 bartvb
                                // It's a bird! It's a plane! It's something we didn't expect ;(
268 1438 bartvb
                        }
269 1242 bartvb
                }
270 1242 bartvb
        }
271 2093 psotfx
272 1242 bartvb
        $schema['field_def'] = $field_def;
273 1242 bartvb
        $schema['table_def'] = $table_def;
274 1438 bartvb
        $schema['create_def'] = $create_def;
275 1438 bartvb
        $schema['key_def'] = $key_def;
276 2093 psotfx
277 1242 bartvb
        return $schema;
278 1242 bartvb
}
279 1242 bartvb
280 1242 bartvb
function get_inserts()
281 1242 bartvb
{
282 1438 bartvb
        global $table_prefix;
283 1752 psotfx
284 2511 psotfx
        $insertfile = file('db/schemas/mysql_basic.sql');
285 1752 psotfx
286 2093 psotfx
        for($i = 0; $i < count($insertfile); $i++)
287 1242 bartvb
        {
288 2511 psotfx
                if ( preg_match('/(INSERT INTO (\w+)\s.*);/i', str_replace('phpbb_', $table_prefix, $insertfile[$i]), $matches) )
289 1242 bartvb
                {
290 1242 bartvb
                        $returnvalue[$matches[2]][] = $matches[1];
291 1242 bartvb
                }
292 1242 bartvb
        }
293 1752 psotfx
294 1242 bartvb
        return $returnvalue;
295 1242 bartvb
}
296 1242 bartvb
297 1242 bartvb
function lock_tables($state, $tables= '')
298 1242 bartvb
{
299 2093 psotfx
        if ( $state == 1 )
300 1242 bartvb
        {
301 2093 psotfx
                if ( is_array($tables) )
302 1242 bartvb
                {
303 1242 bartvb
                        $tables = join(' WRITE, ', $tables);
304 1242 bartvb
                }
305 2093 psotfx
306 2093 psotfx
                query("LOCK TABLES $tables WRITE", "Couldn't do: $sql");
307 1242 bartvb
        }
308 1242 bartvb
        else
309 1242 bartvb
        {
310 1242 bartvb
                query("UNLOCK TABLES", "Couldn't unlock all tables");
311 1242 bartvb
        }
312 1242 bartvb
}
313 1242 bartvb
314 2093 psotfx
function output_table_content($content)
315 2093 psotfx
{
316 2093 psotfx
        echo $content . "\n";
317 1242 bartvb
318 1242 bartvb
        return;
319 1242 bartvb
}
320 1242 bartvb
321 1242 bartvb
//
322 1242 bartvb
// Nathan's bbcode2 conversion routines
323 1242 bartvb
//
324 2093 psotfx
function bbdecode($message)
325 2093 psotfx
{
326 2093 psotfx
        // Undo [code]
327 2511 psotfx
        $code_start_html = '<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-1>Code:</font><HR></TD></TR><TR><TD><FONT SIZE=-1><PRE>';
328 2511 psotfx
        $code_end_html = '</PRE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode End -->';
329 2511 psotfx
        $message = str_replace($code_start_html, '[code]', $message);
330 2511 psotfx
        $message = str_replace($code_end_html, '[/code]', $message);
331 1242 bartvb
332 2093 psotfx
        // Undo [quote]
333 2511 psotfx
        $quote_start_html = '<!-- BBCode Quote Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-1>Quote:</font><HR></TD></TR><TR><TD><FONT SIZE=-1><BLOCKQUOTE>';
334 2511 psotfx
        $quote_end_html = '</BLOCKQUOTE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->';
335 2511 psotfx
        $message = str_replace($quote_start_html, '[quote]', $message);
336 2511 psotfx
        $message = str_replace($quote_end_html, '[/quote]', $message);
337 1242 bartvb
338 2093 psotfx
        // Undo [b] and [i]
339 2093 psotfx
        $message = preg_replace("#<!-- BBCode Start --><B>(.*?)</B><!-- BBCode End -->#s", "[b]\\1[/b]", $message);
340 2093 psotfx
        $message = preg_replace("#<!-- BBCode Start --><I>(.*?)</I><!-- BBCode End -->#s", "[i]\\1[/i]", $message);
341 1242 bartvb
342 2093 psotfx
        // Undo [url] (long form)
343 2093 psotfx
        $message = preg_replace("#<!-- BBCode u2 Start --><A HREF=\"([a-z]+?://)(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode u2 End -->#s", "[url=\\1\\2]\\3[/url]", $message);
344 1242 bartvb
345 2093 psotfx
        // Undo [url] (short form)
346 2093 psotfx
        $message = preg_replace("#<!-- BBCode u1 Start --><A HREF=\"([a-z]+?://)(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode u1 End -->#s", "[url]\\3[/url]", $message);
347 1242 bartvb
348 2093 psotfx
        // Undo [email]
349 2093 psotfx
        $message = preg_replace("#<!-- BBCode Start --><A HREF=\"mailto:(.*?)\">(.*?)</A><!-- BBCode End -->#s", "[email]\\1[/email]", $message);
350 1242 bartvb
351 2093 psotfx
        // Undo [img]
352 2093 psotfx
        $message = preg_replace("#<!-- BBCode Start --><IMG SRC=\"(.*?)\" BORDER=\"0\"><!-- BBCode End -->#s", "[img]\\1[/img]", $message);
353 1242 bartvb
354 2093 psotfx
        // Undo lists (unordered/ordered)
355 1242 bartvb
356 2093 psotfx
        // <li> tags:
357 2511 psotfx
        $message = str_replace('<!-- BBCode --><LI>', '[*]', $message);
358 1242 bartvb
359 2093 psotfx
        // [list] tags:
360 2511 psotfx
        $message = str_replace('<!-- BBCode ulist Start --><UL>', '[list]', $message);
361 1242 bartvb
362 2093 psotfx
        // [list=x] tags:
363 2511 psotfx
        $message = preg_replace('#<!-- BBCode olist Start --><OL TYPE=([A1])>#si', "[list=\\1]", $message);
364 1242 bartvb
365 2093 psotfx
        // [/list] tags:
366 2511 psotfx
        $message = str_replace('</UL><!-- BBCode ulist End -->', '[/list]', $message);
367 2511 psotfx
        $message = str_replace('</OL><!-- BBCode olist End -->', '[/list]', $message);
368 1242 bartvb
369 2093 psotfx
        return $message;
370 1242 bartvb
}
371 1242 bartvb
372 1242 bartvb
//
373 1242 bartvb
// Alternative for in_array() which is only available in PHP4
374 1242 bartvb
//
375 2093 psotfx
function inarray($needle, $haystack)
376 2093 psotfx
{
377 2093 psotfx
        for( $i = 0 ; $i < sizeof($haystack) ; $i++ )
378 1242 bartvb
        {
379 2093 psotfx
                if ( $haystack[$i] == $needle )
380 1242 bartvb
                {
381 1242 bartvb
                        return true;
382 1242 bartvb
                }
383 1242 bartvb
        }
384 2093 psotfx
385 2093 psotfx
        return false;
386 1242 bartvb
}
387 1242 bartvb
388 1242 bartvb
function end_step($next)
389 1242 bartvb
{
390 1242 bartvb
        global $debug;
391 2093 psotfx
392 2093 psotfx
        print "<hr /><a href=\"$PHP_SELF?next=$next\">Next step: <b>$next</b></a><br /><br />\n";
393 1242 bartvb
}
394 1242 bartvb
//
395 1752 psotfx
// End functions
396 1752 psotfx
// -------------
397 1242 bartvb
398 1242 bartvb
399 1752 psotfx
//
400 1242 bartvb
// Start at the beginning if the user hasn't specified a specific starting point.
401 1752 psotfx
//
402 1752 psotfx
$next = ( isset($HTTP_GET_VARS['next']) ) ? $HTTP_GET_VARS['next'] : 'start';
403 1242 bartvb
404 1242 bartvb
// If debug is set we'll do all steps in one go.
405 1752 psotfx
$debug = 1;
406 1242 bartvb
407 1438 bartvb
// Parse the MySQL schema file into some arrays.
408 1438 bartvb
$schema = get_schema();
409 2093 psotfx
410 1438 bartvb
$table_def = $schema['table_def'];
411 1438 bartvb
$field_def = $schema['field_def'];
412 1438 bartvb
$key_def = $schema['key_def'];
413 1438 bartvb
$create_def = $schema['create_def'];
414 1438 bartvb
415 1752 psotfx
//
416 1752 psotfx
// Get mysql_basic data
417 1752 psotfx
//
418 1752 psotfx
$inserts = get_inserts();
419 1558 bartvb
420 1752 psotfx
//
421 1752 psotfx
// Get smiley data
422 1752 psotfx
//
423 1752 psotfx
smiley_replace();
424 1752 psotfx
425 2093 psotfx
common_header();
426 2093 psotfx
427 2093 psotfx
if ( !empty($next) )
428 1242 bartvb
{
429 1242 bartvb
        switch($next)
430 1242 bartvb
        {
431 1752 psotfx
                case 'start':
432 2093 psotfx
                        end_step('initial_drops');
433 2093 psotfx
434 2093 psotfx
                case 'initial_drops':
435 2093 psotfx
                        print " * Dropping sessions and themes tables :: ";
436 1766 psotfx
                        flush();
437 1242 bartvb
438 1766 psotfx
                        query("DROP TABLE sessions", "Couldn't drop table 'sessions'");
439 1766 psotfx
                        query("DROP TABLE themes", "Couldn't drop table 'themes'");
440 1766 psotfx
441 2093 psotfx
                        print "<span class=\"ok\"><b>OK</b></span><br />\n";
442 1766 psotfx
443 1752 psotfx
                        end_step('mod_old_tables');
444 1242 bartvb
445 1752 psotfx
                case 'mod_old_tables':
446 1752 psotfx
                        $modtables = array(
447 1752 psotfx
                                "banlist" => "banlist",
448 1752 psotfx
                                "catagories" => "categories",
449 1752 psotfx
                                "config" => "old_config",
450 1752 psotfx
                                "forums" => "forums",
451 1752 psotfx
                                "disallow" => "disallow",
452 1752 psotfx
                                "posts" => "posts",
453 1752 psotfx
                                "posts_text" => "posts_text",
454 1752 psotfx
                                "priv_msgs" => "privmsgs",
455 1752 psotfx
                                "ranks" => "ranks",
456 1752 psotfx
                                "smiles" => "smilies",
457 1752 psotfx
                                "topics" => "topics",
458 1752 psotfx
                                "users" => "users",
459 1752 psotfx
                                "words" => "words"
460 1752 psotfx
                        );
461 1752 psotfx
462 1752 psotfx
                        while( list($old, $new) = each($modtables) )
463 1438 bartvb
                        {
464 1752 psotfx
                                $result = query("SHOW INDEX FROM $old", "Couldn't get list of indices for table $old");
465 1752 psotfx
466 1752 psotfx
                                while( $row = $db->sql_fetchrow($result) )
467 1438 bartvb
                                {
468 1752 psotfx
                                        $index = $row['Key_name'];
469 2093 psotfx
                                        if ( $index != 'PRIMARY' )
470 1752 psotfx
                                        {
471 1752 psotfx
                                                query("ALTER TABLE $old DROP INDEX $index", "Couldn't DROP INDEX $old.$index");
472 1752 psotfx
                                        }
473 1438 bartvb
                                }
474 1752 psotfx
475 1752 psotfx
                                // Rename table
476 1752 psotfx
                                $new = $table_prefix . $new;
477 1752 psotfx
478 2093 psotfx
                                print " * Renaming '$old' to '$new' :: ";
479 2093 psotfx
                                flush();
480 1752 psotfx
                                query("ALTER TABLE $old RENAME $new", "Failed to rename $old to $new");
481 2093 psotfx
                                print "<span class=\"ok\"><b>OK</b></span><br />\n";
482 1752 psotfx
483 1438 bartvb
                        }
484 1752 psotfx
                        end_step('create_tables');
485 1752 psotfx
486 1752 psotfx
                case 'create_tables':
487 1752 psotfx
                        // Create array with tables in 'old' database
488 1752 psotfx
                        $result = query('SHOW TABLES', "Couldn't get list of current tables");
489 1438 bartvb
490 1752 psotfx
                        while( $table = $db->sql_fetchrow($result) )
491 1752 psotfx
                        {
492 1752 psotfx
                                $currenttables[] = $table[0];
493 1752 psotfx
                        }
494 1438 bartvb
495 1752 psotfx
                        // Check what tables we need to CREATE
496 1752 psotfx
                        while( list($table, $definition) = each($table_def) )
497 1242 bartvb
                        {
498 2093 psotfx
                                if ( !inarray($table, $currenttables) )
499 1752 psotfx
                                {
500 2093 psotfx
                                        print " * Creating $table :: ";
501 1752 psotfx
502 1752 psotfx
                                        query($definition, "Couldn't create table $table");
503 1752 psotfx
504 2093 psotfx
                                        print "<span class=\"ok\"><b>OK</b></span><br />\n";
505 1752 psotfx
                                }
506 1242 bartvb
                        }
507 1752 psotfx
508 1752 psotfx
                        end_step('create_config');
509 1752 psotfx
510 1752 psotfx
                case 'create_config':
511 2093 psotfx
                        print " * Inserting new values into new layout config table :: ";
512 1752 psotfx
513 1752 psotfx
                        @reset($inserts);
514 1752 psotfx
                        while( list($table, $inserts_table) = each($inserts) )
515 1242 bartvb
                        {
516 2093 psotfx
                                if ( $table == CONFIG_TABLE )
517 1242 bartvb
                                {
518 2093 psotfx
                                        $per_pct = ceil( count($inserts_table) / 40 );
519 2093 psotfx
                                        $inc = 0;
520 2093 psotfx
521 1752 psotfx
                                        while( list($nr, $insert) = each($inserts_table) )
522 1752 psotfx
                                        {
523 1752 psotfx
                                                query($insert, "Couldn't insert value into config table");
524 1752 psotfx
525 2093 psotfx
                                                $inc++;
526 2093 psotfx
                                                if ( $inc == $per_pct )
527 2093 psotfx
                                                {
528 2093 psotfx
                                                        print ".";
529 2093 psotfx
                                                        flush();
530 2093 psotfx
                                                        $inc = 0;
531 2093 psotfx
                                                }
532 1752 psotfx
                                        }
533 1242 bartvb
                                }
534 1242 bartvb
                        }
535 1752 psotfx
536 2093 psotfx
                        print " <span class=\"ok\"><b>OK</b></span><br />\n";
537 1752 psotfx
538 2093 psotfx
                        end_step('convert_config');
539 1752 psotfx
540 1752 psotfx
                case 'convert_config':
541 2093 psotfx
                        print " * Converting configuration table :: ";
542 1752 psotfx
543 1752 psotfx
                        $sql = "SELECT *
544 1752 psotfx
                                FROM $table_prefix" . "old_config";
545 1752 psotfx
                        $result = query($sql, "Couldn't get info from old config table");
546 1752 psotfx
547 1752 psotfx
                        $oldconfig = $db->sql_fetchrow($result);
548 1752 psotfx
549 1752 psotfx
                        //
550 1752 psotfx
                        // We don't need several original config types and two others
551 1752 psotfx
                        // have changed name ... so take account of this.
552 1752 psotfx
                        //
553 1752 psotfx
                        $ignore_configs = array("selected", "admin_passwd", "override_themes", "allow_sig");
554 1752 psotfx
                        $rename_configs = array(
555 1752 psotfx
                                "email_from" => "board_email",
556 1752 psotfx
                                "email_sig" => "board_email_sig"
557 1752 psotfx
                        );
558 1752 psotfx
559 1752 psotfx
                        while( list($name, $value) = each($oldconfig) )
560 1242 bartvb
                        {
561 2093 psotfx
                                if ( is_int($name) )
562 1752 psotfx
                                {
563 1752 psotfx
                                        continue;
564 1752 psotfx
                                }
565 1752 psotfx
566 2093 psotfx
                                if ( !inarray($name, $ignore_configs) )
567 1752 psotfx
                                {
568 1752 psotfx
                                        $name = ( !empty($rename_configs[$name]) ) ? $rename_configs[$name] : $name;
569 1752 psotfx
570 1752 psotfx
                                        $sql = "REPLACE INTO " . CONFIG_TABLE . " (config_name, config_value)
571 1752 psotfx
                                                VALUES ('$name', '" . stripslashes($value) . "')";
572 1752 psotfx
                                        query($sql, "Couldn't update config table with values from old config table");
573 1752 psotfx
                                }
574 1242 bartvb
                        }
575 1752 psotfx
576 2271 bartvb
                        $sql = "UPDATE " . CONFIG_TABLE . "
577 2271 bartvb
                                SET config_value = 'dutch'
578 2271 bartvb
                                WHERE config_name = 'default_lang' && config_value = 'nederlands'";
579 2271 bartvb
                        query($sql, "Couldn't rename 'nederlands' to 'dutch' in config table");
580 2271 bartvb
581 2093 psotfx
                        print "<span class=\"ok\"><b>OK</b></span><br />\n";
582 2093 psotfx
                        end_step('convert_ips');
583 1519 bartvb
584 2093 psotfx
                case 'convert_ips':
585 1752 psotfx
                        $names = array(
586 1752 psotfx
                                POSTS_TABLE => array(
587 1752 psotfx
                                        'id' => 'post_id',
588 1752 psotfx
                                        'field' => 'poster_ip'
589 1752 psotfx
                                ),
590 1752 psotfx
                                PRIVMSGS_TABLE => array(
591 1752 psotfx
                                        'id' => 'msg_id',
592 1752 psotfx
                                        'field' => 'poster_ip'
593 1752 psotfx
                                ),
594 1752 psotfx
                                BANLIST_TABLE => array(
595 1752 psotfx
                                        'id' => 'ban_id',
596 1752 psotfx
                                        'field' => 'ban_ip'
597 1752 psotfx
                                )
598 1752 psotfx
                        );
599 1752 psotfx
600 1752 psotfx
                        lock_tables(1, array(POSTS_TABLE, PRIVMSGS_TABLE, BANLIST_TABLE));
601 1752 psotfx
602 2093 psotfx
                        $batchsize = 2000;
603 1752 psotfx
                        while( list($table, $data_array) = each($names) )
604 1242 bartvb
                        {
605 2093 psotfx
                                $sql = "SELECT MAX(" . $data_array['id'] . ") AS max_id
606 1752 psotfx
                                        FROM $table";
607 1752 psotfx
                                $result = query($sql, "Couldn't obtain ip data from $table (" . $fields . ")");
608 1752 psotfx
609 2093 psotfx
                                $row = $db->sql_fetchrow($result);
610 1752 psotfx
611 2093 psotfx
                                $maxid = $row['max_id'];
612 1752 psotfx
613 2093 psotfx
                                for($i = 0; $i <= $maxid; $i += $batchsize)
614 1752 psotfx
                                {
615 2093 psotfx
                                        $batchstart = $i;
616 2093 psotfx
                                        $batchend = $i + $batchsize;
617 1752 psotfx
618 2093 psotfx
                                        $field_id = $data_array['id'];
619 2093 psotfx
                                        $field = $data_array['field'];
620 2093 psotfx
621 2093 psotfx
                                        print " * Converting IP format '" . $field . "' / '$table' ( $batchstart to $batchend ) :: ";
622 2093 psotfx
                                        flush();
623 2093 psotfx
624 2093 psotfx
                                        $sql = "SELECT $field_id, $field
625 2093 psotfx
                                                FROM $table
626 2093 psotfx
                                                WHERE $field_id
627 2093 psotfx
                                                        BETWEEN $batchstart
628 2093 psotfx
                                                                AND $batchend";
629 2093 psotfx
                                        $result = query($sql, "Couldn't obtain ip data from $table (" . $fields . ")");
630 2093 psotfx
631 2093 psotfx
                                        $per_pct = ceil( $db->sql_numrows($result) / 40 );
632 2093 psotfx
                                        $inc = 0;
633 2093 psotfx
634 2093 psotfx
                                        while( $row = $db->sql_fetchrow($result) )
635 2093 psotfx
                                        {
636 2093 psotfx
                                                $sql = "UPDATE $table
637 2093 psotfx
                                                        SET $field = '" . encode_ip($row[$field]) . "'
638 2093 psotfx
                                                        WHERE $field_id = " . $row[$field_id];
639 2093 psotfx
                                                query($sql, "Couldn't convert IP format of $field in $table with $field_id of " . $rowset[$field_id]);
640 2093 psotfx
641 2093 psotfx
                                                $inc++;
642 2093 psotfx
                                                if ( $inc == $per_pct )
643 2093 psotfx
                                                {
644 2093 psotfx
                                                        print ".";
645 2093 psotfx
                                                        flush();
646 2093 psotfx
                                                        $inc = 0;
647 2093 psotfx
                                                }
648 2093 psotfx
                                        }
649 2093 psotfx
650 2093 psotfx
                                        print " <span class=\"ok\"><b>OK</b></span><br />\n";
651 1752 psotfx
                                }
652 1242 bartvb
                        }
653 1519 bartvb
654 1752 psotfx
                        lock_tables(0);
655 1752 psotfx
                        end_step('convert_dates');
656 1752 psotfx
657 1752 psotfx
                case 'convert_dates':
658 1752 psotfx
                        $names = array(
659 1752 psotfx
                                POSTS_TABLE => array('post_time'),
660 1752 psotfx
                                TOPICS_TABLE => array('topic_time'),
661 1752 psotfx
                                PRIVMSGS_TABLE => array('msg_time')
662 1752 psotfx
                        );
663 1752 psotfx
664 1752 psotfx
                        lock_tables(1, array(POSTS_TABLE, TOPICS_TABLE, PRIVMSGS_TABLE));
665 1752 psotfx
666 1752 psotfx
                        while( list($table, $fields) = each($names) )
667 1242 bartvb
                        {
668 2093 psotfx
                                print " * Converting date format of $fields[$i] in $table :: ";
669 1752 psotfx
                                flush();
670 1752 psotfx
671 1752 psotfx
                                for($i = 0; $i < count($fields); $i++)
672 1242 bartvb
                                {
673 1752 psotfx
                                        $sql = "UPDATE $table
674 1752 psotfx
                                                SET " . $fields[$i] . " = UNIX_TIMESTAMP(" . $fields[$i] . ")";
675 1752 psotfx
                                        query($sql, "Couldn't convert date format of $table(" . $fields[$i] . ")");
676 1242 bartvb
                                }
677 1752 psotfx
678 2093 psotfx
                                print "<span class=\"ok\"><b>OK</b></span><br />\n";
679 1242 bartvb
                        }
680 1242 bartvb
681 1752 psotfx
                        lock_tables(0);
682 1752 psotfx
                        end_step('fix_addslashes');
683 1242 bartvb
684 1752 psotfx
                case 'fix_addslashes':
685 1752 psotfx
                        $slashfields[TOPICS_TABLE] = array('topic_title');
686 1752 psotfx
                        $slashfields[FORUMS_TABLE] = array('forum_desc', 'forum_name');
687 1752 psotfx
                        $slashfields[CATEGORIES_TABLE] = array('cat_title');
688 1752 psotfx
                        $slashfields[WORDS_TABLE] = array('word', 'replacement');
689 1752 psotfx
                        $slashfields[RANKS_TABLE] = array('rank_title');
690 1752 psotfx
                        $slashfields[DISALLOW_TABLE] = array('disallow_username');
691 1752 psotfx
692 1752 psotfx
                        //convert smilies?
693 1752 psotfx
                        $slashes = array(
694 1752 psotfx
                                "\\'" => "'",
695 1752 psotfx
                                "\\\"" => "\"",
696 1752 psotfx
                                "\\\\" => "\\");
697 1752 psotfx
                        $slashes = array(
698 1752 psotfx
                                "\\'" => "'",
699 1752 psotfx
                                "\\\"" => "\"",
700 1752 psotfx
                                "\\\\" => "\\");
701 1752 psotfx
702 1752 psotfx
                        lock_tables(1, array(TOPICS_TABLE, FORUMS_TABLE, CATEGORIES_TABLE, WORDS_TABLE, RANKS_TABLE, DISALLOW_TABLE, SMILIES_TABLE));
703 1752 psotfx
704 1752 psotfx
                        while( list($table, $fields) = each($slashfields) )
705 1752 psotfx
                        {
706 2093 psotfx
                                print " * Removing slashes from $table table :: ";
707 1752 psotfx
                                flush();
708 1752 psotfx
709 1752 psotfx
                                while( list($nr, $field) = each($fields) )
710 1752 psotfx
                                {
711 1752 psotfx
                                        @reset($slashes);
712 1752 psotfx
                                        while( list($search, $replace) = each($slashes) )
713 1752 psotfx
                                        {
714 1752 psotfx
                                                $sql = "UPDATE $table
715 1752 psotfx
                                                        SET $field = REPLACE($field, '" . addslashes($search) . "', '" . addslashes($replace) . "')";
716 1752 psotfx
                                                query($sql, "Couldn't remove extraneous slashes from the old data.");
717 1752 psotfx
                                        }
718 1752 psotfx
                                }
719 2093 psotfx
720 2093 psotfx
                                print "<span class=\"ok\"><b>OK</b></span><br />\n";
721 1752 psotfx
                        }
722 2093 psotfx
723 1752 psotfx
                        lock_tables(0);
724 1752 psotfx
                        end_step('remove_topics');
725 1752 psotfx
726 1752 psotfx
                case 'remove_topics':
727 2093 psotfx
                        print " * Removing posts with no corresponding topics :: ";
728 1242 bartvb
                        flush();
729 1438 bartvb
730 1752 psotfx
                        $sql = "SELECT p.post_id
731 1752 psotfx
                                FROM " . POSTS_TABLE . " p
732 1752 psotfx
                                LEFT JOIN " . TOPICS_TABLE . " t ON p.topic_id = t.topic_id
733 1752 psotfx
                                WHERE t.topic_id IS NULL";
734 1752 psotfx
                        $result = query($sql, "Couldn't obtain list of deleted topics");
735 1752 psotfx
736 1752 psotfx
                        $post_total = $db->sql_numrows($result);
737 1242 bartvb
738 2093 psotfx
                        if ( $post_total )
739 1242 bartvb
                        {
740 1756 psotfx
                                $post_id_ary = array();
741 1756 psotfx
                                while( $row = $db->sql_fetchrow($result) )
742 1756 psotfx
                                {
743 1756 psotfx
                                        $post_id_ary[] = $row['post_id'];
744 1756 psotfx
                                }
745 1752 psotfx
746 1756 psotfx
                                $sql = "DELETE FROM " . POSTS_TABLE . "
747 1756 psotfx
                                        WHERE post_id IN (" . implode(", ", $post_id_ary) . ")";
748 1756 psotfx
                                query($sql, "Couldn't update posts to remove deleted user poster_id values");
749 1752 psotfx
750 1756 psotfx
                                $sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
751 1756 psotfx
                                        WHERE post_id IN (" . implode(", ", $post_id_ary) . ")";
752 1756 psotfx
                                query($sql, "Couldn't update posts to remove deleted user poster_id values");
753 1756 psotfx
                        }
754 1752 psotfx
755 2093 psotfx
                        echo "<span class=\"ok\"><b>OK</b></span> ( Removed $post_total posts )<br />\n";
756 1752 psotfx
                        end_step('convert_users');
757 1752 psotfx
758 1752 psotfx
                case 'convert_users':
759 1829 psotfx
                        //
760 1829 psotfx
                        // Completely remove old soft-deleted users
761 1829 psotfx
                        //
762 1829 psotfx
                        $sql = "DELETE FROM " . USERS_TABLE . "
763 1829 psotfx
                                WHERE user_level = -1";
764 1829 psotfx
                        query($sql, "Couldn't delete old soft-deleted users");
765 1829 psotfx
766 1752 psotfx
                        $sql = "SELECT COUNT(*) AS total, MAX(user_id) AS maxid
767 1752 psotfx
                                FROM " . USERS_TABLE;
768 1752 psotfx
                        $result = query($sql, "Couldn't get max post_id.");
769 1752 psotfx
770 1752 psotfx
                        $maxid = $db->sql_fetchrow($result);
771 1752 psotfx
772 1752 psotfx
                        $totalposts = $maxid['total'];
773 1752 psotfx
                        $maxid = $maxid['maxid'];
774 1752 psotfx
775 1752 psotfx
                        $sql = "ALTER TABLE " . USERS_TABLE . "
776 1752 psotfx
                                ADD user_sig_bbcode_uid CHAR(10),
777 1752 psotfx
                                MODIFY user_sig text";
778 1752 psotfx
                        query($sql, "Couldn't add user_sig_bbcode_uid field to users table");
779 1752 psotfx
780 1752 psotfx
                        $super_mods = array();
781 1752 psotfx
                        $first_admin = -2;
782 1752 psotfx
783 1752 psotfx
                        $batchsize = 1000;
784 1752 psotfx
                        for($i = -1; $i <= $maxid; $i += $batchsize)
785 1752 psotfx
                        {
786 1752 psotfx
                                $batchstart = $i;
787 1752 psotfx
                                $batchend = $i + $batchsize;
788 1752 psotfx
789 2093 psotfx
                                print " * Converting Users ( $batchstart to $batchend ) :: ";
790 1752 psotfx
                                flush();
791 1752 psotfx
792 1752 psotfx
                                $sql = "SELECT *
793 1752 psotfx
                                        FROM " . USERS_TABLE . "
794 1752 psotfx
                                        WHERE user_id
795 1752 psotfx
                                                BETWEEN $batchstart
796 1752 psotfx
                                                        AND $batchend";
797 1752 psotfx
                                $result = query($sql, "Couldn't get ". USERS_TABLE .".user_id $batchstart to $batchend");
798 1752 psotfx
799 1752 psotfx
                                // Array with user fields that we want to check for invalid data (to few characters)
800 1752 psotfx
                                $checklength = array(
801 1752 psotfx
                                        'user_occ',
802 1752 psotfx
                                        'user_website',
803 1752 psotfx
                                        'user_email',
804 1752 psotfx
                                        'user_from',
805 1752 psotfx
                                        'user_intrest',
806 1752 psotfx
                                        'user_aim',
807 1752 psotfx
                                        'user_yim',
808 1752 psotfx
                                        'user_msnm');
809 1752 psotfx
810 1752 psotfx
                                lock_tables(1, array(USERS_TABLE, GROUPS_TABLE, USER_GROUP_TABLE, POSTS_TABLE));
811 1752 psotfx
812 2093 psotfx
                                $per_pct = ceil( $db->sql_numrows($result) / 40 );
813 2093 psotfx
                                $inc = 0;
814 2093 psotfx
815 2732 psotfx
                                $group_id = 1;
816 1752 psotfx
                                while( $row = $db->sql_fetchrow($result) )
817 1250 bartvb
                                {
818 2732 psotfx
                                        $sql = "INSERT INTO " . GROUPS_TABLE . " (group_id, group_name, group_description, group_single_user)
819 2732 psotfx
                                                VALUES ($group_id, '" . addslashes($row['username']) . "', 'Personal User', 1)";
820 1752 psotfx
                                        query($sql, "Wasn't able to insert user ".$row['user_id']." into table ".GROUPS_TABLE);
821 1752 psotfx
822 2732 psotfx
                                        $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
823 2732 psotfx
                                                VALUES ($group_id, " . $row['user_id'] . ", 0)";
824 2732 psotfx
                                        query($sql, "Wasn't able to insert user ".$row['user_id']." into table ".USER_GROUP_TABLE);
825 1752 psotfx
826 2093 psotfx
                                        if ( is_int($row['user_regdate']) )
827 1752 psotfx
                                        {
828 1752 psotfx
                                                // We already converted this post to the new style BBcode, skip this post.
829 1752 psotfx
                                                continue;
830 1752 psotfx
                                        }
831 1752 psotfx
832 2732 psotfx
                                        $group_id++;
833 2732 psotfx
834 1752 psotfx
                                        //
835 1752 psotfx
                                        // Nathan's bbcode2 conversion
836 1752 psotfx
                                        //
837 1752 psotfx
838 1752 psotfx
                                        // undo 1.2.x encoding..
839 1752 psotfx
                                        $row['user_sig'] = bbdecode(stripslashes($row['user_sig']));
840 1752 psotfx
                                        $row['user_sig'] = undo_make_clickable($row['user_sig']);
841 1752 psotfx
                                        $row['user_sig'] = str_replace("<BR>", "\n", $row['user_sig']);
842 1752 psotfx
843 1752 psotfx
                                        // make a uid
844 1752 psotfx
                                        $uid = make_bbcode_uid();
845 1752 psotfx
846 1752 psotfx
                                        // do 2.x first-pass encoding..
847 1752 psotfx
                                        $row['user_sig'] = bbencode_first_pass($row['user_sig'], $uid);
848 1752 psotfx
                                        $row['user_sig'] = addslashes($row['user_sig']);
849 1752 psotfx
850 1752 psotfx
                                        // Check for invalid info like '-' and '?' for a lot of fields
851 1752 psotfx
                                        @reset($checklength);
852 1752 psotfx
                                        while($field = each($checklength))
853 1752 psotfx
                                        {
854 1752 psotfx
                                                $row[$field[1]] = strlen($row[$field[1]]) < 3 ? '' : $row[$field[1]];
855 1752 psotfx
                                        }
856 1752 psotfx
857 1752 psotfx
                                        preg_match('/(.*?) (\d{1,2}), (\d{4})/', $row['user_regdate'], $parts);
858 1752 psotfx
                                        $row['user_regdate'] = gmmktime(0, 0, 0, $months[$parts[1]], $parts[2], $parts[3]);
859 1752 psotfx
860 1752 psotfx
                                        $website = $row['user_website'];
861 2093 psotfx
                                        if ( substr(strtolower($website), 0, 7) != "http://" )
862 1752 psotfx
                                        {
863 1752 psotfx
                                                $website = "http://" . $website;
864 1752 psotfx
                                        }
865 1752 psotfx
                                        if( strtolower($website) == 'http://' )
866 1752 psotfx
                                        {
867 1752 psotfx
                                                $website = '';
868 1752 psotfx
                                        }
869 1752 psotfx
                                        $row['user_website'] = addslashes($website);
870 1752 psotfx
871 1752 psotfx
                                        $row['user_icq'] = (ereg("^[0-9]+$", $row['user_icq'])) ? $row['user_icq'] : '';
872 1752 psotfx
                                        reset($checklength);
873 1752 psotfx
874 1752 psotfx
                                        while($field = each($checklength))
875 1752 psotfx
                                        {
876 2093 psotfx
                                                if ( strlen($row[$field[1]]) < 3 )
877 1752 psotfx
                                                {
878 1752 psotfx
                                                        $row[$field[1]] = '';
879 1752 psotfx
                                                }
880 1752 psotfx
                                                $row[$field[1]] = addslashes($row[$field[1]]);
881 1752 psotfx
                                        }
882 1752 psotfx
883 1752 psotfx
                                        //
884 1752 psotfx
                                        // Is user a super moderator?
885 1752 psotfx
                                        //
886 1752 psotfx
                                        if( $row['user_level'] == 3 )
887 1752 psotfx
                                        {
888 1752 psotfx
                                                $super_mods[] = $row['user_id'];
889 1752 psotfx
                                        }
890 1752 psotfx
891 1752 psotfx
                                        $row['user_level'] = ( $row['user_level'] == 4 ) ? ADMIN : USER;
892 1752 psotfx
893 1752 psotfx
                                        //
894 1752 psotfx
                                        // Used to define a 'practical' group moderator user_id
895 1752 psotfx
                                        // for super mods a little latter.
896 1752 psotfx
                                        //
897 1752 psotfx
                                        if( $first_admin == -2 && $row['user_level'] == ADMIN )
898 1752 psotfx
                                        {
899 1752 psotfx
                                                $first_admin = $row['user_id'];
900 1752 psotfx
                                        }
901 1752 psotfx
902 2271 bartvb
                                        //
903 2271 bartvb
                                        // Dutch language files have been renamed from 'nederlands' to 'dutch'
904 2271 bartvb
                                        //
905 2271 bartvb
                                        if( $row['user_lang'] == 'nederlands' )
906 2271 bartvb
                                        {
907 2271 bartvb
                                                $row['user_lang'] = 'dutch';
908 2271 bartvb
                                        }
909 2271 bartvb
910 1752 psotfx
                                        $sql = "UPDATE " . USERS_TABLE . "
911 1752 psotfx
                                                SET
912 1752 psotfx
                                                        user_sig = '" . $row['user_sig'] . "',
913 2093 psotfx
                                                        user_sig_bbcode_uid = '$uid',
914 1752 psotfx
                                                        user_regdate = '" . $row['user_regdate'] . "',
915 1752 psotfx
                                                        user_website = '" . $row['user_website'] . "',
916 1752 psotfx
                                                        user_occ = '" . $row['user_occ'] . "',
917 1752 psotfx
                                                        user_email = '" . $row['user_email'] . "',
918 1752 psotfx
                                                        user_from = '" . $row['user_from'] . "',
919 1752 psotfx
                                                        user_intrest = '" . $row['user_intrest'] . "',
920 1752 psotfx
                                                        user_aim = '" . $row['user_aim'] . "',
921 1752 psotfx
                                                        user_yim = '" . $row['user_yim'] . "',
922 1752 psotfx
                                                        user_msnm = '" . $row['user_msnm'] . "',
923 1752 psotfx
                                                        user_level = '" . $row['user_level'] . "',
924 1752 psotfx
                                                        user_desmile = NOT(user_desmile),
925 1752 psotfx
                                                        user_bbcode = 1,
926 1752 psotfx
                                                        user_theme = 1
927 1752 psotfx
                                                WHERE user_id = " . $row['user_id'];
928 1752 psotfx
                                        query($sql, "Couldn't update ".USERS_TABLE." table with new BBcode and regdate for user_id ".$row['user_id']);
929 2093 psotfx
930 2093 psotfx
                                        $inc++;
931 2093 psotfx
                                        if ( $inc == $per_pct )
932 2093 psotfx
                                        {
933 2093 psotfx
                                                print ".";
934 2093 psotfx
                                                flush();
935 2093 psotfx
                                                $inc = 0;
936 2093 psotfx
                                        }
937 1250 bartvb
                                }
938 1752 psotfx
939 2093 psotfx
                                print " <span class=\"ok\"><b>OK</b></span><br />\n";
940 2093 psotfx
941 1752 psotfx
                                lock_tables(0);
942 1752 psotfx
                        }
943 1752 psotfx
944 1752 psotfx
                        //
945 1752 psotfx
                        // Handle super-mods, create hidden group for them
946 1752 psotfx
                        //
947 1752 psotfx
                        // Iterate trough access table
948 1752 psotfx
                        if( count($super_mods) && $first_admin != -2 )
949 1752 psotfx
                        {
950 2093 psotfx
                                print "\n<br />\n * Creating new group for super moderators :: ";
951 1752 psotfx
                                flush();
952 1752 psotfx
953 1752 psotfx
                                $sql = "INSERT INTO " . GROUPS_TABLE . " (group_type, group_name, group_description, group_moderator, group_single_user)
954 1752 psotfx
                                        VALUES (" . GROUP_HIDDEN . ", 'Super Moderators', 'Converted super moderators', $first_admin, 0)";
955 1752 psotfx
                                $result = query($sql, "Couldn't create group for ".$row['forum_name']);
956 1752 psotfx
957 1752 psotfx
                                $group_id = $db->sql_nextid();
958 1752 psotfx
959 2093 psotfx
                                if ( $group_id <= 0 )
960 1250 bartvb
                                {
961 1752 psotfx
                                        print "<font color=\"red\">Group creation failed. Aborting creation of groups...<br></font>\n";
962 1752 psotfx
                                        continue 2;
963 1250 bartvb
                                }
964 1250 bartvb
965 2093 psotfx
                                print "<span class=\"ok\"><b>OK</b></span><br />\n";
966 1752 psotfx
967 2093 psotfx
                                print " * Updating auth_access for super moderator group :: ";
968 1752 psotfx
                                flush();
969 1752 psotfx
970 1752 psotfx
                                $sql = "SELECT forum_id
971 1752 psotfx
                                        FROM " . FORUMS_TABLE;
972 1752 psotfx
                                $result = query($sql, "Couldn't obtain forum_id list");
973 1752 psotfx
974 1752 psotfx
                                while( $row = $db->sql_fetchrow($result) )
975 1242 bartvb
                                {
976 1752 psotfx
                                        $sql = "INSERT INTO " . AUTH_ACCESS_TABLE . " (group_id, forum_id, auth_mod)
977 1752 psotfx
                                                VALUES ($group_id, " . $row['forum_id'] . ", 1)";
978 1752 psotfx
                                        $result_insert = query($sql, "Unable to set group auth access for super mods.");
979 1242 bartvb
                                }
980 1242 bartvb
981 1752 psotfx
                                for($i = 0; $i < count($super_mods); $i++)
982 1242 bartvb
                                {
983 1752 psotfx
                                        $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
984 1752 psotfx
                                                VALUES ($group_id, " . $super_mods[$i] . ", 0)";
985 1752 psotfx
                                        query($sql, "Unable to add user_id $user_id to group_id $group_id (super mods)<br>\n");
986 1242 bartvb
                                }
987 1752 psotfx
988 2093 psotfx
                                print "<span class=\"ok\"><b>OK</b></span><br />\n";
989 1752 psotfx
                        }
990 1242 bartvb
991 1752 psotfx
                        end_step('convert_posts');
992 1242 bartvb
993 1752 psotfx
                case 'convert_posts':
994 2093 psotfx
                        print " * Adding enable_sig field to " . POSTS_TABLE . " :: ";
995 2093 psotfx
                        flush();
996 1752 psotfx
                        $sql = "ALTER TABLE " . POSTS_TABLE . "
997 1752 psotfx
                                ADD enable_sig tinyint(1) DEFAULT '1' NOT NULL";
998 1752 psotfx
                        $result = query($sql, "Couldn't add enable_sig field to " . POSTS_TABLE . ".");
999 2093 psotfx
                        print "<span class=\"ok\"><b>OK</b></span><br />\n";
1000 1752 psotfx
1001 2093 psotfx
                        print " * Adding enable_bbcode field to " . POSTS_TEXT_TABLE . " :: ";
1002 2093 psotfx
                        flush();
1003 1752 psotfx
                        $sql = "ALTER TABLE " . POSTS_TEXT_TABLE . "
1004 1752 psotfx
                                ADD enable_bbcode tinyint(1) DEFAULT '1' NOT NULL";
1005 1752 psotfx
                        $result = query($sql, "Couldn't add enable_bbcode field to " . POSTS_TABLE . ".");
1006 2093 psotfx
                        print "<span class=\"ok\"><b>OK</b></span><br />\n";
1007 1752 psotfx
1008 2093 psotfx
                        print " * Adding bbcode_uid field to " . POSTS_TEXT_TABLE . " :: ";
1009 2093 psotfx
                        flush();
1010 1752 psotfx
                        $sql = "ALTER TABLE " . POSTS_TEXT_TABLE . "
1011 1752 psotfx
                                ADD bbcode_uid char(10) NOT NULL";
1012 1752 psotfx
                        $result = query($sql, "Couldn't add bbcode_uid field to " . POSTS_TABLE . ".");
1013 2093 psotfx
                        print "<span class=\"ok\"><b>OK</b></span><br />\n";
1014 1752 psotfx
1015 2093 psotfx
                        print " * Adding post_edit_time field to " . POSTS_TABLE . " :: ";
1016 2093 psotfx
                        flush();
1017 1752 psotfx
                        $sql = "ALTER TABLE " . POSTS_TABLE . "
1018 1752 psotfx
                                ADD post_edit_time int(11)";
1019 1752 psotfx
                        $result = query($sql, "Couldn't add post_edit_time field to " . POSTS_TABLE . ".");
1020 2093 psotfx
                        print "<span class=\"ok\"><b>OK</b></span><br />\n";
1021 1752 psotfx
1022 2093 psotfx
                        print " * Adding post_edit_count field to " . POSTS_TABLE . " :: ";
1023 2093 psotfx
                        flush();
1024 1752 psotfx
                        $sql = "ALTER TABLE " . POSTS_TABLE . "
1025 1752 psotfx
                                ADD post_edit_count smallint(5) UNSIGNED DEFAULT '0' NOT NULL";
1026 1752 psotfx
                        $result = query($sql, "Couldn't add post_edit_count field to " . POSTS_TABLE . ".");
1027 2093 psotfx
                        print "<span class=\"ok\"><b>OK</b></span><br />\n<br />\n";
1028 1752 psotfx
1029 1752 psotfx
                        $sql = "SELECT COUNT(*) as total, MAX(post_id) as maxid
1030 1752 psotfx
                                FROM " . POSTS_TEXT_TABLE;
1031 1752 psotfx
                        $result = query($sql, "Couldn't get max post_id.");
1032 1752 psotfx
1033 1752 psotfx
                        $maxid = $db->sql_fetchrow($result);
1034 1752 psotfx
1035 1752 psotfx
                        $totalposts = $maxid['total'];
1036 1752 psotfx
                        $maxid = $maxid['maxid'];
1037 1752 psotfx
1038 1752 psotfx
                        $batchsize = 2000;
1039 1752 psotfx
                        for($i = 0; $i <= $maxid; $i += $batchsize)
1040 1752 psotfx
                        {
1041 1752 psotfx
                                $batchstart = $i + 1;
1042 1752 psotfx
                                $batchend = $i + $batchsize;
1043 1752 psotfx
1044 2093 psotfx
                                print " * Converting BBcode ( $batchstart to $batchend ) :: ";
1045 1752 psotfx
                                flush();
1046 1752 psotfx
1047 1752 psotfx
                                $sql = "SELECT *
1048 1752 psotfx
                                        FROM " . POSTS_TEXT_TABLE . "
1049 1752 psotfx
                                        WHERE post_id
1050 1752 psotfx
                                                BETWEEN $batchstart
1051 1752 psotfx
                                                        AND $batchend";
1052 1752 psotfx
                                $result = query($sql, "Couldn't get ". POSTS_TEXT_TABLE .".post_id $batchstart to $batchend");
1053 1752 psotfx
1054 1752 psotfx
                                lock_tables(1, array(POSTS_TEXT_TABLE, POSTS_TABLE));
1055 1752 psotfx
1056 2093 psotfx
                                $per_pct = ceil( $db->sql_numrows($result) / 40 );
1057 2093 psotfx
                                $inc = 0;
1058 2093 psotfx
1059 1752 psotfx
                                while( $row = $db->sql_fetchrow($result) )
1060 1242 bartvb
                                {
1061 2093 psotfx
                                        if ( $row['bbcode_uid'] != '' )
1062 1752 psotfx
                                        {
1063 1752 psotfx
                                                // We already converted this post to the new style BBcode, skip this post.
1064 1752 psotfx
                                                continue;
1065 1752 psotfx
                                        }
1066 1752 psotfx
1067 1752 psotfx
                                        //
1068 1752 psotfx
                                        // Nathan's bbcode2 conversion
1069 1752 psotfx
                                        //
1070 1752 psotfx
                                        // undo 1.2.x encoding..
1071 1752 psotfx
                                        $row['post_text'] = bbdecode(stripslashes($row['post_text']));
1072 1752 psotfx
                                        $row['post_text'] = undo_make_clickable($row['post_text']);
1073 2511 psotfx
                                        $row['post_text'] = str_replace('<BR>', "\n", $row['post_text']);
1074 1752 psotfx
1075 1752 psotfx
                                        // make a uid
1076 1752 psotfx
                                        $uid = make_bbcode_uid();
1077 1752 psotfx
1078 1752 psotfx
                                        // do 2.x first-pass encoding..
1079 1752 psotfx
                                        $row['post_text'] = smiley_replace($row['post_text']);
1080 1752 psotfx
                                        $row['post_text'] = bbencode_first_pass($row['post_text'], $uid);
1081 1752 psotfx
                                        $row['post_text'] = addslashes($row['post_text']);
1082 1752 psotfx
1083 1752 psotfx
                                        $edited_sql = "";
1084 2511 psotfx
                                        if ( preg_match('/^(.*?)([\n]+<font size=\-1>\[ This message was .*?)$/s', $row['post_text'], $matches) )
1085 1752 psotfx
                                        {
1086 1752 psotfx
                                                $row['post_text'] = $matches[1];
1087 1752 psotfx
                                                $edit_info = $matches[2];
1088 1752 psotfx
1089 2511 psotfx
                                                $edit_times = count(explode(' message ', $edit_info)) - 1; // Taken from example for substr_count in annotated PHP manual
1090 1752 psotfx
1091 2511 psotfx
                                                if ( preg_match('/^.* by: (.*?) on (....)-(..)-(..) (..):(..) \]<\/font>/s', $edit_info, $matches) )
1092 1752 psotfx
                                                {
1093 1752 psotfx
                                                        $edited_user = $matches[1];
1094 1752 psotfx
                                                        $edited_time = gmmktime($matches[5], $matches[6], 0, $matches[3], $matches[4], $matches[2]);
1095 1752 psotfx
1096 1752 psotfx
                                                        //
1097 1752 psotfx
                                                        // This isn't strictly correct since 2.0 won't include and edit
1098 1752 psotfx
                                                        // statement if the edit wasn't by the user who posted ...
1099 1752 psotfx
                                                        //
1100 1752 psotfx
                                                        $edited_sql = ", post_edit_time = $edited_time, post_edit_count = $edit_times";
1101 1752 psotfx
                                                }
1102 1752 psotfx
                                        }
1103 1752 psotfx
1104 2093 psotfx
                                        if ( preg_match("/^(.*?)\n-----------------\n.*$/is", $row['post_text'], $matches) )
1105 1752 psotfx
                                        {
1106 1752 psotfx
                                                $row['post_text'] = $matches[1];
1107 1752 psotfx
                                                $enable_sig = 1;
1108 1752 psotfx
                                        }
1109 1752 psotfx
                                        else
1110 1752 psotfx
                                        {
1111 1752 psotfx
                                                $checksig = preg_replace('/\[addsig\]$/', '', $row['post_text']);
1112 1752 psotfx
                                                $enable_sig = ( strlen($checksig) == strlen($row['post_text']) ) ? 0 : 1;
1113 1752 psotfx
                                        }
1114 1752 psotfx
1115 1752 psotfx
                                        $sql = "UPDATE " . POSTS_TEXT_TABLE . "
1116 1752 psotfx
                                                SET post_text = '$checksig', bbcode_uid = '$uid'
1117 1752 psotfx
                                                WHERE post_id = " . $row['post_id'];
1118 1752 psotfx
                                        query($sql, "Couldn't update " . POSTS_TEXT_TABLE . " table with new BBcode for post_id :: " . $row['post_id']);
1119 1752 psotfx
1120 1752 psotfx
                                        $sql = "UPDATE " . POSTS_TABLE . "
1121 1752 psotfx
                                                SET enable_sig = $enable_sig" . $edited_sql . "
1122 1752 psotfx
                                                WHERE post_id = " . $row['post_id'];
1123 1752 psotfx
                                        query($sql, "Couldn't update " . POSTS_TABLE . " table with signature status for post with post_id :: " . $row['post_id']);
1124 2093 psotfx
1125 2093 psotfx
                                        $inc++;
1126 2093 psotfx
                                        if ( $inc == $per_pct )
1127 2093 psotfx
                                        {
1128 2511 psotfx
                                                print '.';
1129 2093 psotfx
                                                flush();
1130 2093 psotfx
                                                $inc = 0;
1131 2093 psotfx
                                        }
1132 1242 bartvb
                                }
1133 1752 psotfx
1134 2093 psotfx
                                print " <span class=\"ok\"><b>OK</b></span><br />\n";
1135 2093 psotfx
1136 1752 psotfx
                                lock_tables(0);
1137 1752 psotfx
                        }
1138 1752 psotfx
1139 2093 psotfx
                        print "<br />\n * Updating poster_id for deleted users :: ";
1140 1752 psotfx
                        flush();
1141 1752 psotfx
1142 1752 psotfx
                        $sql = "SELECT DISTINCT p.post_id
1143 1752 psotfx
                                FROM " . POSTS_TABLE . " p
1144 1752 psotfx
                                LEFT JOIN " . USERS_TABLE . " u ON p.poster_id = u.user_id
1145 1752 psotfx
                                WHERE u.user_id IS NULL";
1146 1752 psotfx
                        $result = query($sql, "Couldn't obtain list of deleted users");
1147 1752 psotfx
1148 1757 psotfx
                        $users_removed = $db->sql_numrows($result);
1149 1757 psotfx
1150 2093 psotfx
                        if ( $users_removed )
1151 1752 psotfx
                        {
1152 1757 psotfx
                                $post_id_ary = array();
1153 1757 psotfx
                                while( $row = $db->sql_fetchrow($result) )
1154 1757 psotfx
                                {
1155 1757 psotfx
                                        $post_id_ary[] = $row['post_id'];
1156 1757 psotfx
                                }
1157 1757 psotfx
1158 1757 psotfx
                                $sql = "UPDATE " . POSTS_TABLE . "
1159 1757 psotfx
                                        SET poster_id = " . ANONYMOUS . ", enable_sig = 0
1160 1757 psotfx
                                        WHERE post_id IN (" . implode(", ", $post_id_ary) . ")";
1161 1757 psotfx
                                query($sql, "Couldn't update posts to remove deleted user poster_id values");
1162 1752 psotfx
                        }
1163 1752 psotfx
1164 2093 psotfx
                        print "<span class=\"ok\"><b>OK</b></span> ( Removed $users_removed non-existent user references )<br />\n";
1165 1752 psotfx
1166 2093 psotfx
                        end_step('convert_privmsgs');
1167 1752 psotfx
1168 2093 psotfx
                case 'convert_privmsgs':
1169 1752 psotfx
                        $sql = "SELECT COUNT(*) as total, max(msg_id) as maxid
1170 1752 psotfx
                                FROM " . PRIVMSGS_TABLE;
1171 1752 psotfx
                        $result = query($sql, "Couldn't get max privmsgs_id.");
1172 1752 psotfx
1173 1752 psotfx
                        $maxid = $db->sql_fetchrow($result);
1174 1752 psotfx
1175 1752 psotfx
                        $totalposts = $maxid['total'];
1176 1752 psotfx
                        $maxid = $maxid['maxid'];
1177 1752 psotfx
1178 1752 psotfx
                        $sql = "ALTER TABLE " . PRIVMSGS_TABLE . "
1179 1752 psotfx
                                ADD privmsgs_subject VARCHAR(255),
1180 1752 psotfx
                                ADD privmsgs_attach_sig TINYINT(1) DEFAULT 1";
1181 1752 psotfx
                        query($sql, "Couldn't add privmsgs_subject field to " . PRIVMSGS_TABLE . " table");
1182 1752 psotfx
1183 1752 psotfx
                        $batchsize = 2000;
1184 1752 psotfx
                        for($i = 0; $i <= $maxid; $i += $batchsize)
1185 1752 psotfx
                        {
1186 1752 psotfx
                                $batchstart = $i + 1;
1187 1752 psotfx
                                $batchend = $i + $batchsize;
1188 1242 bartvb
1189 2093 psotfx
                                print " * Converting Private Message ( $batchstart to $batchend ) :: ";
1190 1752 psotfx
                                flush();
1191 1752 psotfx
1192 1752 psotfx
                                $sql = "SELECT *
1193 1752 psotfx
                                        FROM " . PRIVMSGS_TABLE . "
1194 1752 psotfx
                                        WHERE msg_id
1195 1752 psotfx
                                                BETWEEN $batchstart
1196 1752 psotfx
                                                        AND $batchend";
1197 1752 psotfx
                                $result = query($sql, "Couldn't get " . POSTS_TEXT_TABLE . " post_id $batchstart to $batchend");
1198 1752 psotfx
1199 1752 psotfx
                                lock_tables(1, array(PRIVMSGS_TABLE, PRIVMSGS_TEXT_TABLE));
1200 1752 psotfx
1201 2093 psotfx
                                $per_pct = ceil( $db->sql_numrows($result) / 40 );
1202 2093 psotfx
                                $inc = 0;
1203 2093 psotfx
1204 1752 psotfx
                                while( $row = $db->sql_fetchrow($result) )
1205 1242 bartvb
                                {
1206 2093 psotfx
                                        if ( $row['msg_text'] == NULL )
1207 1242 bartvb
                                        {
1208 1752 psotfx
                                                // We already converted this post to the new style BBcode, skip this post.
1209 1752 psotfx
                                                continue;
1210 1242 bartvb
                                        }
1211 1752 psotfx
                                        //
1212 1752 psotfx
                                        // Nathan's bbcode2 conversion
1213 1752 psotfx
                                        //
1214 1752 psotfx
                                        // undo 1.2.x encoding..
1215 1752 psotfx
                                        $row['msg_text'] = bbdecode(stripslashes($row['msg_text']));
1216 1752 psotfx
                                        $row['msg_text'] = undo_make_clickable($row['msg_text']);
1217 1752 psotfx
                                        $row['msg_text'] = str_replace("<BR>", "\n", $row['msg_text']);
1218 1242 bartvb
1219 1752 psotfx
                                        // make a uid
1220 1752 psotfx
                                        $uid = make_bbcode_uid();
1221 1752 psotfx
1222 1752 psotfx
                                        // do 2.x first-pass encoding..
1223 1752 psotfx
                                        $row['msg_text'] = smiley_replace($row['msg_text']);
1224 1752 psotfx
                                        $row['msg_text'] = bbencode_first_pass($row['msg_text'], $uid);
1225 1752 psotfx
1226 1752 psotfx
                                        $checksig = preg_replace('/\[addsig\]$/', '', $row['msg_text']);
1227 1752 psotfx
                                        $enable_sig = (strlen($checksig) == strlen($row['msg_text'])) ? 0 : 1;
1228 1752 psotfx
1229 2093 psotfx
                                        if ( preg_match("/^(.*?)\n-----------------\n.*$/is", $checksig, $matches) )
1230 1752 psotfx
                                        {
1231 1752 psotfx
                                                $checksig = $matches[1];
1232 1752 psotfx
                                                $enable_sig = 1;
1233 1752 psotfx
                                        }
1234 1752 psotfx
1235 1752 psotfx
                                        $row['msg_text'] = $checksig;
1236 1752 psotfx
1237 1752 psotfx
                                        $row['msg_status'] = ($row['msg_status'] == 1) ? PRIVMSGS_READ_MAIL : PRIVMSGS_NEW_MAIL;
1238 1752 psotfx
1239 1752 psotfx
                                        // Subject contains first 60 characters of msg, remove any BBCode tags
1240 1752 psotfx
                                        $subject = addslashes(strip_tags(substr($row['msg_text'], 0, 60)));
1241 1752 psotfx
                                        $subject = preg_replace("/\[.*?\:(([a-z0-9]:)?)$uid.*?\]/si", "", $subject);
1242 1752 psotfx
1243 1752 psotfx
                                        $row['msg_text'] = addslashes($row['msg_text']);
1244 1752 psotfx
1245 1752 psotfx
                                        $sql = "INSERT INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text)
1246 1752 psotfx
                                                VALUES ('" . $row['msg_id'] . "', '$uid', '" . $row['msg_text'] . "')";
1247 1752 psotfx
                                        query($sql, "Couldn't insert PrivMsg text into " . PRIVMSGS_TEXT_TABLE . " table msg_id " . $row['msg_id']);
1248 1752 psotfx
1249 1752 psotfx
                                        $sql = "UPDATE " . PRIVMSGS_TABLE . "
1250 1752 psotfx
                                                SET msg_text = NULL, msg_status = " . $row['msg_status'] . ", privmsgs_subject = '$subject', privmsgs_attach_sig = $enable_sig
1251 1752 psotfx
                                                WHERE msg_id = " . $row['msg_id'];
1252 1752 psotfx
                                        query($sql, "Couldn't update " . PRIVMSGS_TABLE . " table for msg_id " . $row['post_id']);
1253 2093 psotfx
1254 2093 psotfx
                                        $inc++;
1255 2093 psotfx
                                        if ( $inc == $per_pct )
1256 2093 psotfx
                                        {
1257 2511 psotfx
                                                print '.';
1258 2093 psotfx
                                                flush();
1259 2093 psotfx
                                                $inc = 0;
1260 2093 psotfx
                                        }
1261 1242 bartvb
                                }
1262 2093 psotfx
1263 2093 psotfx
                                print " <span class=\"ok\"><b>OK</b></span><br />\n";
1264 1752 psotfx
                        }
1265 1242 bartvb
1266 1242 bartvb
                        lock_tables(0);
1267 2093 psotfx
                        end_step('convert_moderators');
1268 1495 bartvb
1269 2093 psotfx
                case 'convert_moderators';
1270 1752 psotfx
                        $sql = "SELECT *
1271 1752 psotfx
                                FROM forum_mods";
1272 1752 psotfx
                        $result = query($sql, "Couldn't get list with all forum moderators");
1273 1242 bartvb
1274 1752 psotfx
                        while( $row = $db->sql_fetchrow($result) )
1275 1242 bartvb
                        {
1276 1752 psotfx
                                // Check if this moderator and this forum still exist
1277 2511 psotfx
                                $sql = "SELECT user_id
1278 1752 psotfx
                                        FROM " . USERS_TABLE . ", " . FORUMS_TABLE . "
1279 1752 psotfx
                                        WHERE user_id = " . $row['user_id'] . "
1280 1752 psotfx
                                                AND forum_id = " . $row['forum_id'];
1281 2093 psotfx
                                $check_data = query($sql, "Couldn't check if user " . $row['user_id'] . " and forum " . $row['forum_id'] . " exist");
1282 1752 psotfx
1283 2093 psotfx
                                if ( !($rowtest = $db->sql_fetchrow($check_data)) )
1284 1242 bartvb
                                {
1285 1752 psotfx
                                        // Either the moderator or the forum have been deleted, this line in forum_mods was redundant, skip it.
1286 1242 bartvb
                                        continue;
1287 1242 bartvb
                                }
1288 1752 psotfx
1289 1752 psotfx
                                $sql = "SELECT g.group_id
1290 1752 psotfx
                                        FROM " . GROUPS_TABLE . " g, " . USER_GROUP_TABLE . " ug
1291 2093 psotfx
                                        WHERE g.group_id = ug.group_id
1292 1752 psotfx
                                                AND ug.user_id = " . $row['user_id'] . "
1293 1752 psotfx
                                                AND g.group_single_user = 1";
1294 2093 psotfx
                                $insert_group = query($sql, "Couldn't get group number for user " . $row['user_id'] . ".");
1295 1752 psotfx
1296 1752 psotfx
                                $group_id = $db->sql_fetchrow($insert_group);
1297 1752 psotfx
                                $group_id = $group_id['group_id'];
1298 1752 psotfx
1299 2093 psotfx
                                print " * Adding moderator for forum " . $row['forum_id'] . " :: ";
1300 2093 psotfx
                                flush();
1301 1752 psotfx
1302 1752 psotfx
                                $sql = "INSERT INTO " . AUTH_ACCESS_TABLE . " (group_id, forum_id, auth_mod) VALUES ($group_id, ".$row['forum_id'].", 1)";
1303 1752 psotfx
                                query($sql, "Couldn't set moderator (user_id = " . $row['user_id'] . ") for forum " . $row['forum_id'] . ".");
1304 2093 psotfx
1305 2093 psotfx
                                print "<span class=\"ok\"><b>OK</b></span><br />\n";
1306 1752 psotfx
                        }
1307 2511 psotfx
1308 2511 psotfx
                        print " * Setting correct user_level for moderators ::";
1309 2511 psotfx
                        flush();
1310 2511 psotfx
1311 2511 psotfx
                        $sql = "SELECT DISTINCT u.user_id
1312 2511 psotfx
                                FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug, " . AUTH_ACCESS_TABLE . " aa
1313 2511 psotfx
                                WHERE aa.auth_mod = 1
1314 2511 psotfx
                                        AND ug.group_id = aa.group_id
1315 2511 psotfx
                                        AND u.user_id = ug.user_id
1316 2511 psotfx
                                        AND u.user_level <> " . ADMIN;
1317 2511 psotfx
                        $result = query($sql, "Couldn't obtain list of moderators");
1318 2511 psotfx
1319 2511 psotfx
                        if ( $row = $db->sql_fetchrow($result) )
1320 2511 psotfx
                        {
1321 2511 psotfx
                                $ug_sql = '';
1322 2511 psotfx
1323 2511 psotfx
                                do
1324 2511 psotfx
                                {
1325 2511 psotfx
                                        $ug_sql .= ( ( $ug_sql != '' ) ? ', ' : '' ) . $row['user_id'];
1326 2511 psotfx
                                }
1327 2511 psotfx
                                while ( $row = $db->sql_fetchrow($result) );
1328 2511 psotfx
1329 2511 psotfx
                                $sql = "UPDATE " . USERS_TABLE . "
1330 2511 psotfx
                                        SET user_level = " . MOD . "
1331 2511 psotfx
                                        WHERE user_id IN ($ug_sql)";
1332 2511 psotfx
                                query($sql, "Couldn't set moderator status for users");
1333 2511 psotfx
                        }
1334 2511 psotfx
1335 2511 psotfx
                        print "<span class=\"ok\"><b>OK</b></span><br />\n";
1336 1752 psotfx
1337 1752 psotfx
                        end_step('convert_privforums');
1338 1752 psotfx
1339 1752 psotfx
                case 'convert_privforums':
1340 1752 psotfx
                        $sql = "SELECT fa.*, f.forum_name
1341 1752 psotfx
                                        FROM forum_access fa
1342 1752 psotfx
                                        LEFT JOIN " . FORUMS_TABLE . " f ON fa.forum_id = f.forum_id
1343 1752 psotfx
                                        ORDER BY fa.forum_id, fa.user_id";
1344 1752 psotfx
                        $forum_access = query($sql, "Couldn't get list with special forum access (forum_access)");
1345 1752 psotfx
1346 1752 psotfx
                        $forum_id = -1;
1347 1752 psotfx
                        while( $row = $db->sql_fetchrow($forum_access) )
1348 1752 psotfx
                        {
1349 1752 psotfx
                                // Iterate trough access table
1350 2093 psotfx
                                if ( $row['forum_id'] != $forum_id )
1351 1242 bartvb
                                {
1352 1752 psotfx
                                        // This is a new forum, create new group.
1353 1752 psotfx
                                        $forum_id = $row['forum_id'];
1354 1752 psotfx
1355 2093 psotfx
                                        print " * Creating new group for forum $forum_id :: ";
1356 2093 psotfx
                                        flush();
1357 1752 psotfx
1358 1752 psotfx
                                        $sql = "INSERT INTO " . GROUPS_TABLE . " (group_type, group_name, group_description, group_moderator, group_single_user)
1359 1752 psotfx
                                                VALUES (" . GROUP_HIDDEN . ", '" . addslashes($row['forum_name']) . " Group', 'Converted Private Forum Group', " . $row['user_id'] . ", 0)";
1360 1752 psotfx
                                        $result = query($sql, "Couldn't create group for ".$row['forum_name']);
1361 1752 psotfx
1362 1752 psotfx
                                        $group_id = $db->sql_nextid();
1363 1752 psotfx
1364 2093 psotfx
                                        if ( $group_id <= 0 )
1365 1752 psotfx
                                        {
1366 1752 psotfx
                                                print "<font color=\"red\">Group creation failed. Aborting creation of groups...<br></font>\n";
1367 1752 psotfx
                                                continue 2;
1368 1752 psotfx
                                        }
1369 1752 psotfx
1370 2093 psotfx
                                        print "<span class=\"ok\"><b>OK</b></span><br />\n";
1371 1752 psotfx
1372 2093 psotfx
                                        print " * Creating auth_access group for forum $forum_id :: ";
1373 2093 psotfx
                                        flush();
1374 2093 psotfx
1375 2400 psotfx
                                        $sql = "INSERT INTO " . AUTH_ACCESS_TABLE . " (group_id, forum_id, auth_view, auth_read, auth_post, auth_reply, auth_edit, auth_delete, auth_sticky, auth_announce, auth_vote, auth_pollcreate)
1376 2400 psotfx
                                                VALUES ($group_id, $forum_id, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1)";
1377 1752 psotfx
                                        $result = query($sql, "Unable to set group auth access.");
1378 1752 psotfx
1379 2093 psotfx
                                        if ( $db->sql_affectedrows($result) <= 0 )
1380 1752 psotfx
                                        {
1381 1752 psotfx
                                                print "<font color=\"red\">Group creation failed. Aborting creation of groups...</font><br>\n";
1382 1752 psotfx
                                                continue 2;
1383 1752 psotfx
                                        }
1384 2093 psotfx
1385 2093 psotfx
                                        print "<span class=\"ok\"><b>OK</b></span><br />\n";
1386 1242 bartvb
                                }
1387 1242 bartvb
1388 1752 psotfx
                                // Add user to the group
1389 1752 psotfx
                                $user_id = $row['user_id'];
1390 1752 psotfx
1391 1752 psotfx
                                $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
1392 1752 psotfx
                                        VALUES ($group_id, $user_id, 0)";
1393 1752 psotfx
                                query($sql, "Unable to add user_id $user_id to group_id $group_id <br>\n");
1394 1242 bartvb
                        }
1395 1242 bartvb
1396 1752 psotfx
                        end_step('update_schema');
1397 1242 bartvb
1398 1752 psotfx
                case 'update_schema':
1399 1752 psotfx
                        $rename = array(
1400 1752 psotfx
                                $table_prefix . "users" => array(
1401 1752 psotfx
                                        "user_interests" => "user_intrest",
1402 1752 psotfx
                                        "user_allowsmile" => "user_desmile",
1403 1752 psotfx
                                        "user_allowhtml" => "user_html",
1404 1752 psotfx
                                        "user_allowbbcode" => "user_bbcode",
1405 1752 psotfx
                                        "user_style" => "user_theme"
1406 1752 psotfx
                                ),
1407 1752 psotfx
                                $table_prefix . "privmsgs" => array(
1408 1752 psotfx
                                         "privmsgs_id" => "msg_id",
1409 1752 psotfx
                                         "privmsgs_from_userid" => "from_userid",
1410 1752 psotfx
                                         "privmsgs_to_userid" => "to_userid",
1411 1752 psotfx
                                         "privmsgs_date" => "msg_time",
1412 1752 psotfx
                                         "privmsgs_ip" => "poster_ip",
1413 1752 psotfx
                                         "privmsgs_type" => "msg_status"
1414 1752 psotfx
                                ),
1415 1752 psotfx
                                $table_prefix . "smilies" => array(
1416 1752 psotfx
                                        "smilies_id" => "id"
1417 1752 psotfx
                                )
1418 1752 psotfx
                        );
1419 1752 psotfx
1420 1752 psotfx
                        $schema = get_schema();
1421 1752 psotfx
1422 1752 psotfx
                        $table_def = $schema['table_def'];
1423 1752 psotfx
                        $field_def = $schema['field_def'];
1424 1752 psotfx
1425 1752 psotfx
                        // Loop tables in schema
1426 2093 psotfx
                        while (list($table, $table_def) = @each($field_def))
1427 1242 bartvb
                        {
1428 1752 psotfx
                                // Loop fields in table
1429 2093 psotfx
                                print " * Updating table '$table' :: ";
1430 1752 psotfx
                                flush();
1431 1752 psotfx
1432 1752 psotfx
                                $sql = "SHOW FIELDS
1433 1752 psotfx
                                        FROM $table";
1434 1752 psotfx
                                $result = query($sql, "Can't get definition of current $table table");
1435 1752 psotfx
1436 2093 psotfx
                                while( $row = $db->sql_fetchrow($result) )
1437 1242 bartvb
                                {
1438 2093 psotfx
                                        $current_fields[] = $row['Field'];
1439 1242 bartvb
                                }
1440 1242 bartvb
1441 1752 psotfx
                                $alter_sql = "ALTER TABLE $table ";
1442 1752 psotfx
                                while (list($field, $definition) = each($table_def))
1443 1242 bartvb
                                {
1444 2093 psotfx
                                        if ( $field == '' )
1445 1752 psotfx
                                        {
1446 1752 psotfx
                                                // Skip empty fields if any (shouldn't be needed)
1447 1752 psotfx
                                                continue;
1448 1752 psotfx
                                        }
1449 1752 psotfx
1450 1752 psotfx
                                        $type = $definition['type'];
1451 1752 psotfx
                                        $size = $definition['size'];
1452 1752 psotfx
1453 1752 psotfx
                                        $default = isset($definition['default']) ? "DEFAULT " . $definition['default'] : '';
1454 1752 psotfx
1455 1752 psotfx
                                        $notnull = $definition['notnull'] == 1 ? 'NOT NULL' : '';
1456 1752 psotfx
1457 1752 psotfx
                                        $auto_increment = $definition['auto_increment'] == 1 ? 'auto_increment' : '';
1458 1752 psotfx
1459 1752 psotfx
                                        $oldfield = isset($rename[$table][$field]) ? $rename[$table][$field] : $field;
1460 1752 psotfx
1461 2093 psotfx
                                        if ( !inarray($field, $current_fields) && $oldfield == $field )
1462 1752 psotfx
                                        {
1463 1752 psotfx
                                                // If the current is not a key of $current_def and it is not a field that is
1464 1752 psotfx
                                                // to be renamed then the field doesn't currently exist.
1465 1752 psotfx
                                                $changes[] = " ADD $field " . $create_def[$table][$field];
1466 1752 psotfx
                                        }
1467 1752 psotfx
                                        else
1468 1752 psotfx
                                        {
1469 1752 psotfx
                                                $changes[] = " CHANGE $oldfield $field " . $create_def[$table][$field];
1470 1752 psotfx
                                        }
1471 1242 bartvb
                                }
1472 1752 psotfx
1473 1752 psotfx
                                $alter_sql .= join(',', $changes);
1474 1752 psotfx
                                unset($changes);
1475 1752 psotfx
                                unset($current_fields);
1476 1752 psotfx
1477 1752 psotfx
                                $sql = "SHOW INDEX
1478 1752 psotfx
                                        FROM $table";
1479 1752 psotfx
                                $result = query($sql, "Couldn't get list of indices for table $table");
1480 1752 psotfx
1481 1752 psotfx
                                unset($indices);
1482 1752 psotfx
1483 1752 psotfx
                                while( $row = $db->sql_fetchrow($result) )
1484 1242 bartvb
                                {
1485 1752 psotfx
                                        $indices[] = $row['Key_name'];
1486 1242 bartvb
                                }
1487 1242 bartvb
1488 2093 psotfx
                                while ( list($key_name, $key_field) = each($key_def[$table]) )
1489 1242 bartvb
                                {
1490 2093 psotfx
                                        if ( !inarray($key_name, $indices) )
1491 1752 psotfx
                                        {
1492 1752 psotfx
                                                $alter_sql .= ($key_name == 'PRIMARY') ? ", ADD PRIMARY KEY ($key_field)" : ", ADD INDEX $key_name ($key_field)";
1493 1752 psotfx
                                        }
1494 1242 bartvb
                                }
1495 1752 psotfx
                                query($alter_sql, "Couldn't alter table $table");
1496 2093 psotfx
1497 2093 psotfx
                                print "<span class=\"ok\"><b>OK</b></span><br />\n";
1498 1752 psotfx
                                flush();
1499 1752 psotfx
                        }
1500 1752 psotfx
1501 1752 psotfx
                        end_step('convert_forums');
1502 1752 psotfx
1503 1752 psotfx
                case 'convert_forums':
1504 1752 psotfx
                        $sql = "SELECT *
1505 1752 psotfx
                                FROM " . FORUMS_TABLE;
1506 1752 psotfx
                        $result = query($sql, "Couldn't get list with all forums");
1507 1752 psotfx
1508 1752 psotfx
                        while( $row = $db->sql_fetchrow($result) )
1509 1752 psotfx
                        {
1510 2093 psotfx
                                print " * Converting forum '" . $row['forum_name'] . "' :: ";
1511 2093 psotfx
                                flush();
1512 2093 psotfx
1513 1752 psotfx
                                // forum_access: (only concerns posting)
1514 1752 psotfx
                                //                1 = Registered users only
1515 1752 psotfx
                                //                2 = Anonymous Posting
1516 1752 psotfx
                                //                3 = Moderators/Administrators only
1517 2093 psotfx
                                switch( $row['forum_access'] )
1518 1752 psotfx
                                {
1519 1752 psotfx
                                        case 1:
1520 1752 psotfx
                                                // Public forum, no anonymous posting
1521 2400 psotfx
                                                $auth_view                        = AUTH_ALL;
1522 2400 psotfx
                                                $auth_read                        = AUTH_ALL;
1523 1752 psotfx
                                                $auth_post                        = AUTH_REG;
1524 1752 psotfx
                                                $auth_reply                        = AUTH_REG;
1525 1752 psotfx
                                                $auth_edit                        = AUTH_REG;
1526 1752 psotfx
                                                $auth_delete                = AUTH_REG;
1527 1752 psotfx
                                                $auth_vote                        = AUTH_REG;
1528 1752 psotfx
                                                $auth_pollcreate        = AUTH_REG;
1529 1752 psotfx
                                                $auth_sticky                = AUTH_MOD;
1530 1752 psotfx
                                                $auth_announce                = AUTH_MOD;
1531 1752 psotfx
                                                break;
1532 1752 psotfx
                                        case 2:
1533 1752 psotfx
                                                $auth_post                        = AUTH_ALL;
1534 1752 psotfx
                                                $auth_reply                        = AUTH_ALL;
1535 2400 psotfx
                                                $auth_edit                        = AUTH_REG;
1536 2400 psotfx
                                                $auth_delete                = AUTH_REG;
1537 1752 psotfx
                                                $auth_vote                        = AUTH_ALL;
1538 1752 psotfx
                                                $auth_pollcreate        = AUTH_ALL;
1539 1752 psotfx
                                                $auth_sticky                = AUTH_MOD;
1540 1752 psotfx
                                                $auth_announce                = AUTH_MOD;
1541 1752 psotfx
                                                break;
1542 1752 psotfx
                                        default:
1543 1752 psotfx
                                                $auth_post                        = AUTH_MOD;
1544 1752 psotfx
                                                $auth_reply                        = AUTH_MOD;
1545 1752 psotfx
                                                $auth_edit                        = AUTH_MOD;
1546 1752 psotfx
                                                $auth_delete                = AUTH_MOD;
1547 1752 psotfx
                                                $auth_vote                        = AUTH_MOD;
1548 1752 psotfx
                                                $auth_pollcreate        = AUTH_MOD;
1549 1752 psotfx
                                                $auth_sticky                = AUTH_MOD;
1550 1752 psotfx
                                                $auth_announce                = AUTH_MOD;
1551 1752 psotfx
                                                break;
1552 1752 psotfx
                                }
1553 1242 bartvb
1554 2400 psotfx
                                // Old auth structure:
1555 2400 psotfx
                                // forum_type: (only concerns viewing)
1556 2400 psotfx
                                //                0 = Public
1557 2400 psotfx
                                //                1 = Private
1558 2400 psotfx
                                switch( $row['forum_type'] )
1559 2400 psotfx
                                {
1560 2400 psotfx
                                        case 0:
1561 2400 psotfx
                                                $auth_view                        = AUTH_ALL;
1562 2400 psotfx
                                                $auth_read                        = AUTH_ALL;
1563 2400 psotfx
                                                break;
1564 2400 psotfx
                                        default:
1565 2400 psotfx
                                                //
1566 2400 psotfx
                                                // Make it really private ...
1567 2400 psotfx
                                                //
1568 2400 psotfx
                                                $auth_view                        = AUTH_ACL;
1569 2400 psotfx
                                                $auth_read                        = AUTH_ACL;
1570 2400 psotfx
                                                $auth_post                        = AUTH_ACL;
1571 2400 psotfx
                                                $auth_reply                        = AUTH_ACL;
1572 2400 psotfx
                                                $auth_edit                        = AUTH_ACL;
1573 2400 psotfx
                                                $auth_delete                = AUTH_ACL;
1574 2400 psotfx
                                                $auth_vote                        = AUTH_ACL;
1575 2400 psotfx
                                                $auth_pollcreate        = AUTH_ACL;
1576 2400 psotfx
                                                $auth_sticky                = AUTH_ACL;
1577 2400 psotfx
                                                $auth_announce                = AUTH_MOD;
1578 2400 psotfx
                                                break;
1579 2400 psotfx
                                }
1580 2400 psotfx
1581 1752 psotfx
                                $sql = "UPDATE " . FORUMS_TABLE . " SET
1582 1752 psotfx
                                        auth_view = $auth_view,
1583 1752 psotfx
                                        auth_read = $auth_read,
1584 1752 psotfx
                                        auth_post = $auth_post,
1585 1752 psotfx
                                        auth_reply = $auth_reply,
1586 1752 psotfx
                                        auth_edit = $auth_edit,
1587 1752 psotfx
                                        auth_delete = $auth_delete,
1588 1752 psotfx
                                        auth_vote = $auth_vote,
1589 1752 psotfx
                                        auth_pollcreate = $auth_pollcreate,
1590 1752 psotfx
                                        auth_sticky = $auth_sticky,
1591 1752 psotfx
                                        auth_announce = $auth_announce
1592 1752 psotfx
                                        WHERE forum_id = ". $row['forum_id'];
1593 1752 psotfx
                                query($sql, "Was unable to update forum permissions!");
1594 2093 psotfx
1595 2093 psotfx
                                print "<span class=\"ok\"><b>OK</b></span><br />\n";
1596 1752 psotfx
                        }
1597 1242 bartvb
1598 1752 psotfx
                        end_step('insert_themes');
1599 1242 bartvb
1600 1752 psotfx
                case 'insert_themes':
1601 2093 psotfx
                        print " * Inserting new values into themes table :: ";
1602 1752 psotfx
1603 1752 psotfx
                        @reset($inserts);
1604 1752 psotfx
                        while( list($table, $inserts_table) = each($inserts) )
1605 1250 bartvb
                        {
1606 2093 psotfx
                                if ( $table == THEMES_TABLE )
1607 1752 psotfx
                                {
1608 2093 psotfx
                                        $per_pct = ceil( count($inserts_table) / 40 );
1609 2093 psotfx
                                        $inc = 0;
1610 2093 psotfx
1611 1752 psotfx
                                        while( list($nr, $insert) = each($inserts_table) )
1612 1752 psotfx
                                        {
1613 1752 psotfx
                                                query($insert, "Couldn't insert value into " . THEMES_TABLE);
1614 1752 psotfx
1615 2093 psotfx
                                                $inc++;
1616 2093 psotfx
                                                if ( $inc == $per_pct )
1617 2093 psotfx
                                                {
1618 2093 psotfx
                                                        print ".";
1619 2093 psotfx
                                                        flush();
1620 2093 psotfx
                                                        $inc = 0;
1621 2093 psotfx
                                                }
1622 1752 psotfx
                                        }
1623 1752 psotfx
                                }
1624 1250 bartvb
                        }
1625 1250 bartvb
1626 2093 psotfx
                        print " <span class=\"ok\"><b>OK</b></span><br />\n";
1627 2093 psotfx
                        end_step('update_topics');
1628 1752 psotfx
1629 2093 psotfx
                case 'update_topics':
1630 2093 psotfx
                        $sql = "SELECT MAX(topic_id) AS max_topic
1631 2093 psotfx
                                FROM " . TOPICS_TABLE;
1632 2093 psotfx
                        $result = query($sql, "Couldn't get max topic id");
1633 1752 psotfx
1634 2093 psotfx
                        $row = $db->sql_fetchrow($result);
1635 1752 psotfx
1636 2093 psotfx
                        $maxid = $row['max_topic'];
1637 1752 psotfx
1638 2093 psotfx
                        lock_tables(1, array(TOPICS_TABLE, POSTS_TABLE));
1639 1752 psotfx
1640 2093 psotfx
                        $batchsize = 1000;
1641 2093 psotfx
                        for($i = 0; $i <= $maxid; $i += $batchsize)
1642 2093 psotfx
                        {
1643 2093 psotfx
                                $batchstart = $i + 1;
1644 2093 psotfx
                                $batchend = $i + $batchsize;
1645 2093 psotfx
1646 2093 psotfx
                                print " * Setting topic first post_id ( $batchstart to $batchend ) :: ";
1647 2093 psotfx
                                flush();
1648 1752 psotfx
1649 2093 psotfx
                                $sql = "SELECT MIN(post_id) AS first_post_id, topic_id
1650 2093 psotfx
                                        FROM " . POSTS_TABLE . "
1651 2093 psotfx
                                        WHERE topic_id
1652 2093 psotfx
                                                BETWEEN $batchstart
1653 2093 psotfx
                                                        AND $batchend
1654 2093 psotfx
                                        GROUP BY topic_id
1655 2093 psotfx
                                        ORDER BY topic_id ASC";
1656 2093 psotfx
                                $result = query($sql, "Couldn't get post id data");
1657 1752 psotfx
1658 2093 psotfx
                                $per_pct = ceil( $db->sql_numrows($result) / 40 );
1659 2093 psotfx
                                $inc = 0;
1660 1752 psotfx
1661 2093 psotfx
                                if ( $row = $db->sql_fetchrow($result) )
1662 2093 psotfx
                                {
1663 2093 psotfx
                                        do
1664 2093 psotfx
                                        {
1665 2093 psotfx
                                                $sql = "UPDATE " . TOPICS_TABLE . "
1666 2093 psotfx
                                                        SET topic_first_post_id = " . $row['first_post_id'] . "
1667 2093 psotfx
                                                        WHERE topic_id = " . $row['topic_id'];
1668 2093 psotfx
                                                query($sql, "Couldn't update topic first post id in topic :: $topic_id");
1669 1752 psotfx
1670 2093 psotfx
                                                $inc++;
1671 2093 psotfx
                                                if ( $inc == $per_pct )
1672 1752 psotfx
                                                {
1673 2093 psotfx
                                                        print ".";
1674 2093 psotfx
                                                        flush();
1675 2093 psotfx
                                                        $inc = 0;
1676 1752 psotfx
                                                }
1677 2093 psotfx
                                        }
1678 2093 psotfx
                                        while ( $row = $db->sql_fetchrow($result) );
1679 1519 bartvb
                                }
1680 1752 psotfx
1681 2093 psotfx
                                print " <span class=\"ok\"><b>OK</b></span><br />\n";
1682 1519 bartvb
                        }
1683 1519 bartvb
1684 2093 psotfx
                        lock_tables(0);
1685 2093 psotfx
                        end_step('final_configuration');
1686 1242 bartvb
1687 2093 psotfx
                case 'final_configuration':
1688 1752 psotfx
                        //
1689 1752 psotfx
                        // Update forum last post information
1690 1752 psotfx
                        //
1691 1752 psotfx
                        $sql = "SELECT forum_id, forum_name
1692 1752 psotfx
                                FROM " . FORUMS_TABLE;
1693 1752 psotfx
                        $f_result = query($sql, "Couldn't obtain forum_ids");
1694 1752 psotfx
1695 1752 psotfx
                        while( $forum_row = $db->sql_fetchrow($f_result) )
1696 1242 bartvb
                        {
1697 2093 psotfx
                                print " * Updating '" . $forum_row['forum_name'] . "' post info :: ";
1698 1752 psotfx
                                flush();
1699 1752 psotfx
1700 1752 psotfx
                                $id = $forum_row['forum_id'];
1701 1752 psotfx
1702 2093 psotfx
                                $sql = "SELECT MIN(p.post_id) AS first_post, MAX(p.post_id) AS last_post
1703 1752 psotfx
                                        FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
1704 1752 psotfx
                                        WHERE p.forum_id = $id
1705 1752 psotfx
                                                AND p.topic_id = t.topic_id";
1706 1752 psotfx
                                $result = query($sql, "Could not get post ID forum post information :: $id");
1707 1752 psotfx
1708 2093 psotfx
                                if ( $row = $db->sql_fetchrow($result) )
1709 1242 bartvb
                                {
1710 2093 psotfx
                                        $first_post = ( $row['first_post'] ) ? $row['first_post'] : 0;
1711 1752 psotfx
                                        $last_post = ($row['last_post']) ? $row['last_post'] : 0;
1712 1242 bartvb
                                }
1713 1752 psotfx
                                else
1714 1242 bartvb
                                {
1715 2093 psotfx
                                        $first_post = 0;
1716 1752 psotfx
                                        $last_post = 0;
1717 1242 bartvb
                                }
1718 1752 psotfx
1719 1752 psotfx
                                $sql = "SELECT COUNT(post_id) AS total
1720 1752 psotfx
                                        FROM " . POSTS_TABLE . "
1721 1752 psotfx
                                        WHERE forum_id = $id";
1722 1752 psotfx
                                $result = query($sql, "Could not get post count forum post information :: $id");
1723 1752 psotfx
1724 2093 psotfx
                                if ( $row = $db->sql_fetchrow($result) )
1725 1752 psotfx
                                {
1726 1752 psotfx
                                        $total_posts = ($row['total']) ? $row['total'] : 0;
1727 1752 psotfx
                                }
1728 1242 bartvb
                                else
1729 1242 bartvb
                                {
1730 1752 psotfx
                                        $total_posts = 0;
1731 1242 bartvb
                                }
1732 1752 psotfx
1733 1752 psotfx
                                $sql = "SELECT COUNT(topic_id) AS total
1734 1752 psotfx
                                        FROM " . TOPICS_TABLE . "
1735 1752 psotfx
                                        WHERE forum_id = $id
1736 1752 psotfx
                                                AND topic_status <> " . TOPIC_MOVED;
1737 1752 psotfx
                                $result = query($sql, "Could not get topic count forum post information :: $id");
1738 1752 psotfx
1739 2093 psotfx
                                if ( $row = $db->sql_fetchrow($result) )
1740 1438 bartvb
                                {
1741 1752 psotfx
                                        $total_topics = ($row['total']) ? $row['total'] : 0;
1742 1438 bartvb
                                }
1743 1752 psotfx
                                else
1744 1752 psotfx
                                {
1745 1752 psotfx
                                        $total_topics = 0;
1746 1752 psotfx
                                }
1747 1752 psotfx
1748 1752 psotfx
                                $sql = "UPDATE " . FORUMS_TABLE . "
1749 1752 psotfx
                                        SET forum_last_post_id = $last_post, forum_posts = $total_posts, forum_topics = $total_topics
1750 1752 psotfx
                                        WHERE forum_id = $id";
1751 1752 psotfx
                                query($sql, "Could not update forum post information :: $id");
1752 1752 psotfx
1753 2093 psotfx
                                print "<span class=\"ok\"><b>OK</b></span><br />\n";
1754 1438 bartvb
                        }
1755 1752 psotfx
1756 2093 psotfx
                        print "<br />\n * Update default user and finalise configuration :: ";
1757 1242 bartvb
                        flush();
1758 1242 bartvb
1759 1752 psotfx
                        //
1760 1752 psotfx
                        // Update the default admin user with their information.
1761 1752 psotfx
                        //
1762 1752 psotfx
                        $sql = "SELECT MIN(user_regdate) AS oldest_time
1763 1752 psotfx
                                FROM " . USERS_TABLE . "
1764 2433 thefinn
                                WHERE user_regdate > 0 AND user_id > 0";
1765 1752 psotfx
                        $result = query($sql, "Couldn't obtain oldest post time");
1766 1752 psotfx
1767 1752 psotfx
                        $row = $db->sql_fetchrow($result);
1768 1752 psotfx
1769 1752 psotfx
                        $sql = "INSERT INTO " . $table_prefix . "config (config_name, config_value)
1770 1752 psotfx
                                VALUES ('board_startdate', " . $row['oldest_time']  . ")";
1771 1752 psotfx
                        query($sql, "Couldn't insert board_startdate");
1772 1752 psotfx
1773 2363 the_systech
                        $sql = "UPDATE " . $table_prefix . "config
1774 2363 the_systech
                                SET config_value = '" . $server_name . "'
1775 2363 the_systech
                                WHERE config_name = 'server_name'
1776 2363 the_systech
                                        OR config_name = 'cookie_domain'";
1777 2363 the_systech
                        query($sql, "Couldn't insert Board Server domain");
1778 2363 the_systech
1779 2363 the_systech
                        $sql = "UPDATE " . $table_prefix . "config
1780 2363 the_systech
                                SET config_value = '" . $server_port . "'
1781 2363 the_systech
                                WHERE config_name = 'server_port'";
1782 2363 the_systech
                        query($sql, "Couldn't insert Board server port");
1783 2363 the_systech
1784 2363 the_systech
                        $sql = "UPDATE " . $table_prefix . "config
1785 2363 the_systech
                                SET config_value = '" . $board_email . "'
1786 2363 the_systech
                                WHERE config_name = 'board_email'";
1787 2363 the_systech
                        query($sql, "Couldn't insert Board admin email");
1788 2363 the_systech
1789 2363 the_systech
                        $sql = "UPDATE " . $table_prefix . "config
1790 2363 the_systech
                                SET config_value = '" . $script_path . "'
1791 2363 the_systech
                                WHERE config_name = 'script_path'";
1792 2785 dougk_ff7
                        query($sql, "Couldn't insert Board script path");
1793 2363 the_systech
1794 1752 psotfx
                        //
1795 1752 psotfx
                        // Change session table to HEAP if MySQL version matches
1796 1752 psotfx
                        //
1797 1752 psotfx
                        $sql = "SELECT VERSION() AS mysql_version";
1798 1752 psotfx
                        $result = query($sql, "Couldn't obtain MySQL Version");
1799 1752 psotfx
1800 1752 psotfx
                        $row = $db->sql_fetchrow($result);
1801 1752 psotfx
1802 1752 psotfx
                        $version = $row['mysql_version'];
1803 1752 psotfx
1804 2093 psotfx
                        if ( preg_match("/^(3\.23)|(4\.)/", $version) )
1805 1519 bartvb
                        {
1806 1752 psotfx
                                $sql = "ALTER TABLE " . $table_prefix . "sessions
1807 2723 psotfx
                                        TYPE=HEAP MAX_ROWS=500";
1808 1771 psotfx
                                $db->sql_query($sql);
1809 1519 bartvb
                        }
1810 1752 psotfx
1811 2093 psotfx
                        echo "<span class=\"ok\"><b>OK</b></span><br />\n";
1812 2093 psotfx
                        end_step('drop_fields');
1813 1752 psotfx
1814 2093 psotfx
                case 'drop_fields':
1815 1752 psotfx
                        $fields = array(
1816 1752 psotfx
                                BANLIST_TABLE => array("ban_start", "ban_end", "ban_time_type"),
1817 1758 psotfx
                                FORUMS_TABLE => array("forum_access", "forum_moderator", "forum_type"),
1818 1752 psotfx
                                PRIVMSGS_TABLE => array("msg_text"),
1819 1752 psotfx
                                RANKS_TABLE => array("rank_max"),
1820 2356 the_systech
                                SMILIES_TABLE => array("emotion"),
1821 2356 the_systech
                                TOPICS_TABLE => array("topic_notify")
1822 1752 psotfx
                        );
1823 1752 psotfx
1824 1752 psotfx
                        while( list($table, $field_data) = each($fields) )
1825 1519 bartvb
                        {
1826 1752 psotfx
                                for($i = 0; $i < count($field_data); $i++)
1827 1242 bartvb
                                {
1828 2093 psotfx
                                        print " * Drop field '" . $field_data[$i] . "' in '$table' :: ";
1829 1752 psotfx
                                        flush();
1830 1752 psotfx
1831 1752 psotfx
                                        $sql = "ALTER TABLE $table
1832 1752 psotfx
                                                DROP COLUMN " . $field_data[$i];
1833 1752 psotfx
                                        query($sql, "Couldn't drop field :: " . $field_data[$i] . " from table :: $table");
1834 1752 psotfx
1835 2093 psotfx
                                        print "<span class=\"ok\"><b>OK</b></span><br />\n";
1836 1752 psotfx
1837 1242 bartvb
                                }
1838 1242 bartvb
                        }
1839 1242 bartvb
1840 2093 psotfx
                        end_step('drop_tables');
1841 1752 psotfx
1842 2093 psotfx
                case 'drop_tables':
1843 1766 psotfx
                        $drop_tables = array('access', 'forum_access', 'forum_mods', 'headermetafooter', 'whosonline', $table_prefix . 'old_config');
1844 1752 psotfx
1845 1752 psotfx
                        for($i = 0; $i < count($drop_tables); $i++)
1846 1752 psotfx
                        {
1847 2093 psotfx
                                print " * Dropping table '" . $drop_tables[$i] . "' :: ";
1848 1752 psotfx
                                flush();
1849 1752 psotfx
1850 1752 psotfx
                                $sql = "DROP TABLE " . $drop_tables[$i];
1851 1752 psotfx
                                query($sql, "Couldn't drop table :: " . $drop_tables[$i]);
1852 1752 psotfx
1853 2093 psotfx
                                print "<span class=\"ok\"><b>OK</b></span><br />\n";
1854 1752 psotfx
                        }
1855 1752 psotfx
1856 2732 psotfx
                        end_step('fulltext_search_indexing');
1857 2732 psotfx
1858 2732 psotfx
                case 'fulltext_search_indexing':
1859 2732 psotfx
                        //
1860 2732 psotfx
                        // Generate search word list
1861 2732 psotfx
                        //
1862 2732 psotfx
                        // Fetch a batch of posts_text entries
1863 2732 psotfx
                        //
1864 2732 psotfx
                        $sql = "SELECT COUNT(*) as total, MAX(post_id) as max_post_id
1865 2732 psotfx
                                FROM " . POSTS_TEXT_TABLE;
1866 2732 psotfx
                        $result = query($sql, "Couldn't get post count totals");
1867 2732 psotfx
1868 2732 psotfx
                        $max_post_id = $db->sql_fetchrow($result);
1869 2732 psotfx
1870 2732 psotfx
                        $totalposts = $max_post_id['total'];
1871 2732 psotfx
                        $max_post_id = $max_post_id['max_post_id'];
1872 2732 psotfx
                        $per_percent = round(( $totalposts / 500 ) * 10);
1873 2732 psotfx
1874 2732 psotfx
                        $postcounter = ( !isset($HTTP_GET_VARS['batchstart']) ) ? 0 : $HTTP_GET_VARS['batchstart'];
1875 2732 psotfx
1876 2732 psotfx
                        $batchsize = 150; // Process this many posts per loop
1877 2732 psotfx
                        $batchcount = 0;
1878 2732 psotfx
                        $total_percent = 0;
1879 2732 psotfx
1880 2732 psotfx
                        for(;$postcounter <= $max_post_id; $postcounter += $batchsize)
1881 2732 psotfx
                        {
1882 2732 psotfx
                                $batchstart = $postcounter + 1;
1883 2732 psotfx
                                $batchend = $postcounter + $batchsize;
1884 2732 psotfx
                                $batchcount++;
1885 2732 psotfx
1886 2732 psotfx
                                print " * Fulltext Indexing ( $batchstart to $batchend ) :: ";
1887 2732 psotfx
                                flush();
1888 2732 psotfx
1889 2732 psotfx
                                $sql = "SELECT *
1890 2732 psotfx
                                        FROM " . POSTS_TEXT_TABLE ."
1891 2732 psotfx
                                        WHERE post_id
1892 2732 psotfx
                                                BETWEEN $batchstart
1893 2732 psotfx
                                                        AND $batchend";
1894 2732 psotfx
                                $posts_result = query($sql, "Couldn't obtain post_text");
1895 2732 psotfx
1896 2732 psotfx
                                $per_pct = ceil( $db->sql_numrows($posts_result) / 40 );
1897 2732 psotfx
                                $inc = 0;
1898 2732 psotfx
1899 2732 psotfx
                                if ( $row = $db->sql_fetchrow($posts_result) )
1900 2732 psotfx
                                {
1901 2732 psotfx
                                        do
1902 2732 psotfx
                                        {
1903 2732 psotfx
                                                add_search_words($row['post_id'], $row['post_text'], $row['post_subject']);
1904 2732 psotfx
1905 2732 psotfx
                                                $inc++;
1906 2732 psotfx
                                                if ( $inc == $per_pct )
1907 2732 psotfx
                                                {
1908 2732 psotfx
                                                        print ".";
1909 2732 psotfx
                                                        flush();
1910 2732 psotfx
                                                        $inc = 0;
1911 2732 psotfx
                                                }
1912 2732 psotfx
                                        }
1913 2732 psotfx
                                        while( $row = $db->sql_fetchrow($posts_result) );
1914 2732 psotfx
                                }
1915 2732 psotfx
1916 2732 psotfx
                                $db->sql_freeresult($posts_result);
1917 2732 psotfx
1918 2732 psotfx
                                // Remove common words after the first 2 batches and after every 4th batch after that.
1919 2732 psotfx
                                if ( $batchcount % 4 == 3 )
1920 2732 psotfx
                                {
1921 2732 psotfx
                                        remove_common('global', 0.4);
1922 2732 psotfx
                                }
1923 2732 psotfx
1924 2732 psotfx
                                print " <span class=\"ok\"><b>OK</b></span><br />\n";
1925 2732 psotfx
                        }
1926 2732 psotfx
1927 2093 psotfx
                        echo "\n<br /><br />\n\n<font size=\"+3\"><b>UPGRADE COMPLETED</b></font><br />\n";
1928 1242 bartvb
        }
1929 1242 bartvb
}
1930 1752 psotfx
1931 1752 psotfx
print "<br />If the upgrade completed without error you may click <a href=\"index.$phpEx\">Here</a> to proceed to the index<br />";
1932 1752 psotfx
1933 2093 psotfx
common_footer();
1934 2093 psotfx
1935 2785 dougk_ff7
?>