root / tags / release_2_0_1 / phpBB / upgrade.php
View | Annotate | Download (55.6 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 | 1752 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 816 | 1250 | bartvb | {
|
| 817 | 1752 | psotfx | $sql = "INSERT INTO " . GROUPS_TABLE . " (group_name, group_description, group_single_user) |
| 818 | 1752 | psotfx | VALUES ('" . addslashes($row['username']) . "', 'Personal User', 1)";
|
| 819 | 1752 | psotfx | query($sql, "Wasn't able to insert user ".$row['user_id']." into table ".GROUPS_TABLE); |
| 820 | 1752 | psotfx | |
| 821 | 1752 | psotfx | $group_id = $db->sql_nextid(); |
| 822 | 1752 | psotfx | |
| 823 | 2093 | psotfx | if ( $group_id != 0 ) |
| 824 | 1752 | psotfx | {
|
| 825 | 1752 | psotfx | $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending) |
| 826 | 1752 | psotfx | VALUES ($group_id, " . $row['user_id'] . ", 0)"; |
| 827 | 1752 | psotfx | query($sql, "Wasn't able to insert user ".$row['user_id']." into table ".USER_GROUP_TABLE); |
| 828 | 1752 | psotfx | } |
| 829 | 1752 | psotfx | else |
| 830 | 1752 | psotfx | {
|
| 831 | 1752 | psotfx | print "Couldn't get insert ID for " . GROUPS_TABLE . " table<br>\n"; |
| 832 | 1752 | psotfx | } |
| 833 | 1752 | psotfx | |
| 834 | 2093 | psotfx | if ( is_int($row['user_regdate']) ) |
| 835 | 1752 | psotfx | {
|
| 836 | 1752 | psotfx | // We already converted this post to the new style BBcode, skip this post. |
| 837 | 1752 | psotfx | continue; |
| 838 | 1752 | psotfx | } |
| 839 | 1752 | psotfx | |
| 840 | 1752 | psotfx | // |
| 841 | 1752 | psotfx | // Nathan's bbcode2 conversion |
| 842 | 1752 | psotfx | // |
| 843 | 1752 | psotfx | |
| 844 | 1752 | psotfx | // undo 1.2.x encoding.. |
| 845 | 1752 | psotfx | $row['user_sig'] = bbdecode(stripslashes($row['user_sig'])); |
| 846 | 1752 | psotfx | $row['user_sig'] = undo_make_clickable($row['user_sig']); |
| 847 | 1752 | psotfx | $row['user_sig'] = str_replace("<BR>", "\n", $row['user_sig']);
|
| 848 | 1752 | psotfx | |
| 849 | 1752 | psotfx | // make a uid |
| 850 | 1752 | psotfx | $uid = make_bbcode_uid(); |
| 851 | 1752 | psotfx | |
| 852 | 1752 | psotfx | // do 2.x first-pass encoding.. |
| 853 | 1752 | psotfx | $row['user_sig'] = bbencode_first_pass($row['user_sig'], $uid); |
| 854 | 1752 | psotfx | $row['user_sig'] = addslashes($row['user_sig']); |
| 855 | 1752 | psotfx | |
| 856 | 1752 | psotfx | // Check for invalid info like '-' and '?' for a lot of fields |
| 857 | 1752 | psotfx | @reset($checklength); |
| 858 | 1752 | psotfx | while($field = each($checklength)) |
| 859 | 1752 | psotfx | {
|
| 860 | 1752 | psotfx | $row[$field[1]] = strlen($row[$field[1]]) < 3 ? '' : $row[$field[1]]; |
| 861 | 1752 | psotfx | } |
| 862 | 1752 | psotfx | |
| 863 | 1752 | psotfx | preg_match('/(.*?) (\d{1,2}), (\d{4})/', $row['user_regdate'], $parts);
|
| 864 | 1752 | psotfx | $row['user_regdate'] = gmmktime(0, 0, 0, $months[$parts[1]], $parts[2], $parts[3]); |
| 865 | 1752 | psotfx | |
| 866 | 1752 | psotfx | $website = $row['user_website']; |
| 867 | 2093 | psotfx | if ( substr(strtolower($website), 0, 7) != "http://" ) |
| 868 | 1752 | psotfx | {
|
| 869 | 1752 | psotfx | $website = "http://" . $website; |
| 870 | 1752 | psotfx | } |
| 871 | 1752 | psotfx | if( strtolower($website) == 'http://' ) |
| 872 | 1752 | psotfx | {
|
| 873 | 1752 | psotfx | $website = ''; |
| 874 | 1752 | psotfx | } |
| 875 | 1752 | psotfx | $row['user_website'] = addslashes($website); |
| 876 | 1752 | psotfx | |
| 877 | 1752 | psotfx | $row['user_icq'] = (ereg("^[0-9]+$", $row['user_icq'])) ? $row['user_icq'] : '';
|
| 878 | 1752 | psotfx | reset($checklength); |
| 879 | 1752 | psotfx | |
| 880 | 1752 | psotfx | while($field = each($checklength)) |
| 881 | 1752 | psotfx | {
|
| 882 | 2093 | psotfx | if ( strlen($row[$field[1]]) < 3 ) |
| 883 | 1752 | psotfx | {
|
| 884 | 1752 | psotfx | $row[$field[1]] = ''; |
| 885 | 1752 | psotfx | } |
| 886 | 1752 | psotfx | $row[$field[1]] = addslashes($row[$field[1]]); |
| 887 | 1752 | psotfx | } |
| 888 | 1752 | psotfx | |
| 889 | 1752 | psotfx | // |
| 890 | 1752 | psotfx | // Is user a super moderator? |
| 891 | 1752 | psotfx | // |
| 892 | 1752 | psotfx | if( $row['user_level'] == 3 ) |
| 893 | 1752 | psotfx | {
|
| 894 | 1752 | psotfx | $super_mods[] = $row['user_id']; |
| 895 | 1752 | psotfx | } |
| 896 | 1752 | psotfx | |
| 897 | 1752 | psotfx | $row['user_level'] = ( $row['user_level'] == 4 ) ? ADMIN : USER; |
| 898 | 1752 | psotfx | |
| 899 | 1752 | psotfx | // |
| 900 | 1752 | psotfx | // Used to define a 'practical' group moderator user_id |
| 901 | 1752 | psotfx | // for super mods a little latter. |
| 902 | 1752 | psotfx | // |
| 903 | 1752 | psotfx | if( $first_admin == -2 && $row['user_level'] == ADMIN ) |
| 904 | 1752 | psotfx | {
|
| 905 | 1752 | psotfx | $first_admin = $row['user_id']; |
| 906 | 1752 | psotfx | } |
| 907 | 1752 | psotfx | |
| 908 | 2271 | bartvb | // |
| 909 | 2271 | bartvb | // Dutch language files have been renamed from 'nederlands' to 'dutch' |
| 910 | 2271 | bartvb | // |
| 911 | 2271 | bartvb | if( $row['user_lang'] == 'nederlands' ) |
| 912 | 2271 | bartvb | {
|
| 913 | 2271 | bartvb | $row['user_lang'] = 'dutch'; |
| 914 | 2271 | bartvb | } |
| 915 | 2271 | bartvb | |
| 916 | 1752 | psotfx | $sql = "UPDATE " . USERS_TABLE . " |
| 917 | 1752 | psotfx | SET |
| 918 | 1752 | psotfx | user_sig = '" . $row['user_sig'] . "', |
| 919 | 2093 | psotfx | user_sig_bbcode_uid = '$uid', |
| 920 | 1752 | psotfx | user_regdate = '" . $row['user_regdate'] . "', |
| 921 | 1752 | psotfx | user_website = '" . $row['user_website'] . "', |
| 922 | 1752 | psotfx | user_occ = '" . $row['user_occ'] . "', |
| 923 | 1752 | psotfx | user_email = '" . $row['user_email'] . "', |
| 924 | 1752 | psotfx | user_from = '" . $row['user_from'] . "', |
| 925 | 1752 | psotfx | user_intrest = '" . $row['user_intrest'] . "', |
| 926 | 1752 | psotfx | user_aim = '" . $row['user_aim'] . "', |
| 927 | 1752 | psotfx | user_yim = '" . $row['user_yim'] . "', |
| 928 | 1752 | psotfx | user_msnm = '" . $row['user_msnm'] . "', |
| 929 | 1752 | psotfx | user_level = '" . $row['user_level'] . "', |
| 930 | 1752 | psotfx | user_desmile = NOT(user_desmile), |
| 931 | 1752 | psotfx | user_bbcode = 1, |
| 932 | 1752 | psotfx | user_theme = 1 |
| 933 | 1752 | psotfx | WHERE user_id = " . $row['user_id']; |
| 934 | 1752 | psotfx | query($sql, "Couldn't update ".USERS_TABLE." table with new BBcode and regdate for user_id ".$row['user_id']); |
| 935 | 2093 | psotfx | |
| 936 | 2093 | psotfx | $inc++; |
| 937 | 2093 | psotfx | if ( $inc == $per_pct ) |
| 938 | 2093 | psotfx | {
|
| 939 | 2093 | psotfx | print "."; |
| 940 | 2093 | psotfx | flush(); |
| 941 | 2093 | psotfx | $inc = 0; |
| 942 | 2093 | psotfx | } |
| 943 | 1250 | bartvb | } |
| 944 | 1752 | psotfx | |
| 945 | 2093 | psotfx | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 946 | 2093 | psotfx | |
| 947 | 1752 | psotfx | lock_tables(0); |
| 948 | 1752 | psotfx | } |
| 949 | 1752 | psotfx | |
| 950 | 1752 | psotfx | // |
| 951 | 1752 | psotfx | // Handle super-mods, create hidden group for them |
| 952 | 1752 | psotfx | // |
| 953 | 1752 | psotfx | // Iterate trough access table |
| 954 | 1752 | psotfx | if( count($super_mods) && $first_admin != -2 ) |
| 955 | 1752 | psotfx | {
|
| 956 | 2093 | psotfx | print "\n<br />\n * Creating new group for super moderators :: "; |
| 957 | 1752 | psotfx | flush(); |
| 958 | 1752 | psotfx | |
| 959 | 1752 | psotfx | $sql = "INSERT INTO " . GROUPS_TABLE . " (group_type, group_name, group_description, group_moderator, group_single_user) |
| 960 | 1752 | psotfx | VALUES (" . GROUP_HIDDEN . ", 'Super Moderators', 'Converted super moderators', $first_admin, 0)";
|
| 961 | 1752 | psotfx | $result = query($sql, "Couldn't create group for ".$row['forum_name']); |
| 962 | 1752 | psotfx | |
| 963 | 1752 | psotfx | $group_id = $db->sql_nextid(); |
| 964 | 1752 | psotfx | |
| 965 | 2093 | psotfx | if ( $group_id <= 0 ) |
| 966 | 1250 | bartvb | {
|
| 967 | 1752 | psotfx | print "<font color=\"red\">Group creation failed. Aborting creation of groups...<br></font>\n"; |
| 968 | 1752 | psotfx | continue 2; |
| 969 | 1250 | bartvb | } |
| 970 | 1250 | bartvb | |
| 971 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 972 | 1752 | psotfx | |
| 973 | 2093 | psotfx | print " * Updating auth_access for super moderator group :: "; |
| 974 | 1752 | psotfx | flush(); |
| 975 | 1752 | psotfx | |
| 976 | 1752 | psotfx | $sql = "SELECT forum_id |
| 977 | 1752 | psotfx | FROM " . FORUMS_TABLE; |
| 978 | 1752 | psotfx | $result = query($sql, "Couldn't obtain forum_id list"); |
| 979 | 1752 | psotfx | |
| 980 | 1752 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 981 | 1242 | bartvb | {
|
| 982 | 1752 | psotfx | $sql = "INSERT INTO " . AUTH_ACCESS_TABLE . " (group_id, forum_id, auth_mod) |
| 983 | 1752 | psotfx | VALUES ($group_id, " . $row['forum_id'] . ", 1)"; |
| 984 | 1752 | psotfx | $result_insert = query($sql, "Unable to set group auth access for super mods."); |
| 985 | 1242 | bartvb | } |
| 986 | 1242 | bartvb | |
| 987 | 1752 | psotfx | for($i = 0; $i < count($super_mods); $i++) |
| 988 | 1242 | bartvb | {
|
| 989 | 1752 | psotfx | $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending) |
| 990 | 1752 | psotfx | VALUES ($group_id, " . $super_mods[$i] . ", 0)"; |
| 991 | 1752 | psotfx | query($sql, "Unable to add user_id $user_id to group_id $group_id (super mods)<br>\n"); |
| 992 | 1242 | bartvb | } |
| 993 | 1752 | psotfx | |
| 994 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 995 | 1752 | psotfx | } |
| 996 | 1242 | bartvb | |
| 997 | 1752 | psotfx | end_step('convert_posts');
|
| 998 | 1242 | bartvb | |
| 999 | 1752 | psotfx | case 'convert_posts': |
| 1000 | 2093 | psotfx | print " * Adding enable_sig field to " . POSTS_TABLE . " :: "; |
| 1001 | 2093 | psotfx | flush(); |
| 1002 | 1752 | psotfx | $sql = "ALTER TABLE " . POSTS_TABLE . " |
| 1003 | 1752 | psotfx | ADD enable_sig tinyint(1) DEFAULT '1' NOT NULL"; |
| 1004 | 1752 | psotfx | $result = query($sql, "Couldn't add enable_sig field to " . POSTS_TABLE . "."); |
| 1005 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1006 | 1752 | psotfx | |
| 1007 | 2093 | psotfx | print " * Adding enable_bbcode field to " . POSTS_TEXT_TABLE . " :: "; |
| 1008 | 2093 | psotfx | flush(); |
| 1009 | 1752 | psotfx | $sql = "ALTER TABLE " . POSTS_TEXT_TABLE . " |
| 1010 | 1752 | psotfx | ADD enable_bbcode tinyint(1) DEFAULT '1' NOT NULL"; |
| 1011 | 1752 | psotfx | $result = query($sql, "Couldn't add enable_bbcode field to " . POSTS_TABLE . "."); |
| 1012 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1013 | 1752 | psotfx | |
| 1014 | 2093 | psotfx | print " * Adding bbcode_uid field to " . POSTS_TEXT_TABLE . " :: "; |
| 1015 | 2093 | psotfx | flush(); |
| 1016 | 1752 | psotfx | $sql = "ALTER TABLE " . POSTS_TEXT_TABLE . " |
| 1017 | 1752 | psotfx | ADD bbcode_uid char(10) NOT NULL"; |
| 1018 | 1752 | psotfx | $result = query($sql, "Couldn't add bbcode_uid field to " . POSTS_TABLE . "."); |
| 1019 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1020 | 1752 | psotfx | |
| 1021 | 2093 | psotfx | print " * Adding post_edit_time field to " . POSTS_TABLE . " :: "; |
| 1022 | 2093 | psotfx | flush(); |
| 1023 | 1752 | psotfx | $sql = "ALTER TABLE " . POSTS_TABLE . " |
| 1024 | 1752 | psotfx | ADD post_edit_time int(11)"; |
| 1025 | 1752 | psotfx | $result = query($sql, "Couldn't add post_edit_time field to " . POSTS_TABLE . "."); |
| 1026 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1027 | 1752 | psotfx | |
| 1028 | 2093 | psotfx | print " * Adding post_edit_count field to " . POSTS_TABLE . " :: "; |
| 1029 | 2093 | psotfx | flush(); |
| 1030 | 1752 | psotfx | $sql = "ALTER TABLE " . POSTS_TABLE . " |
| 1031 | 1752 | psotfx | ADD post_edit_count smallint(5) UNSIGNED DEFAULT '0' NOT NULL"; |
| 1032 | 1752 | psotfx | $result = query($sql, "Couldn't add post_edit_count field to " . POSTS_TABLE . "."); |
| 1033 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n<br />\n"; |
| 1034 | 1752 | psotfx | |
| 1035 | 1752 | psotfx | $sql = "SELECT COUNT(*) as total, MAX(post_id) as maxid |
| 1036 | 1752 | psotfx | FROM " . POSTS_TEXT_TABLE; |
| 1037 | 1752 | psotfx | $result = query($sql, "Couldn't get max post_id."); |
| 1038 | 1752 | psotfx | |
| 1039 | 1752 | psotfx | $maxid = $db->sql_fetchrow($result); |
| 1040 | 1752 | psotfx | |
| 1041 | 1752 | psotfx | $totalposts = $maxid['total']; |
| 1042 | 1752 | psotfx | $maxid = $maxid['maxid']; |
| 1043 | 1752 | psotfx | |
| 1044 | 1752 | psotfx | $batchsize = 2000; |
| 1045 | 1752 | psotfx | for($i = 0; $i <= $maxid; $i += $batchsize) |
| 1046 | 1752 | psotfx | {
|
| 1047 | 1752 | psotfx | $batchstart = $i + 1; |
| 1048 | 1752 | psotfx | $batchend = $i + $batchsize; |
| 1049 | 1752 | psotfx | |
| 1050 | 2093 | psotfx | print " * Converting BBcode ( $batchstart to $batchend ) :: "; |
| 1051 | 1752 | psotfx | flush(); |
| 1052 | 1752 | psotfx | |
| 1053 | 1752 | psotfx | $sql = "SELECT * |
| 1054 | 1752 | psotfx | FROM " . POSTS_TEXT_TABLE . " |
| 1055 | 1752 | psotfx | WHERE post_id |
| 1056 | 1752 | psotfx | BETWEEN $batchstart |
| 1057 | 1752 | psotfx | AND $batchend"; |
| 1058 | 1752 | psotfx | $result = query($sql, "Couldn't get ". POSTS_TEXT_TABLE .".post_id $batchstart to $batchend"); |
| 1059 | 1752 | psotfx | |
| 1060 | 1752 | psotfx | lock_tables(1, array(POSTS_TEXT_TABLE, POSTS_TABLE)); |
| 1061 | 1752 | psotfx | |
| 1062 | 2093 | psotfx | $per_pct = ceil( $db->sql_numrows($result) / 40 ); |
| 1063 | 2093 | psotfx | $inc = 0; |
| 1064 | 2093 | psotfx | |
| 1065 | 1752 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 1066 | 1242 | bartvb | {
|
| 1067 | 2093 | psotfx | if ( $row['bbcode_uid'] != '' ) |
| 1068 | 1752 | psotfx | {
|
| 1069 | 1752 | psotfx | // We already converted this post to the new style BBcode, skip this post. |
| 1070 | 1752 | psotfx | continue; |
| 1071 | 1752 | psotfx | } |
| 1072 | 1752 | psotfx | |
| 1073 | 1752 | psotfx | // |
| 1074 | 1752 | psotfx | // Nathan's bbcode2 conversion |
| 1075 | 1752 | psotfx | // |
| 1076 | 1752 | psotfx | // undo 1.2.x encoding.. |
| 1077 | 1752 | psotfx | $row['post_text'] = bbdecode(stripslashes($row['post_text'])); |
| 1078 | 1752 | psotfx | $row['post_text'] = undo_make_clickable($row['post_text']); |
| 1079 | 2511 | psotfx | $row['post_text'] = str_replace('<BR>', "\n", $row['post_text']);
|
| 1080 | 1752 | psotfx | |
| 1081 | 1752 | psotfx | // make a uid |
| 1082 | 1752 | psotfx | $uid = make_bbcode_uid(); |
| 1083 | 1752 | psotfx | |
| 1084 | 1752 | psotfx | // do 2.x first-pass encoding.. |
| 1085 | 1752 | psotfx | $row['post_text'] = smiley_replace($row['post_text']); |
| 1086 | 1752 | psotfx | $row['post_text'] = bbencode_first_pass($row['post_text'], $uid); |
| 1087 | 1752 | psotfx | $row['post_text'] = addslashes($row['post_text']); |
| 1088 | 1752 | psotfx | |
| 1089 | 1752 | psotfx | $edited_sql = ""; |
| 1090 | 2511 | psotfx | if ( preg_match('/^(.*?)([\n]+<font size=\-1>\[ This message was .*?)$/s', $row['post_text'], $matches) )
|
| 1091 | 1752 | psotfx | {
|
| 1092 | 1752 | psotfx | $row['post_text'] = $matches[1]; |
| 1093 | 1752 | psotfx | $edit_info = $matches[2]; |
| 1094 | 1752 | psotfx | |
| 1095 | 2511 | psotfx | $edit_times = count(explode(' message ', $edit_info)) - 1; // Taken from example for substr_count in annotated PHP manual
|
| 1096 | 1752 | psotfx | |
| 1097 | 2511 | psotfx | if ( preg_match('/^.* by: (.*?) on (....)-(..)-(..) (..):(..) \]<\/font>/s', $edit_info, $matches) )
|
| 1098 | 1752 | psotfx | {
|
| 1099 | 1752 | psotfx | $edited_user = $matches[1]; |
| 1100 | 1752 | psotfx | $edited_time = gmmktime($matches[5], $matches[6], 0, $matches[3], $matches[4], $matches[2]); |
| 1101 | 1752 | psotfx | |
| 1102 | 1752 | psotfx | // |
| 1103 | 1752 | psotfx | // This isn't strictly correct since 2.0 won't include and edit |
| 1104 | 1752 | psotfx | // statement if the edit wasn't by the user who posted ... |
| 1105 | 1752 | psotfx | // |
| 1106 | 1752 | psotfx | $edited_sql = ", post_edit_time = $edited_time, post_edit_count = $edit_times"; |
| 1107 | 1752 | psotfx | } |
| 1108 | 1752 | psotfx | } |
| 1109 | 1752 | psotfx | |
| 1110 | 2093 | psotfx | if ( preg_match("/^(.*?)\n-----------------\n.*$/is", $row['post_text'], $matches) )
|
| 1111 | 1752 | psotfx | {
|
| 1112 | 1752 | psotfx | $row['post_text'] = $matches[1]; |
| 1113 | 1752 | psotfx | $enable_sig = 1; |
| 1114 | 1752 | psotfx | } |
| 1115 | 1752 | psotfx | else |
| 1116 | 1752 | psotfx | {
|
| 1117 | 1752 | psotfx | $checksig = preg_replace('/\[addsig\]$/', '', $row['post_text']);
|
| 1118 | 1752 | psotfx | $enable_sig = ( strlen($checksig) == strlen($row['post_text']) ) ? 0 : 1; |
| 1119 | 1752 | psotfx | } |
| 1120 | 1752 | psotfx | |
| 1121 | 1752 | psotfx | $sql = "UPDATE " . POSTS_TEXT_TABLE . " |
| 1122 | 1752 | psotfx | SET post_text = '$checksig', bbcode_uid = '$uid' |
| 1123 | 1752 | psotfx | WHERE post_id = " . $row['post_id']; |
| 1124 | 1752 | psotfx | query($sql, "Couldn't update " . POSTS_TEXT_TABLE . " table with new BBcode for post_id :: " . $row['post_id']); |
| 1125 | 1752 | psotfx | |
| 1126 | 1752 | psotfx | $sql = "UPDATE " . POSTS_TABLE . " |
| 1127 | 1752 | psotfx | SET enable_sig = $enable_sig" . $edited_sql . " |
| 1128 | 1752 | psotfx | WHERE post_id = " . $row['post_id']; |
| 1129 | 1752 | psotfx | query($sql, "Couldn't update " . POSTS_TABLE . " table with signature status for post with post_id :: " . $row['post_id']); |
| 1130 | 2093 | psotfx | |
| 1131 | 2093 | psotfx | $inc++; |
| 1132 | 2093 | psotfx | if ( $inc == $per_pct ) |
| 1133 | 2093 | psotfx | {
|
| 1134 | 2511 | psotfx | print '.'; |
| 1135 | 2093 | psotfx | flush(); |
| 1136 | 2093 | psotfx | $inc = 0; |
| 1137 | 2093 | psotfx | } |
| 1138 | 1242 | bartvb | } |
| 1139 | 1752 | psotfx | |
| 1140 | 2093 | psotfx | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1141 | 2093 | psotfx | |
| 1142 | 1752 | psotfx | lock_tables(0); |
| 1143 | 1752 | psotfx | } |
| 1144 | 1752 | psotfx | |
| 1145 | 2093 | psotfx | print "<br />\n * Updating poster_id for deleted users :: "; |
| 1146 | 1752 | psotfx | flush(); |
| 1147 | 1752 | psotfx | |
| 1148 | 1752 | psotfx | $sql = "SELECT DISTINCT p.post_id |
| 1149 | 1752 | psotfx | FROM " . POSTS_TABLE . " p |
| 1150 | 1752 | psotfx | LEFT JOIN " . USERS_TABLE . " u ON p.poster_id = u.user_id |
| 1151 | 1752 | psotfx | WHERE u.user_id IS NULL"; |
| 1152 | 1752 | psotfx | $result = query($sql, "Couldn't obtain list of deleted users"); |
| 1153 | 1752 | psotfx | |
| 1154 | 1757 | psotfx | $users_removed = $db->sql_numrows($result); |
| 1155 | 1757 | psotfx | |
| 1156 | 2093 | psotfx | if ( $users_removed ) |
| 1157 | 1752 | psotfx | {
|
| 1158 | 1757 | psotfx | $post_id_ary = array(); |
| 1159 | 1757 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 1160 | 1757 | psotfx | {
|
| 1161 | 1757 | psotfx | $post_id_ary[] = $row['post_id']; |
| 1162 | 1757 | psotfx | } |
| 1163 | 1757 | psotfx | |
| 1164 | 1757 | psotfx | $sql = "UPDATE " . POSTS_TABLE . " |
| 1165 | 1757 | psotfx | SET poster_id = " . ANONYMOUS . ", enable_sig = 0 |
| 1166 | 1757 | psotfx | WHERE post_id IN (" . implode(", ", $post_id_ary) . ")";
|
| 1167 | 1757 | psotfx | query($sql, "Couldn't update posts to remove deleted user poster_id values"); |
| 1168 | 1752 | psotfx | } |
| 1169 | 1752 | psotfx | |
| 1170 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span> ( Removed $users_removed non-existent user references )<br />\n"; |
| 1171 | 1752 | psotfx | |
| 1172 | 2093 | psotfx | end_step('convert_privmsgs');
|
| 1173 | 1752 | psotfx | |
| 1174 | 2093 | psotfx | case 'convert_privmsgs': |
| 1175 | 1752 | psotfx | $sql = "SELECT COUNT(*) as total, max(msg_id) as maxid |
| 1176 | 1752 | psotfx | FROM " . PRIVMSGS_TABLE; |
| 1177 | 1752 | psotfx | $result = query($sql, "Couldn't get max privmsgs_id."); |
| 1178 | 1752 | psotfx | |
| 1179 | 1752 | psotfx | $maxid = $db->sql_fetchrow($result); |
| 1180 | 1752 | psotfx | |
| 1181 | 1752 | psotfx | $totalposts = $maxid['total']; |
| 1182 | 1752 | psotfx | $maxid = $maxid['maxid']; |
| 1183 | 1752 | psotfx | |
| 1184 | 1752 | psotfx | $sql = "ALTER TABLE " . PRIVMSGS_TABLE . " |
| 1185 | 1752 | psotfx | ADD privmsgs_subject VARCHAR(255), |
| 1186 | 1752 | psotfx | ADD privmsgs_attach_sig TINYINT(1) DEFAULT 1"; |
| 1187 | 1752 | psotfx | query($sql, "Couldn't add privmsgs_subject field to " . PRIVMSGS_TABLE . " table"); |
| 1188 | 1752 | psotfx | |
| 1189 | 1752 | psotfx | $batchsize = 2000; |
| 1190 | 1752 | psotfx | for($i = 0; $i <= $maxid; $i += $batchsize) |
| 1191 | 1752 | psotfx | {
|
| 1192 | 1752 | psotfx | $batchstart = $i + 1; |
| 1193 | 1752 | psotfx | $batchend = $i + $batchsize; |
| 1194 | 1242 | bartvb | |
| 1195 | 2093 | psotfx | print " * Converting Private Message ( $batchstart to $batchend ) :: "; |
| 1196 | 1752 | psotfx | flush(); |
| 1197 | 1752 | psotfx | |
| 1198 | 1752 | psotfx | $sql = "SELECT * |
| 1199 | 1752 | psotfx | FROM " . PRIVMSGS_TABLE . " |
| 1200 | 1752 | psotfx | WHERE msg_id |
| 1201 | 1752 | psotfx | BETWEEN $batchstart |
| 1202 | 1752 | psotfx | AND $batchend"; |
| 1203 | 1752 | psotfx | $result = query($sql, "Couldn't get " . POSTS_TEXT_TABLE . " post_id $batchstart to $batchend"); |
| 1204 | 1752 | psotfx | |
| 1205 | 1752 | psotfx | lock_tables(1, array(PRIVMSGS_TABLE, PRIVMSGS_TEXT_TABLE)); |
| 1206 | 1752 | psotfx | |
| 1207 | 2093 | psotfx | $per_pct = ceil( $db->sql_numrows($result) / 40 ); |
| 1208 | 2093 | psotfx | $inc = 0; |
| 1209 | 2093 | psotfx | |
| 1210 | 1752 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 1211 | 1242 | bartvb | {
|
| 1212 | 2093 | psotfx | if ( $row['msg_text'] == NULL ) |
| 1213 | 1242 | bartvb | {
|
| 1214 | 1752 | psotfx | // We already converted this post to the new style BBcode, skip this post. |
| 1215 | 1752 | psotfx | continue; |
| 1216 | 1242 | bartvb | } |
| 1217 | 1752 | psotfx | // |
| 1218 | 1752 | psotfx | // Nathan's bbcode2 conversion |
| 1219 | 1752 | psotfx | // |
| 1220 | 1752 | psotfx | // undo 1.2.x encoding.. |
| 1221 | 1752 | psotfx | $row['msg_text'] = bbdecode(stripslashes($row['msg_text'])); |
| 1222 | 1752 | psotfx | $row['msg_text'] = undo_make_clickable($row['msg_text']); |
| 1223 | 1752 | psotfx | $row['msg_text'] = str_replace("<BR>", "\n", $row['msg_text']);
|
| 1224 | 1242 | bartvb | |
| 1225 | 1752 | psotfx | // make a uid |
| 1226 | 1752 | psotfx | $uid = make_bbcode_uid(); |
| 1227 | 1752 | psotfx | |
| 1228 | 1752 | psotfx | // do 2.x first-pass encoding.. |
| 1229 | 1752 | psotfx | $row['msg_text'] = smiley_replace($row['msg_text']); |
| 1230 | 1752 | psotfx | $row['msg_text'] = bbencode_first_pass($row['msg_text'], $uid); |
| 1231 | 1752 | psotfx | |
| 1232 | 1752 | psotfx | $checksig = preg_replace('/\[addsig\]$/', '', $row['msg_text']);
|
| 1233 | 1752 | psotfx | $enable_sig = (strlen($checksig) == strlen($row['msg_text'])) ? 0 : 1; |
| 1234 | 1752 | psotfx | |
| 1235 | 2093 | psotfx | if ( preg_match("/^(.*?)\n-----------------\n.*$/is", $checksig, $matches) )
|
| 1236 | 1752 | psotfx | {
|
| 1237 | 1752 | psotfx | $checksig = $matches[1]; |
| 1238 | 1752 | psotfx | $enable_sig = 1; |
| 1239 | 1752 | psotfx | } |
| 1240 | 1752 | psotfx | |
| 1241 | 1752 | psotfx | $row['msg_text'] = $checksig; |
| 1242 | 1752 | psotfx | |
| 1243 | 1752 | psotfx | $row['msg_status'] = ($row['msg_status'] == 1) ? PRIVMSGS_READ_MAIL : PRIVMSGS_NEW_MAIL; |
| 1244 | 1752 | psotfx | |
| 1245 | 1752 | psotfx | // Subject contains first 60 characters of msg, remove any BBCode tags |
| 1246 | 1752 | psotfx | $subject = addslashes(strip_tags(substr($row['msg_text'], 0, 60))); |
| 1247 | 1752 | psotfx | $subject = preg_replace("/\[.*?\:(([a-z0-9]:)?)$uid.*?\]/si", "", $subject);
|
| 1248 | 1752 | psotfx | |
| 1249 | 1752 | psotfx | $row['msg_text'] = addslashes($row['msg_text']); |
| 1250 | 1752 | psotfx | |
| 1251 | 1752 | psotfx | $sql = "INSERT INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text) |
| 1252 | 1752 | psotfx | VALUES ('" . $row['msg_id'] . "', '$uid', '" . $row['msg_text'] . "')";
|
| 1253 | 1752 | psotfx | query($sql, "Couldn't insert PrivMsg text into " . PRIVMSGS_TEXT_TABLE . " table msg_id " . $row['msg_id']); |
| 1254 | 1752 | psotfx | |
| 1255 | 1752 | psotfx | $sql = "UPDATE " . PRIVMSGS_TABLE . " |
| 1256 | 1752 | psotfx | SET msg_text = NULL, msg_status = " . $row['msg_status'] . ", privmsgs_subject = '$subject', privmsgs_attach_sig = $enable_sig |
| 1257 | 1752 | psotfx | WHERE msg_id = " . $row['msg_id']; |
| 1258 | 1752 | psotfx | query($sql, "Couldn't update " . PRIVMSGS_TABLE . " table for msg_id " . $row['post_id']); |
| 1259 | 2093 | psotfx | |
| 1260 | 2093 | psotfx | $inc++; |
| 1261 | 2093 | psotfx | if ( $inc == $per_pct ) |
| 1262 | 2093 | psotfx | {
|
| 1263 | 2511 | psotfx | print '.'; |
| 1264 | 2093 | psotfx | flush(); |
| 1265 | 2093 | psotfx | $inc = 0; |
| 1266 | 2093 | psotfx | } |
| 1267 | 1242 | bartvb | } |
| 1268 | 2093 | psotfx | |
| 1269 | 2093 | psotfx | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1270 | 1752 | psotfx | } |
| 1271 | 1242 | bartvb | |
| 1272 | 1242 | bartvb | lock_tables(0); |
| 1273 | 2093 | psotfx | end_step('convert_moderators');
|
| 1274 | 1495 | bartvb | |
| 1275 | 2093 | psotfx | case 'convert_moderators'; |
| 1276 | 1752 | psotfx | $sql = "SELECT * |
| 1277 | 1752 | psotfx | FROM forum_mods"; |
| 1278 | 1752 | psotfx | $result = query($sql, "Couldn't get list with all forum moderators"); |
| 1279 | 1242 | bartvb | |
| 1280 | 1752 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 1281 | 1242 | bartvb | {
|
| 1282 | 1752 | psotfx | // Check if this moderator and this forum still exist |
| 1283 | 2511 | psotfx | $sql = "SELECT user_id |
| 1284 | 1752 | psotfx | FROM " . USERS_TABLE . ", " . FORUMS_TABLE . " |
| 1285 | 1752 | psotfx | WHERE user_id = " . $row['user_id'] . " |
| 1286 | 1752 | psotfx | AND forum_id = " . $row['forum_id']; |
| 1287 | 2093 | psotfx | $check_data = query($sql, "Couldn't check if user " . $row['user_id'] . " and forum " . $row['forum_id'] . " exist"); |
| 1288 | 1752 | psotfx | |
| 1289 | 2093 | psotfx | if ( !($rowtest = $db->sql_fetchrow($check_data)) ) |
| 1290 | 1242 | bartvb | {
|
| 1291 | 1752 | psotfx | // Either the moderator or the forum have been deleted, this line in forum_mods was redundant, skip it. |
| 1292 | 1242 | bartvb | continue; |
| 1293 | 1242 | bartvb | } |
| 1294 | 1752 | psotfx | |
| 1295 | 1752 | psotfx | $sql = "SELECT g.group_id |
| 1296 | 1752 | psotfx | FROM " . GROUPS_TABLE . " g, " . USER_GROUP_TABLE . " ug |
| 1297 | 2093 | psotfx | WHERE g.group_id = ug.group_id |
| 1298 | 1752 | psotfx | AND ug.user_id = " . $row['user_id'] . " |
| 1299 | 1752 | psotfx | AND g.group_single_user = 1"; |
| 1300 | 2093 | psotfx | $insert_group = query($sql, "Couldn't get group number for user " . $row['user_id'] . "."); |
| 1301 | 1752 | psotfx | |
| 1302 | 1752 | psotfx | $group_id = $db->sql_fetchrow($insert_group); |
| 1303 | 1752 | psotfx | $group_id = $group_id['group_id']; |
| 1304 | 1752 | psotfx | |
| 1305 | 2093 | psotfx | print " * Adding moderator for forum " . $row['forum_id'] . " :: "; |
| 1306 | 2093 | psotfx | flush(); |
| 1307 | 1752 | psotfx | |
| 1308 | 1752 | psotfx | $sql = "INSERT INTO " . AUTH_ACCESS_TABLE . " (group_id, forum_id, auth_mod) VALUES ($group_id, ".$row['forum_id'].", 1)"; |
| 1309 | 1752 | psotfx | query($sql, "Couldn't set moderator (user_id = " . $row['user_id'] . ") for forum " . $row['forum_id'] . "."); |
| 1310 | 2093 | psotfx | |
| 1311 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1312 | 1752 | psotfx | } |
| 1313 | 2511 | psotfx | |
| 1314 | 2511 | psotfx | print " * Setting correct user_level for moderators ::"; |
| 1315 | 2511 | psotfx | flush(); |
| 1316 | 2511 | psotfx | |
| 1317 | 2511 | psotfx | $sql = "SELECT DISTINCT u.user_id |
| 1318 | 2511 | psotfx | FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug, " . AUTH_ACCESS_TABLE . " aa |
| 1319 | 2511 | psotfx | WHERE aa.auth_mod = 1 |
| 1320 | 2511 | psotfx | AND ug.group_id = aa.group_id |
| 1321 | 2511 | psotfx | AND u.user_id = ug.user_id |
| 1322 | 2511 | psotfx | AND u.user_level <> " . ADMIN; |
| 1323 | 2511 | psotfx | $result = query($sql, "Couldn't obtain list of moderators"); |
| 1324 | 2511 | psotfx | |
| 1325 | 2511 | psotfx | if ( $row = $db->sql_fetchrow($result) ) |
| 1326 | 2511 | psotfx | {
|
| 1327 | 2511 | psotfx | $ug_sql = ''; |
| 1328 | 2511 | psotfx | |
| 1329 | 2511 | psotfx | do |
| 1330 | 2511 | psotfx | {
|
| 1331 | 2511 | psotfx | $ug_sql .= ( ( $ug_sql != '' ) ? ', ' : '' ) . $row['user_id']; |
| 1332 | 2511 | psotfx | } |
| 1333 | 2511 | psotfx | while ( $row = $db->sql_fetchrow($result) ); |
| 1334 | 2511 | psotfx | |
| 1335 | 2511 | psotfx | $sql = "UPDATE " . USERS_TABLE . " |
| 1336 | 2511 | psotfx | SET user_level = " . MOD . " |
| 1337 | 2511 | psotfx | WHERE user_id IN ($ug_sql)"; |
| 1338 | 2511 | psotfx | query($sql, "Couldn't set moderator status for users"); |
| 1339 | 2511 | psotfx | } |
| 1340 | 2511 | psotfx | |
| 1341 | 2511 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1342 | 1752 | psotfx | |
| 1343 | 1752 | psotfx | end_step('convert_privforums');
|
| 1344 | 1752 | psotfx | |
| 1345 | 1752 | psotfx | case 'convert_privforums': |
| 1346 | 1752 | psotfx | $sql = "SELECT fa.*, f.forum_name |
| 1347 | 1752 | psotfx | FROM forum_access fa |
| 1348 | 1752 | psotfx | LEFT JOIN " . FORUMS_TABLE . " f ON fa.forum_id = f.forum_id |
| 1349 | 1752 | psotfx | ORDER BY fa.forum_id, fa.user_id"; |
| 1350 | 1752 | psotfx | $forum_access = query($sql, "Couldn't get list with special forum access (forum_access)"); |
| 1351 | 1752 | psotfx | |
| 1352 | 1752 | psotfx | $forum_id = -1; |
| 1353 | 1752 | psotfx | while( $row = $db->sql_fetchrow($forum_access) ) |
| 1354 | 1752 | psotfx | {
|
| 1355 | 1752 | psotfx | // Iterate trough access table |
| 1356 | 2093 | psotfx | if ( $row['forum_id'] != $forum_id ) |
| 1357 | 1242 | bartvb | {
|
| 1358 | 1752 | psotfx | // This is a new forum, create new group. |
| 1359 | 1752 | psotfx | $forum_id = $row['forum_id']; |
| 1360 | 1752 | psotfx | |
| 1361 | 2093 | psotfx | print " * Creating new group for forum $forum_id :: "; |
| 1362 | 2093 | psotfx | flush(); |
| 1363 | 1752 | psotfx | |
| 1364 | 1752 | psotfx | $sql = "INSERT INTO " . GROUPS_TABLE . " (group_type, group_name, group_description, group_moderator, group_single_user) |
| 1365 | 1752 | psotfx | VALUES (" . GROUP_HIDDEN . ", '" . addslashes($row['forum_name']) . " Group', 'Converted Private Forum Group', " . $row['user_id'] . ", 0)";
|
| 1366 | 1752 | psotfx | $result = query($sql, "Couldn't create group for ".$row['forum_name']); |
| 1367 | 1752 | psotfx | |
| 1368 | 1752 | psotfx | $group_id = $db->sql_nextid(); |
| 1369 | 1752 | psotfx | |
| 1370 | 2093 | psotfx | if ( $group_id <= 0 ) |
| 1371 | 1752 | psotfx | {
|
| 1372 | 1752 | psotfx | print "<font color=\"red\">Group creation failed. Aborting creation of groups...<br></font>\n"; |
| 1373 | 1752 | psotfx | continue 2; |
| 1374 | 1752 | psotfx | } |
| 1375 | 1752 | psotfx | |
| 1376 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1377 | 1752 | psotfx | |
| 1378 | 2093 | psotfx | print " * Creating auth_access group for forum $forum_id :: "; |
| 1379 | 2093 | psotfx | flush(); |
| 1380 | 2093 | psotfx | |
| 1381 | 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) |
| 1382 | 2400 | psotfx | VALUES ($group_id, $forum_id, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1)"; |
| 1383 | 1752 | psotfx | $result = query($sql, "Unable to set group auth access."); |
| 1384 | 1752 | psotfx | |
| 1385 | 2093 | psotfx | if ( $db->sql_affectedrows($result) <= 0 ) |
| 1386 | 1752 | psotfx | {
|
| 1387 | 1752 | psotfx | print "<font color=\"red\">Group creation failed. Aborting creation of groups...</font><br>\n"; |
| 1388 | 1752 | psotfx | continue 2; |
| 1389 | 1752 | psotfx | } |
| 1390 | 2093 | psotfx | |
| 1391 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1392 | 1242 | bartvb | } |
| 1393 | 1242 | bartvb | |
| 1394 | 1752 | psotfx | // Add user to the group |
| 1395 | 1752 | psotfx | $user_id = $row['user_id']; |
| 1396 | 1752 | psotfx | |
| 1397 | 1752 | psotfx | $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending) |
| 1398 | 1752 | psotfx | VALUES ($group_id, $user_id, 0)"; |
| 1399 | 1752 | psotfx | query($sql, "Unable to add user_id $user_id to group_id $group_id <br>\n"); |
| 1400 | 1242 | bartvb | } |
| 1401 | 1242 | bartvb | |
| 1402 | 1752 | psotfx | end_step('update_schema');
|
| 1403 | 1242 | bartvb | |
| 1404 | 1752 | psotfx | case 'update_schema': |
| 1405 | 1752 | psotfx | $rename = array( |
| 1406 | 1752 | psotfx | $table_prefix . "users" => array( |
| 1407 | 1752 | psotfx | "user_interests" => "user_intrest", |
| 1408 | 1752 | psotfx | "user_allowsmile" => "user_desmile", |
| 1409 | 1752 | psotfx | "user_allowhtml" => "user_html", |
| 1410 | 1752 | psotfx | "user_allowbbcode" => "user_bbcode", |
| 1411 | 1752 | psotfx | "user_style" => "user_theme" |
| 1412 | 1752 | psotfx | ), |
| 1413 | 1752 | psotfx | $table_prefix . "privmsgs" => array( |
| 1414 | 1752 | psotfx | "privmsgs_id" => "msg_id", |
| 1415 | 1752 | psotfx | "privmsgs_from_userid" => "from_userid", |
| 1416 | 1752 | psotfx | "privmsgs_to_userid" => "to_userid", |
| 1417 | 1752 | psotfx | "privmsgs_date" => "msg_time", |
| 1418 | 1752 | psotfx | "privmsgs_ip" => "poster_ip", |
| 1419 | 1752 | psotfx | "privmsgs_type" => "msg_status" |
| 1420 | 1752 | psotfx | ), |
| 1421 | 1752 | psotfx | $table_prefix . "smilies" => array( |
| 1422 | 1752 | psotfx | "smilies_id" => "id" |
| 1423 | 1752 | psotfx | ) |
| 1424 | 1752 | psotfx | ); |
| 1425 | 1752 | psotfx | |
| 1426 | 1752 | psotfx | $schema = get_schema(); |
| 1427 | 1752 | psotfx | |
| 1428 | 1752 | psotfx | $table_def = $schema['table_def']; |
| 1429 | 1752 | psotfx | $field_def = $schema['field_def']; |
| 1430 | 1752 | psotfx | |
| 1431 | 1752 | psotfx | // Loop tables in schema |
| 1432 | 2093 | psotfx | while (list($table, $table_def) = @each($field_def)) |
| 1433 | 1242 | bartvb | {
|
| 1434 | 1752 | psotfx | // Loop fields in table |
| 1435 | 2093 | psotfx | print " * Updating table '$table' :: "; |
| 1436 | 1752 | psotfx | flush(); |
| 1437 | 1752 | psotfx | |
| 1438 | 1752 | psotfx | $sql = "SHOW FIELDS |
| 1439 | 1752 | psotfx | FROM $table"; |
| 1440 | 1752 | psotfx | $result = query($sql, "Can't get definition of current $table table"); |
| 1441 | 1752 | psotfx | |
| 1442 | 2093 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 1443 | 1242 | bartvb | {
|
| 1444 | 2093 | psotfx | $current_fields[] = $row['Field']; |
| 1445 | 1242 | bartvb | } |
| 1446 | 1242 | bartvb | |
| 1447 | 1752 | psotfx | $alter_sql = "ALTER TABLE $table "; |
| 1448 | 1752 | psotfx | while (list($field, $definition) = each($table_def)) |
| 1449 | 1242 | bartvb | {
|
| 1450 | 2093 | psotfx | if ( $field == '' ) |
| 1451 | 1752 | psotfx | {
|
| 1452 | 1752 | psotfx | // Skip empty fields if any (shouldn't be needed) |
| 1453 | 1752 | psotfx | continue; |
| 1454 | 1752 | psotfx | } |
| 1455 | 1752 | psotfx | |
| 1456 | 1752 | psotfx | $type = $definition['type']; |
| 1457 | 1752 | psotfx | $size = $definition['size']; |
| 1458 | 1752 | psotfx | |
| 1459 | 1752 | psotfx | $default = isset($definition['default']) ? "DEFAULT " . $definition['default'] : ''; |
| 1460 | 1752 | psotfx | |
| 1461 | 1752 | psotfx | $notnull = $definition['notnull'] == 1 ? 'NOT NULL' : ''; |
| 1462 | 1752 | psotfx | |
| 1463 | 1752 | psotfx | $auto_increment = $definition['auto_increment'] == 1 ? 'auto_increment' : ''; |
| 1464 | 1752 | psotfx | |
| 1465 | 1752 | psotfx | $oldfield = isset($rename[$table][$field]) ? $rename[$table][$field] : $field; |
| 1466 | 1752 | psotfx | |
| 1467 | 2093 | psotfx | if ( !inarray($field, $current_fields) && $oldfield == $field ) |
| 1468 | 1752 | psotfx | {
|
| 1469 | 1752 | psotfx | // If the current is not a key of $current_def and it is not a field that is |
| 1470 | 1752 | psotfx | // to be renamed then the field doesn't currently exist. |
| 1471 | 1752 | psotfx | $changes[] = " ADD $field " . $create_def[$table][$field]; |
| 1472 | 1752 | psotfx | } |
| 1473 | 1752 | psotfx | else |
| 1474 | 1752 | psotfx | {
|
| 1475 | 1752 | psotfx | $changes[] = " CHANGE $oldfield $field " . $create_def[$table][$field]; |
| 1476 | 1752 | psotfx | } |
| 1477 | 1242 | bartvb | } |
| 1478 | 1752 | psotfx | |
| 1479 | 1752 | psotfx | $alter_sql .= join(',', $changes);
|
| 1480 | 1752 | psotfx | unset($changes); |
| 1481 | 1752 | psotfx | unset($current_fields); |
| 1482 | 1752 | psotfx | |
| 1483 | 1752 | psotfx | $sql = "SHOW INDEX |
| 1484 | 1752 | psotfx | FROM $table"; |
| 1485 | 1752 | psotfx | $result = query($sql, "Couldn't get list of indices for table $table"); |
| 1486 | 1752 | psotfx | |
| 1487 | 1752 | psotfx | unset($indices); |
| 1488 | 1752 | psotfx | |
| 1489 | 1752 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 1490 | 1242 | bartvb | {
|
| 1491 | 1752 | psotfx | $indices[] = $row['Key_name']; |
| 1492 | 1242 | bartvb | } |
| 1493 | 1242 | bartvb | |
| 1494 | 2093 | psotfx | while ( list($key_name, $key_field) = each($key_def[$table]) ) |
| 1495 | 1242 | bartvb | {
|
| 1496 | 2093 | psotfx | if ( !inarray($key_name, $indices) ) |
| 1497 | 1752 | psotfx | {
|
| 1498 | 1752 | psotfx | $alter_sql .= ($key_name == 'PRIMARY') ? ", ADD PRIMARY KEY ($key_field)" : ", ADD INDEX $key_name ($key_field)"; |
| 1499 | 1752 | psotfx | } |
| 1500 | 1242 | bartvb | } |
| 1501 | 1752 | psotfx | query($alter_sql, "Couldn't alter table $table"); |
| 1502 | 2093 | psotfx | |
| 1503 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1504 | 1752 | psotfx | flush(); |
| 1505 | 1752 | psotfx | } |
| 1506 | 1752 | psotfx | |
| 1507 | 1752 | psotfx | end_step('convert_forums');
|
| 1508 | 1752 | psotfx | |
| 1509 | 1752 | psotfx | case 'convert_forums': |
| 1510 | 1752 | psotfx | $sql = "SELECT * |
| 1511 | 1752 | psotfx | FROM " . FORUMS_TABLE; |
| 1512 | 1752 | psotfx | $result = query($sql, "Couldn't get list with all forums"); |
| 1513 | 1752 | psotfx | |
| 1514 | 1752 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 1515 | 1752 | psotfx | {
|
| 1516 | 2093 | psotfx | print " * Converting forum '" . $row['forum_name'] . "' :: "; |
| 1517 | 2093 | psotfx | flush(); |
| 1518 | 2093 | psotfx | |
| 1519 | 1752 | psotfx | // forum_access: (only concerns posting) |
| 1520 | 1752 | psotfx | // 1 = Registered users only |
| 1521 | 1752 | psotfx | // 2 = Anonymous Posting |
| 1522 | 1752 | psotfx | // 3 = Moderators/Administrators only |
| 1523 | 2093 | psotfx | switch( $row['forum_access'] ) |
| 1524 | 1752 | psotfx | {
|
| 1525 | 1752 | psotfx | case 1: |
| 1526 | 1752 | psotfx | // Public forum, no anonymous posting |
| 1527 | 2400 | psotfx | $auth_view = AUTH_ALL; |
| 1528 | 2400 | psotfx | $auth_read = AUTH_ALL; |
| 1529 | 1752 | psotfx | $auth_post = AUTH_REG; |
| 1530 | 1752 | psotfx | $auth_reply = AUTH_REG; |
| 1531 | 1752 | psotfx | $auth_edit = AUTH_REG; |
| 1532 | 1752 | psotfx | $auth_delete = AUTH_REG; |
| 1533 | 1752 | psotfx | $auth_vote = AUTH_REG; |
| 1534 | 1752 | psotfx | $auth_pollcreate = AUTH_REG; |
| 1535 | 1752 | psotfx | $auth_sticky = AUTH_MOD; |
| 1536 | 1752 | psotfx | $auth_announce = AUTH_MOD; |
| 1537 | 1752 | psotfx | break; |
| 1538 | 1752 | psotfx | case 2: |
| 1539 | 1752 | psotfx | $auth_post = AUTH_ALL; |
| 1540 | 1752 | psotfx | $auth_reply = AUTH_ALL; |
| 1541 | 2400 | psotfx | $auth_edit = AUTH_REG; |
| 1542 | 2400 | psotfx | $auth_delete = AUTH_REG; |
| 1543 | 1752 | psotfx | $auth_vote = AUTH_ALL; |
| 1544 | 1752 | psotfx | $auth_pollcreate = AUTH_ALL; |
| 1545 | 1752 | psotfx | $auth_sticky = AUTH_MOD; |
| 1546 | 1752 | psotfx | $auth_announce = AUTH_MOD; |
| 1547 | 1752 | psotfx | break; |
| 1548 | 1752 | psotfx | default: |
| 1549 | 1752 | psotfx | $auth_post = AUTH_MOD; |
| 1550 | 1752 | psotfx | $auth_reply = AUTH_MOD; |
| 1551 | 1752 | psotfx | $auth_edit = AUTH_MOD; |
| 1552 | 1752 | psotfx | $auth_delete = AUTH_MOD; |
| 1553 | 1752 | psotfx | $auth_vote = AUTH_MOD; |
| 1554 | 1752 | psotfx | $auth_pollcreate = AUTH_MOD; |
| 1555 | 1752 | psotfx | $auth_sticky = AUTH_MOD; |
| 1556 | 1752 | psotfx | $auth_announce = AUTH_MOD; |
| 1557 | 1752 | psotfx | break; |
| 1558 | 1752 | psotfx | } |
| 1559 | 1242 | bartvb | |
| 1560 | 2400 | psotfx | // Old auth structure: |
| 1561 | 2400 | psotfx | // forum_type: (only concerns viewing) |
| 1562 | 2400 | psotfx | // 0 = Public |
| 1563 | 2400 | psotfx | // 1 = Private |
| 1564 | 2400 | psotfx | switch( $row['forum_type'] ) |
| 1565 | 2400 | psotfx | {
|
| 1566 | 2400 | psotfx | case 0: |
| 1567 | 2400 | psotfx | $auth_view = AUTH_ALL; |
| 1568 | 2400 | psotfx | $auth_read = AUTH_ALL; |
| 1569 | 2400 | psotfx | break; |
| 1570 | 2400 | psotfx | default: |
| 1571 | 2400 | psotfx | // |
| 1572 | 2400 | psotfx | // Make it really private ... |
| 1573 | 2400 | psotfx | // |
| 1574 | 2400 | psotfx | $auth_view = AUTH_ACL; |
| 1575 | 2400 | psotfx | $auth_read = AUTH_ACL; |
| 1576 | 2400 | psotfx | $auth_post = AUTH_ACL; |
| 1577 | 2400 | psotfx | $auth_reply = AUTH_ACL; |
| 1578 | 2400 | psotfx | $auth_edit = AUTH_ACL; |
| 1579 | 2400 | psotfx | $auth_delete = AUTH_ACL; |
| 1580 | 2400 | psotfx | $auth_vote = AUTH_ACL; |
| 1581 | 2400 | psotfx | $auth_pollcreate = AUTH_ACL; |
| 1582 | 2400 | psotfx | $auth_sticky = AUTH_ACL; |
| 1583 | 2400 | psotfx | $auth_announce = AUTH_MOD; |
| 1584 | 2400 | psotfx | break; |
| 1585 | 2400 | psotfx | } |
| 1586 | 2400 | psotfx | |
| 1587 | 1752 | psotfx | $sql = "UPDATE " . FORUMS_TABLE . " SET |
| 1588 | 1752 | psotfx | auth_view = $auth_view, |
| 1589 | 1752 | psotfx | auth_read = $auth_read, |
| 1590 | 1752 | psotfx | auth_post = $auth_post, |
| 1591 | 1752 | psotfx | auth_reply = $auth_reply, |
| 1592 | 1752 | psotfx | auth_edit = $auth_edit, |
| 1593 | 1752 | psotfx | auth_delete = $auth_delete, |
| 1594 | 1752 | psotfx | auth_vote = $auth_vote, |
| 1595 | 1752 | psotfx | auth_pollcreate = $auth_pollcreate, |
| 1596 | 1752 | psotfx | auth_sticky = $auth_sticky, |
| 1597 | 1752 | psotfx | auth_announce = $auth_announce |
| 1598 | 1752 | psotfx | WHERE forum_id = ". $row['forum_id']; |
| 1599 | 1752 | psotfx | query($sql, "Was unable to update forum permissions!"); |
| 1600 | 2093 | psotfx | |
| 1601 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1602 | 1752 | psotfx | } |
| 1603 | 1242 | bartvb | |
| 1604 | 1752 | psotfx | end_step('insert_themes');
|
| 1605 | 1242 | bartvb | |
| 1606 | 1752 | psotfx | case 'insert_themes': |
| 1607 | 2093 | psotfx | print " * Inserting new values into themes table :: "; |
| 1608 | 1752 | psotfx | |
| 1609 | 1752 | psotfx | @reset($inserts); |
| 1610 | 1752 | psotfx | while( list($table, $inserts_table) = each($inserts) ) |
| 1611 | 1250 | bartvb | {
|
| 1612 | 2093 | psotfx | if ( $table == THEMES_TABLE ) |
| 1613 | 1752 | psotfx | {
|
| 1614 | 2093 | psotfx | $per_pct = ceil( count($inserts_table) / 40 ); |
| 1615 | 2093 | psotfx | $inc = 0; |
| 1616 | 2093 | psotfx | |
| 1617 | 1752 | psotfx | while( list($nr, $insert) = each($inserts_table) ) |
| 1618 | 1752 | psotfx | {
|
| 1619 | 1752 | psotfx | query($insert, "Couldn't insert value into " . THEMES_TABLE); |
| 1620 | 1752 | psotfx | |
| 1621 | 2093 | psotfx | $inc++; |
| 1622 | 2093 | psotfx | if ( $inc == $per_pct ) |
| 1623 | 2093 | psotfx | {
|
| 1624 | 2093 | psotfx | print "."; |
| 1625 | 2093 | psotfx | flush(); |
| 1626 | 2093 | psotfx | $inc = 0; |
| 1627 | 2093 | psotfx | } |
| 1628 | 1752 | psotfx | } |
| 1629 | 1752 | psotfx | } |
| 1630 | 1250 | bartvb | } |
| 1631 | 1250 | bartvb | |
| 1632 | 2093 | psotfx | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1633 | 2093 | psotfx | end_step('fulltext_search_indexing');
|
| 1634 | 1250 | bartvb | |
| 1635 | 2093 | psotfx | case 'fulltext_search_indexing': |
| 1636 | 1752 | psotfx | // |
| 1637 | 1752 | psotfx | // Generate search word list |
| 1638 | 1752 | psotfx | // |
| 1639 | 1752 | psotfx | // Fetch a batch of posts_text entries |
| 1640 | 1752 | psotfx | // |
| 1641 | 1752 | psotfx | $sql = "SELECT COUNT(*) as total, MAX(post_id) as max_post_id |
| 1642 | 1752 | psotfx | FROM " . POSTS_TEXT_TABLE; |
| 1643 | 1752 | psotfx | $result = query($sql, "Couldn't get post count totals"); |
| 1644 | 1752 | psotfx | |
| 1645 | 1752 | psotfx | $max_post_id = $db->sql_fetchrow($result); |
| 1646 | 1752 | psotfx | |
| 1647 | 1752 | psotfx | $totalposts = $max_post_id['total']; |
| 1648 | 1752 | psotfx | $max_post_id = $max_post_id['max_post_id']; |
| 1649 | 2093 | psotfx | $per_percent = round(( $totalposts / 500 ) * 10); |
| 1650 | 1752 | psotfx | |
| 1651 | 1752 | psotfx | $postcounter = ( !isset($HTTP_GET_VARS['batchstart']) ) ? 0 : $HTTP_GET_VARS['batchstart']; |
| 1652 | 1752 | psotfx | |
| 1653 | 2093 | psotfx | $batchsize = 150; // Process this many posts per loop |
| 1654 | 1752 | psotfx | $batchcount = 0; |
| 1655 | 2093 | psotfx | $total_percent = 0; |
| 1656 | 1752 | psotfx | |
| 1657 | 1752 | psotfx | for(;$postcounter <= $max_post_id; $postcounter += $batchsize) |
| 1658 | 1519 | bartvb | {
|
| 1659 | 1752 | psotfx | $batchstart = $postcounter + 1; |
| 1660 | 1752 | psotfx | $batchend = $postcounter + $batchsize; |
| 1661 | 1752 | psotfx | $batchcount++; |
| 1662 | 2093 | psotfx | |
| 1663 | 2093 | psotfx | print " * Fulltext Indexing ( $batchstart to $batchend ) :: "; |
| 1664 | 2093 | psotfx | flush(); |
| 1665 | 1752 | psotfx | |
| 1666 | 1752 | psotfx | $sql = "SELECT * |
| 1667 | 1752 | psotfx | FROM " . POSTS_TEXT_TABLE ." |
| 1668 | 1752 | psotfx | WHERE post_id |
| 1669 | 1752 | psotfx | BETWEEN $batchstart |
| 1670 | 1752 | psotfx | AND $batchend"; |
| 1671 | 1752 | psotfx | $posts_result = query($sql, "Couldn't obtain post_text"); |
| 1672 | 1519 | bartvb | |
| 1673 | 2093 | psotfx | $per_pct = ceil( $db->sql_numrows($posts_result) / 40 ); |
| 1674 | 2093 | psotfx | $inc = 0; |
| 1675 | 1752 | psotfx | |
| 1676 | 2093 | psotfx | if ( $row = $db->sql_fetchrow($posts_result) ) |
| 1677 | 2093 | psotfx | {
|
| 1678 | 2093 | psotfx | do |
| 1679 | 2093 | psotfx | {
|
| 1680 | 2093 | psotfx | add_search_words($row['post_id'], $row['post_text'], $row['post_subject']); |
| 1681 | 1752 | psotfx | |
| 1682 | 2093 | psotfx | $inc++; |
| 1683 | 2093 | psotfx | if ( $inc == $per_pct ) |
| 1684 | 2093 | psotfx | {
|
| 1685 | 2093 | psotfx | print "."; |
| 1686 | 2093 | psotfx | flush(); |
| 1687 | 2093 | psotfx | $inc = 0; |
| 1688 | 2093 | psotfx | } |
| 1689 | 2093 | psotfx | } |
| 1690 | 2093 | psotfx | while( $row = $db->sql_fetchrow($posts_result) ); |
| 1691 | 2093 | psotfx | } |
| 1692 | 1752 | psotfx | |
| 1693 | 2093 | psotfx | $db->sql_freeresult($posts_result); |
| 1694 | 2093 | psotfx | |
| 1695 | 2093 | psotfx | // Remove common words after the first 2 batches and after every 4th batch after that. |
| 1696 | 2093 | psotfx | if ( $batchcount % 4 == 3 ) |
| 1697 | 2093 | psotfx | {
|
| 1698 | 2093 | psotfx | remove_common('global', 0.4);
|
| 1699 | 2093 | psotfx | } |
| 1700 | 1752 | psotfx | |
| 1701 | 2093 | psotfx | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1702 | 2093 | psotfx | } |
| 1703 | 1752 | psotfx | |
| 1704 | 2093 | psotfx | end_step('update_topics');
|
| 1705 | 1752 | psotfx | |
| 1706 | 2093 | psotfx | case 'update_topics': |
| 1707 | 2093 | psotfx | $sql = "SELECT MAX(topic_id) AS max_topic |
| 1708 | 2093 | psotfx | FROM " . TOPICS_TABLE; |
| 1709 | 2093 | psotfx | $result = query($sql, "Couldn't get max topic id"); |
| 1710 | 1752 | psotfx | |
| 1711 | 2093 | psotfx | $row = $db->sql_fetchrow($result); |
| 1712 | 1752 | psotfx | |
| 1713 | 2093 | psotfx | $maxid = $row['max_topic']; |
| 1714 | 1752 | psotfx | |
| 1715 | 2093 | psotfx | lock_tables(1, array(TOPICS_TABLE, POSTS_TABLE)); |
| 1716 | 1752 | psotfx | |
| 1717 | 2093 | psotfx | $batchsize = 1000; |
| 1718 | 2093 | psotfx | for($i = 0; $i <= $maxid; $i += $batchsize) |
| 1719 | 2093 | psotfx | {
|
| 1720 | 2093 | psotfx | $batchstart = $i + 1; |
| 1721 | 2093 | psotfx | $batchend = $i + $batchsize; |
| 1722 | 2093 | psotfx | |
| 1723 | 2093 | psotfx | print " * Setting topic first post_id ( $batchstart to $batchend ) :: "; |
| 1724 | 2093 | psotfx | flush(); |
| 1725 | 1752 | psotfx | |
| 1726 | 2093 | psotfx | $sql = "SELECT MIN(post_id) AS first_post_id, topic_id |
| 1727 | 2093 | psotfx | FROM " . POSTS_TABLE . " |
| 1728 | 2093 | psotfx | WHERE topic_id |
| 1729 | 2093 | psotfx | BETWEEN $batchstart |
| 1730 | 2093 | psotfx | AND $batchend |
| 1731 | 2093 | psotfx | GROUP BY topic_id |
| 1732 | 2093 | psotfx | ORDER BY topic_id ASC"; |
| 1733 | 2093 | psotfx | $result = query($sql, "Couldn't get post id data"); |
| 1734 | 1752 | psotfx | |
| 1735 | 2093 | psotfx | $per_pct = ceil( $db->sql_numrows($result) / 40 ); |
| 1736 | 2093 | psotfx | $inc = 0; |
| 1737 | 1752 | psotfx | |
| 1738 | 2093 | psotfx | if ( $row = $db->sql_fetchrow($result) ) |
| 1739 | 2093 | psotfx | {
|
| 1740 | 2093 | psotfx | do |
| 1741 | 2093 | psotfx | {
|
| 1742 | 2093 | psotfx | $sql = "UPDATE " . TOPICS_TABLE . " |
| 1743 | 2093 | psotfx | SET topic_first_post_id = " . $row['first_post_id'] . " |
| 1744 | 2093 | psotfx | WHERE topic_id = " . $row['topic_id']; |
| 1745 | 2093 | psotfx | query($sql, "Couldn't update topic first post id in topic :: $topic_id"); |
| 1746 | 1752 | psotfx | |
| 1747 | 2093 | psotfx | $inc++; |
| 1748 | 2093 | psotfx | if ( $inc == $per_pct ) |
| 1749 | 1752 | psotfx | {
|
| 1750 | 2093 | psotfx | print "."; |
| 1751 | 2093 | psotfx | flush(); |
| 1752 | 2093 | psotfx | $inc = 0; |
| 1753 | 1752 | psotfx | } |
| 1754 | 2093 | psotfx | } |
| 1755 | 2093 | psotfx | while ( $row = $db->sql_fetchrow($result) ); |
| 1756 | 1519 | bartvb | } |
| 1757 | 1752 | psotfx | |
| 1758 | 2093 | psotfx | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1759 | 1519 | bartvb | } |
| 1760 | 1519 | bartvb | |
| 1761 | 2093 | psotfx | lock_tables(0); |
| 1762 | 2093 | psotfx | end_step('final_configuration');
|
| 1763 | 1242 | bartvb | |
| 1764 | 2093 | psotfx | case 'final_configuration': |
| 1765 | 1752 | psotfx | // |
| 1766 | 1752 | psotfx | // Update forum last post information |
| 1767 | 1752 | psotfx | // |
| 1768 | 1752 | psotfx | $sql = "SELECT forum_id, forum_name |
| 1769 | 1752 | psotfx | FROM " . FORUMS_TABLE; |
| 1770 | 1752 | psotfx | $f_result = query($sql, "Couldn't obtain forum_ids"); |
| 1771 | 1752 | psotfx | |
| 1772 | 1752 | psotfx | while( $forum_row = $db->sql_fetchrow($f_result) ) |
| 1773 | 1242 | bartvb | {
|
| 1774 | 2093 | psotfx | print " * Updating '" . $forum_row['forum_name'] . "' post info :: "; |
| 1775 | 1752 | psotfx | flush(); |
| 1776 | 1752 | psotfx | |
| 1777 | 1752 | psotfx | $id = $forum_row['forum_id']; |
| 1778 | 1752 | psotfx | |
| 1779 | 2093 | psotfx | $sql = "SELECT MIN(p.post_id) AS first_post, MAX(p.post_id) AS last_post |
| 1780 | 1752 | psotfx | FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t |
| 1781 | 1752 | psotfx | WHERE p.forum_id = $id |
| 1782 | 1752 | psotfx | AND p.topic_id = t.topic_id"; |
| 1783 | 1752 | psotfx | $result = query($sql, "Could not get post ID forum post information :: $id"); |
| 1784 | 1752 | psotfx | |
| 1785 | 2093 | psotfx | if ( $row = $db->sql_fetchrow($result) ) |
| 1786 | 1242 | bartvb | {
|
| 1787 | 2093 | psotfx | $first_post = ( $row['first_post'] ) ? $row['first_post'] : 0; |
| 1788 | 1752 | psotfx | $last_post = ($row['last_post']) ? $row['last_post'] : 0; |
| 1789 | 1242 | bartvb | } |
| 1790 | 1752 | psotfx | else |
| 1791 | 1242 | bartvb | {
|
| 1792 | 2093 | psotfx | $first_post = 0; |
| 1793 | 1752 | psotfx | $last_post = 0; |
| 1794 | 1242 | bartvb | } |
| 1795 | 1752 | psotfx | |
| 1796 | 1752 | psotfx | $sql = "SELECT COUNT(post_id) AS total |
| 1797 | 1752 | psotfx | FROM " . POSTS_TABLE . " |
| 1798 | 1752 | psotfx | WHERE forum_id = $id"; |
| 1799 | 1752 | psotfx | $result = query($sql, "Could not get post count forum post information :: $id"); |
| 1800 | 1752 | psotfx | |
| 1801 | 2093 | psotfx | if ( $row = $db->sql_fetchrow($result) ) |
| 1802 | 1752 | psotfx | {
|
| 1803 | 1752 | psotfx | $total_posts = ($row['total']) ? $row['total'] : 0; |
| 1804 | 1752 | psotfx | } |
| 1805 | 1242 | bartvb | else |
| 1806 | 1242 | bartvb | {
|
| 1807 | 1752 | psotfx | $total_posts = 0; |
| 1808 | 1242 | bartvb | } |
| 1809 | 1752 | psotfx | |
| 1810 | 1752 | psotfx | $sql = "SELECT COUNT(topic_id) AS total |
| 1811 | 1752 | psotfx | FROM " . TOPICS_TABLE . " |
| 1812 | 1752 | psotfx | WHERE forum_id = $id |
| 1813 | 1752 | psotfx | AND topic_status <> " . TOPIC_MOVED; |
| 1814 | 1752 | psotfx | $result = query($sql, "Could not get topic count forum post information :: $id"); |
| 1815 | 1752 | psotfx | |
| 1816 | 2093 | psotfx | if ( $row = $db->sql_fetchrow($result) ) |
| 1817 | 1438 | bartvb | {
|
| 1818 | 1752 | psotfx | $total_topics = ($row['total']) ? $row['total'] : 0; |
| 1819 | 1438 | bartvb | } |
| 1820 | 1752 | psotfx | else |
| 1821 | 1752 | psotfx | {
|
| 1822 | 1752 | psotfx | $total_topics = 0; |
| 1823 | 1752 | psotfx | } |
| 1824 | 1752 | psotfx | |
| 1825 | 1752 | psotfx | $sql = "UPDATE " . FORUMS_TABLE . " |
| 1826 | 1752 | psotfx | SET forum_last_post_id = $last_post, forum_posts = $total_posts, forum_topics = $total_topics |
| 1827 | 1752 | psotfx | WHERE forum_id = $id"; |
| 1828 | 1752 | psotfx | query($sql, "Could not update forum post information :: $id"); |
| 1829 | 1752 | psotfx | |
| 1830 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1831 | 1438 | bartvb | } |
| 1832 | 1752 | psotfx | |
| 1833 | 2093 | psotfx | print "<br />\n * Update default user and finalise configuration :: "; |
| 1834 | 1242 | bartvb | flush(); |
| 1835 | 1242 | bartvb | |
| 1836 | 1752 | psotfx | // |
| 1837 | 1752 | psotfx | // Update the default admin user with their information. |
| 1838 | 1752 | psotfx | // |
| 1839 | 1752 | psotfx | $sql = "SELECT MIN(user_regdate) AS oldest_time |
| 1840 | 1752 | psotfx | FROM " . USERS_TABLE . " |
| 1841 | 2433 | thefinn | WHERE user_regdate > 0 AND user_id > 0"; |
| 1842 | 1752 | psotfx | $result = query($sql, "Couldn't obtain oldest post time"); |
| 1843 | 1752 | psotfx | |
| 1844 | 1752 | psotfx | $row = $db->sql_fetchrow($result); |
| 1845 | 1752 | psotfx | |
| 1846 | 1752 | psotfx | $sql = "INSERT INTO " . $table_prefix . "config (config_name, config_value) |
| 1847 | 1752 | psotfx | VALUES ('board_startdate', " . $row['oldest_time'] . ")";
|
| 1848 | 1752 | psotfx | query($sql, "Couldn't insert board_startdate"); |
| 1849 | 1752 | psotfx | |
| 1850 | 2363 | the_systech | $sql = "UPDATE " . $table_prefix . "config |
| 1851 | 2363 | the_systech | SET config_value = '" . $server_name . "' |
| 1852 | 2363 | the_systech | WHERE config_name = 'server_name' |
| 1853 | 2363 | the_systech | OR config_name = 'cookie_domain'"; |
| 1854 | 2363 | the_systech | query($sql, "Couldn't insert Board Server domain"); |
| 1855 | 2363 | the_systech | |
| 1856 | 2363 | the_systech | $sql = "UPDATE " . $table_prefix . "config |
| 1857 | 2363 | the_systech | SET config_value = '" . $server_port . "' |
| 1858 | 2363 | the_systech | WHERE config_name = 'server_port'"; |
| 1859 | 2363 | the_systech | query($sql, "Couldn't insert Board server port"); |
| 1860 | 2363 | the_systech | |
| 1861 | 2363 | the_systech | $sql = "UPDATE " . $table_prefix . "config |
| 1862 | 2363 | the_systech | SET config_value = '" . $board_email . "' |
| 1863 | 2363 | the_systech | WHERE config_name = 'board_email'"; |
| 1864 | 2363 | the_systech | query($sql, "Couldn't insert Board admin email"); |
| 1865 | 2363 | the_systech | |
| 1866 | 2363 | the_systech | $sql = "UPDATE " . $table_prefix . "config |
| 1867 | 2363 | the_systech | SET config_value = '" . $script_path . "' |
| 1868 | 2363 | the_systech | WHERE config_name = 'script_path'"; |
| 1869 | 2363 | the_systech | query($sql, "Couldn't insert Board admin email"); |
| 1870 | 2363 | the_systech | |
| 1871 | 1752 | psotfx | // |
| 1872 | 1752 | psotfx | // Change session table to HEAP if MySQL version matches |
| 1873 | 1752 | psotfx | // |
| 1874 | 1752 | psotfx | $sql = "SELECT VERSION() AS mysql_version"; |
| 1875 | 1752 | psotfx | $result = query($sql, "Couldn't obtain MySQL Version"); |
| 1876 | 1752 | psotfx | |
| 1877 | 1752 | psotfx | $row = $db->sql_fetchrow($result); |
| 1878 | 1752 | psotfx | |
| 1879 | 1752 | psotfx | $version = $row['mysql_version']; |
| 1880 | 1752 | psotfx | |
| 1881 | 2093 | psotfx | if ( preg_match("/^(3\.23)|(4\.)/", $version) )
|
| 1882 | 1519 | bartvb | {
|
| 1883 | 1752 | psotfx | $sql = "ALTER TABLE " . $table_prefix . "sessions |
| 1884 | 1752 | psotfx | TYPE=HEAP"; |
| 1885 | 1771 | psotfx | $db->sql_query($sql); |
| 1886 | 1519 | bartvb | } |
| 1887 | 1752 | psotfx | |
| 1888 | 2093 | psotfx | echo "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1889 | 2093 | psotfx | end_step('drop_fields');
|
| 1890 | 1752 | psotfx | |
| 1891 | 2093 | psotfx | case 'drop_fields': |
| 1892 | 1752 | psotfx | $fields = array( |
| 1893 | 1752 | psotfx | BANLIST_TABLE => array("ban_start", "ban_end", "ban_time_type"),
|
| 1894 | 1758 | psotfx | FORUMS_TABLE => array("forum_access", "forum_moderator", "forum_type"),
|
| 1895 | 1752 | psotfx | PRIVMSGS_TABLE => array("msg_text"),
|
| 1896 | 1752 | psotfx | RANKS_TABLE => array("rank_max"),
|
| 1897 | 2356 | the_systech | SMILIES_TABLE => array("emotion"),
|
| 1898 | 2356 | the_systech | TOPICS_TABLE => array("topic_notify")
|
| 1899 | 1752 | psotfx | ); |
| 1900 | 1752 | psotfx | |
| 1901 | 1752 | psotfx | while( list($table, $field_data) = each($fields) ) |
| 1902 | 1519 | bartvb | {
|
| 1903 | 1752 | psotfx | for($i = 0; $i < count($field_data); $i++) |
| 1904 | 1242 | bartvb | {
|
| 1905 | 2093 | psotfx | print " * Drop field '" . $field_data[$i] . "' in '$table' :: "; |
| 1906 | 1752 | psotfx | flush(); |
| 1907 | 1752 | psotfx | |
| 1908 | 1752 | psotfx | $sql = "ALTER TABLE $table |
| 1909 | 1752 | psotfx | DROP COLUMN " . $field_data[$i]; |
| 1910 | 1752 | psotfx | query($sql, "Couldn't drop field :: " . $field_data[$i] . " from table :: $table"); |
| 1911 | 1752 | psotfx | |
| 1912 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1913 | 1752 | psotfx | |
| 1914 | 1242 | bartvb | } |
| 1915 | 1242 | bartvb | } |
| 1916 | 1242 | bartvb | |
| 1917 | 2093 | psotfx | end_step('drop_tables');
|
| 1918 | 1752 | psotfx | |
| 1919 | 2093 | psotfx | case 'drop_tables': |
| 1920 | 1766 | psotfx | $drop_tables = array('access', 'forum_access', 'forum_mods', 'headermetafooter', 'whosonline', $table_prefix . 'old_config');
|
| 1921 | 1752 | psotfx | |
| 1922 | 1752 | psotfx | for($i = 0; $i < count($drop_tables); $i++) |
| 1923 | 1752 | psotfx | {
|
| 1924 | 2093 | psotfx | print " * Dropping table '" . $drop_tables[$i] . "' :: "; |
| 1925 | 1752 | psotfx | flush(); |
| 1926 | 1752 | psotfx | |
| 1927 | 1752 | psotfx | $sql = "DROP TABLE " . $drop_tables[$i]; |
| 1928 | 1752 | psotfx | query($sql, "Couldn't drop table :: " . $drop_tables[$i]); |
| 1929 | 1752 | psotfx | |
| 1930 | 2093 | psotfx | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1931 | 1752 | psotfx | } |
| 1932 | 1752 | psotfx | |
| 1933 | 2093 | psotfx | echo "\n<br /><br />\n\n<font size=\"+3\"><b>UPGRADE COMPLETED</b></font><br />\n"; |
| 1934 | 1242 | bartvb | } |
| 1935 | 1242 | bartvb | } |
| 1936 | 1752 | psotfx | |
| 1937 | 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 />"; |
| 1938 | 1752 | psotfx | |
| 1939 | 2093 | psotfx | common_footer(); |
| 1940 | 2093 | psotfx | |
| 1941 | 2271 | bartvb | ?> |