[ Index ]
 

Code source de PHP NUKE 7.9

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/modules/Forums/ -> update_to_205.php (source)

   1  <?php
   2  /***************************************************************************
   3   *                             update_to_xxx.php
   4   *                            -------------------
   5   *   begin                : Wednesday, May 16, 2002
   6   *   copyright            : (C) 2001 The phpBB Group
   7   *   email                : support@phpbb.com
   8   *
   9   *   $Id: update_to_205.php,v 1.1.2.5 2003/06/13 21:35:22 acydburn Exp $
  10   *
  11   ***************************************************************************/
  12  /***************************************************************************
  13  * phpbb2 forums port version 2.0.5 (c) 2003 - Nuke Cops (http://nukecops.com)
  14  *
  15  * Ported by Nuke Cops to phpbb2 standalone 2.0.5 Test
  16  * and debugging completed by the Elite Nukers and site members.
  17  *
  18  * You run this package at your sole risk. Nuke Cops and affiliates cannot
  19  * be held liable if anything goes wrong. You are advised to test this
  20  * package on a development system. Backup everything before implementing
  21  * in a production environment. If something goes wrong, you can always
  22  * backout and restore your backups.
  23  *
  24  * Installing and running this also means you agree to the terms of the AUP
  25  * found at Nuke Cops.
  26  *
  27  * This is version 2.0.5 of the phpbb2 forum port for PHP-Nuke. Work is based
  28  * on Tom Nitzschner's forum port version 2.0.6. Tom's 2.0.6 port was based
  29  * on the phpbb2 standalone version 2.0.3. Our version 2.0.5 from Nuke Cops is
  30  * now reflecting phpbb2 standalone 2.0.5 that fixes some bugs and the
  31  * invalid_session error message.
  32  ***************************************************************************/
  33  /***************************************************************************
  34   *   This file is part of the phpBB2 port to Nuke 6.0 (c) copyright 2002
  35   *   by Tom Nitzschner (tom@toms-home.com)
  36   *   http://bbtonuke.sourceforge.net (or http://www.toms-home.com)
  37   *
  38   *   As always, make a backup before messing with anything. All code
  39   *   release by me is considered sample code only. It may be fully
  40   *   functual, but you use it at your own risk, if you break it,
  41   *   you get to fix it too. No waranty is given or implied.
  42   *
  43   *   Please post all questions/request about this port on http://bbtonuke.sourceforge.net first,
  44   *   then on my site. All original header code and copyright messages will be maintained
  45   *   to give credit where credit is due. If you modify this, the only requirement is
  46   *   that you also maintain all original copyright messages. All my work is released
  47   *   under the GNU GENERAL PUBLIC LICENSE. Please see the README for more information.
  48   *
  49   ***************************************************************************/
  50  /***************************************************************************
  51   *
  52   *   This program is free software; you can redistribute it and/or modify
  53   *   it under the terms of the GNU General Public License as published by
  54   *   the Free Software Foundation; either version 2 of the License, or
  55   *   (at your option) any later version.
  56   *
  57   ***************************************************************************/
  58  if (!eregi("modules.php", $_SERVER['PHP_SELF'])) {
  59      die ("You can't access this file directly...");
  60  }
  61  $module_name = basename(dirname(__FILE__));
  62  require("modules/".$module_name."/nukebb.php");
  63  function _sql($sql, &$errored, &$error_ary, $echo_dot = true)
  64  {
  65          global $db;
  66  
  67          if (!($result = $db->sql_query($sql)))
  68          {
  69                  $errored = true;
  70                  $error_ary['sql'][] = (is_array($sql)) ? $sql[$i] : $sql;
  71                  $error_ary['error_code'][] = $db->sql_error();
  72          }
  73  
  74          if ($echo_dot)
  75          {
  76                  echo ". \n";
  77                  flush();
  78          }
  79  
  80          return $result;
  81  }
  82  
  83  @set_time_limit(120);
  84  
  85  define('IN_PHPBB', 1);
  86  
  87  include ($phpbb_root_path . 'extension.inc');
  88  include($phpbb_root_path . 'config.'.$phpEx);
  89  
  90  include ("includes/constants.php");
  91  include ("includes/functions.php");
  92  include ("includes/functions_admin.php");
  93  include ("includes/functions_search.php");
  94  include ("db/db.php");
  95  
  96  
  97  //
  98  //
  99  //
 100  $updates_to_version = ".0.5";
 101  //
 102  //
 103  //
 104  
 105  ?>
 106  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 107  <html>
 108  <head>
 109  <meta http-equiv="Content-Type" content="text/html;">
 110  <meta http-equiv="Content-Style-Type" content="text/css">
 111  <style type="text/css">
 112  <!--
 113  
 114  font,th,td,p,body { font-family: "Courier New", courier; font-size: 11pt }
 115  
 116  a:link,a:active,a:visited { color : #006699; }
 117  a:hover                { text-decoration: underline; color : #DD6900;}
 118  
 119  hr        { height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;}
 120  
 121  .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;}
 122  
 123  .ok {color:green}
 124  
 125  /* Import the fancy styles for IE only (NS4.x doesn't use the @import function) */
 126  @import url("modules/Forums/templates/subSilver/formIE.css");
 127  -->
 128  </style>
 129  </head>
 130  <body bgcolor="#FFFFFF" text="#000000" link="#006699" vlink="#5584AA">
 131  
 132  <table width="100%" border="0" cellspacing="0" cellpadding="10" align="center">
 133          <tr>
 134                  <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
 135                          <tr>
 136                                  <td><img src="modules/Forums/templates/subSilver/images/logo_phpBB.gif" border="0" alt="Forum Home" vspace="1" /></td>
 137                                  <td align="center" width="100%" valign="middle"><span class="maintitle">Updating to latest stable release</span></td>
 138                          </tr>
 139                  </table></td>
 140          </tr>
 141  </table>
 142  
 143  <br clear="all" />
 144  
 145  <h2>Information</h2>
 146  
 147  <?php
 148  
 149  echo '<p>Database type &nbsp; &nbsp;:: <b>' . SQL_LAYER . '</b><br />';
 150  
 151  $sql = "SELECT config_value
 152          FROM " . CONFIG_TABLE . "
 153          WHERE config_name = 'version'";
 154  if (!($result = $db->sql_query($sql)))
 155  {
 156          die("Couldn't obtain version info");
 157  }
 158  
 159  $row = $db->sql_fetchrow($result);
 160  if ($row['config_value'] != '.0.4')
 161  {
 162                  echo 'Your Current forum version is <b>' . $row['config_value'] . '</b> This upgrade script requires <b>PHP-Nuke 6.5</b> and <b>BBtoNuke .0.4</b><br><br />If you <b>are</b> running PHP-Nuke 6.5 maybe you have not applied sec-fix patch 3,<br> if that is the case get it <a href=http://nukecops.com/downloads-file-71-details-PHP-Nuke_6.5_Bug-Sec_Patch_3.html target=_blank><u>here</u></a> then try upgrading again once the patch has been applied.<br><br />';
 163          die("BBtoNuke Update Failed");
 164  }
 165  $sql = array();
 166  
 167  switch ($row['config_value'])
 168  {
 169          case '':
 170                  echo 'Previous version :: <b>&lt; RC-3</b></p><br />';
 171                  break;
 172          case 'RC-3':
 173                  echo 'Previous version :: <b>RC-3</b></p><br />';
 174                  break;
 175          case 'RC-4':
 176                  echo 'Previous version :: <b>RC-4</b></p><br />';
 177                  break;
 178          default:
 179                  echo 'Previous version :: <b>2' . $row['config_value'] . '</b><br />';
 180                  break;
 181  }
 182  
 183  echo 'Updated version &nbsp;:: <b>2' . $updates_to_version . '</b></p>' ."\n";
 184  
 185  //
 186  // Schema updates
 187  //
 188  switch ($row['config_value'])
 189  {
 190          case '':
 191                  switch (SQL_LAYER)
 192                  {
 193                          case 'mysql':
 194                          case 'mysql4':
 195                                  $sql[] = "ALTER TABLE " . USERS_TABLE . " DROP
 196                                          COLUMN user_autologin_key";
 197  
 198                                  $sql[] = "ALTER TABLE " . RANKS_TABLE . " DROP
 199                                          COLUMN rank_max";
 200  
 201                                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
 202                                          ADD COLUMN user_session_time int(11) DEFAULT '0' NOT NULL,
 203                                          ADD COLUMN user_session_page smallint(5) DEFAULT '0' NOT NULL,
 204                                          ADD INDEX (user_session_time)";
 205                                  $sql[] = "ALTER TABLE " . SEARCH_TABLE . "
 206                                          MODIFY search_id int(11) NOT NULL";
 207  
 208                                  $sql[] = "ALTER TABLE " . TOPICS_TABLE . "
 209                                          MODIFY topic_moved_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
 210                                          ADD COLUMN topic_first_post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
 211                                          ADD INDEX (topic_first_post_id)";
 212  
 213                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
 214                                          ADD COLUMN tr_class1_name varchar(50) NULL,
 215                                          ADD COLUMN tr_class2_name varchar(50) NULL,
 216                                          ADD COLUMN tr_class3_name varchar(50) NULL,
 217                                          ADD COLUMN th_class1_name varchar(50) NULL,
 218                                          ADD COLUMN th_class2_name varchar(50) NULL,
 219                                          ADD COLUMN th_class3_name varchar(50) NULL,
 220                                          ADD COLUMN td_class1_name varchar(50) NULL,
 221                                          ADD COLUMN td_class2_name varchar(50) NULL,
 222                                          ADD COLUMN td_class3_name varchar(50) NULL,
 223                                          ADD COLUMN span_class1_name varchar(50) NULL,
 224                                          ADD COLUMN span_class2_name varchar(50) NULL,
 225                                          ADD COLUMN span_class3_name varchar(50) NULL";
 226                                  break;
 227                          case 'postgresql':
 228                                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
 229                                          ADD COLUMN user_session_time int4";
 230                                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
 231                                          ADD COLUMN user_session_page int2";
 232                                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
 233                                          ALTER COLUMN user_session_time SET DEFAULT '0'";
 234                                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
 235                                          ALTER COLUMN user_session_page SET DEFAULT '0'";
 236                                  $sql[] = "CREATE INDEX user_session_time_" . $table_prefix . "users_index
 237                                          ON " . USERS_TABLE . " (user_session_time)";
 238  
 239                                  $sql[] = "ALTER TABLE " . TOPICS_TABLE . "
 240                                          ADD COLUMN topic_first_post_id int4";
 241                                  $sql[] = "CREATE INDEX topic_first_post_id_" . $table_prefix . "topics_index
 242                                          ON " . TOPICS_TABLE . " (topic_first_post_id)";
 243  
 244                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
 245                                          ADD COLUMN tr_class1_name varchar(50) NULL";
 246                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
 247                                          ADD COLUMN tr_class2_name varchar(50) NULL";
 248                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
 249                                          ADD COLUMN tr_class3_name varchar(50) NULL";
 250                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
 251                                          ADD COLUMN th_class1_name varchar(50) NULL";
 252                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
 253                                          ADD COLUMN th_class2_name varchar(50) NULL";
 254                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
 255                                          ADD COLUMN th_class3_name varchar(50) NULL";
 256                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
 257                                          ADD COLUMN td_class1_name varchar(50) NULL";
 258                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
 259                                          ADD COLUMN td_class2_name varchar(50) NULL";
 260                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
 261                                          ADD COLUMN td_class3_name varchar(50) NULL";
 262                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
 263                                          ADD COLUMN span_class1_name varchar(50) NULL";
 264                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
 265                                          ADD COLUMN span_class2_name varchar(50) NULL";
 266                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
 267                                          ADD COLUMN span_class3_name varchar(50) NULL";
 268                                  break;
 269  
 270                          case 'mssql-odbc':
 271                          case 'mssql':
 272                                  $sql[] = "ALTER TABLE " . USERS_TABLE . " DROP
 273                                          COLUMN user_autologin_key";
 274  
 275                                  $sql[] = "ALTER TABLE " . USERS_TABLE . " ADD
 276                                          user_session_time int NOT NULL,
 277                                          user_session_page smallint NOT NULL,
 278                                          CONSTRAINT [DF_" . $table_prefix . "users_user_session_time] DEFAULT (0) FOR [user_session_time],
 279                                          CONSTRAINT [DF_" . $table_prefix . "users_user_session_page] DEFAULT (0) FOR [user_session_page]";
 280                                  $sql[] = "CREATE INDEX [IX_" . $table_prefix . "users]
 281                                          ON [" . USERS_TABLE . "]([user_session_time]) ON [PRIMARY]";
 282  
 283                                  /* ---------------------------------------------------------------------
 284                                          DROP FORUM TABLE -- if this may cause you problems you can safely
 285                                          comment it out, remember to manually remove the IDENTITY setting on
 286                                          the forum_id column
 287                                     ---------------------------------------------------------------------
 288                                  $sql [] = "ALTER TABLE " . FORUMS_TABLE . " DROP
 289                                          CONSTRAINT [DF_" . $table_prefix . "forums_forum_posts],
 290                                          CONSTRAINT [DF_" . $table_prefix . "forums_forum_topics],
 291                                          CONSTRAINT [DF_" . $table_prefix . "forums_forum_last_post_id],
 292                                          CONSTRAINT [DF_" . $table_prefix . "forums_prune_enable],
 293                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_view],
 294                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_read],
 295                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_post],
 296                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_reply],
 297                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_edit],
 298                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_delete],
 299                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_sticky],
 300                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_announce],
 301                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_vote],
 302                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_pollcreate],
 303                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_attachments]";
 304                                  $sql[] = "CREATE TABLE Tmp_" . FORUMS_TABLE . "
 305                                          (forum_id int NOT NULL, cat_id int NOT NULL, forum_name varchar(100) NOT NULL, forum_desc varchar(255) NULL, forum_status smallint NOT NULL, forum_order int NOT NULL, forum_posts int NOT NULL, forum_topics smallint NOT NULL, forum_last_post_id int NOT NULL, prune_next int NULL, prune_enable smallint NOT NULL, auth_view smallint NOT NULL, auth_read smallint NOT NULL, auth_post smallint NOT NULL, auth_reply smallint NOT NULL, auth_edit smallint NOT NULL, auth_delete smallint NOT NULL,        auth_sticky smallint NOT NULL, auth_announce smallint NOT NULL, auth_vote smallint NOT NULL, auth_pollcreate smallint NOT NULL, auth_attachments smallint NOT NULL) ON [PRIMARY]";
 306                                  $sql[] = "ALTER TABLE [Tmp_" . FORUMS_TABLE . "] WITH NOCHECK ADD
 307                                          CONSTRAINT [DF_" . $table_prefix . "forums_forum_posts] DEFAULT (0) FOR [forum_posts],
 308                                          CONSTRAINT [DF_" . $table_prefix . "forums_forum_topics] DEFAULT (0) FOR [forum_topics],
 309                                          CONSTRAINT [DF_" . $table_prefix . "forums_forum_last_post_id] DEFAULT (0) FOR [forum_last_post_id],
 310                                          CONSTRAINT [DF_" . $table_prefix . "forums_prune_enable] DEFAULT (0) FOR [prune_enable],
 311                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_view] DEFAULT (0) FOR [auth_view],
 312                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_read] DEFAULT (0) FOR [auth_read],
 313                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_post] DEFAULT (0) FOR [auth_post],
 314                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_reply] DEFAULT (0) FOR [auth_reply],
 315                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_edit] DEFAULT (0) FOR [auth_edit],
 316                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_delete] DEFAULT (0) FOR [auth_delete],
 317                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_sticky] DEFAULT (0) FOR [auth_sticky],
 318                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_announce] DEFAULT (0) FOR [auth_announce],
 319                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_vote] DEFAULT (0) FOR [auth_vote],
 320                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_pollcreate] DEFAULT (0) FOR [auth_pollcreate],
 321                                          CONSTRAINT [DF_" . $table_prefix . "forums_auth_attachments] DEFAULT (0) FOR [auth_attachments]";
 322                                  $sql[] = "INSERT INTO Tmp_" . FORUMS_TABLE . " (forum_id, cat_id, forum_name, forum_desc, forum_status, forum_order, forum_posts, forum_topics, forum_last_post_id, prune_next, prune_enable, auth_view, auth_read, auth_post, auth_reply, auth_edit, auth_delete, auth_sticky, auth_announce, auth_vote, auth_pollcreate, auth_attachments)
 323                                                  SELECT forum_id, cat_id, forum_name, forum_desc, forum_status, forum_order, forum_posts, forum_topics, forum_last_post_id, prune_next, prune_enable, auth_view, auth_read, auth_post, auth_reply, auth_edit, auth_delete, auth_sticky, auth_announce, auth_vote, auth_pollcreate, auth_attachments FROM " . FORUMS_TABLE . " TABLOCKX";
 324                                  $sql[] = "DROP TABLE " . FORUMS_TABLE;
 325                                  $sql[] = "EXECUTE sp_rename N'Tmp_" . FORUMS_TABLE . "', N'" . FORUMS_TABLE . "', 'OBJECT'";
 326                                  $sql[] = "ALTER TABLE " . FORUMS_TABLE . " ADD
 327                                          CONSTRAINT [PK_" . $table_prefix . "forums] PRIMARY KEY CLUSTERED (forum_id) ON [PRIMARY]";
 328                                  $sql[] = "CREATE NONCLUSTERED INDEX [IX_" . $table_prefix . "forums]
 329                                          ON " . FORUMS_TABLE . " (cat_id, forum_order, forum_last_post_id) ON [PRIMARY]";
 330                                   --------------------------------------------------------------
 331                                          END OF DROP FORUM -- don't remove anything after this point!
 332                                     -------------------------------------------------------------- */
 333  
 334                                  $sql[] = "DROP INDEX " . RANKS_TABLE . ".IX_" . $table_prefix . "ranks";
 335                                  $sql[] = "ALTER TABLE " . RANKS_TABLE . " DROP
 336                                          COLUMN rank_max";
 337                                  $sql[] = "CREATE  INDEX [IX_" . $table_prefix . "ranks]
 338                                          ON [" . RANKS_TABLE . "]([rank_min], [rank_special]) ON [PRIMARY]";
 339  
 340                                  $sql[] = "DROP INDEX " . TOPICS_TABLE . ".IX_" . $table_prefix . "topics";
 341                                  $sql[] = "ALTER TABLE " . TOPICS_TABLE . " ADD
 342                                          topic_first_post_id int NULL,
 343                                          CONSTRAINT [DF_" . $table_prefix . "topics_topic_first_post_id] FOR [topic_first_post_id]";
 344                                  $sql[] = "CREATE  INDEX [IX_" . $table_prefix . "topics]
 345                                          ON [" . TOPICS_TABLE . "]([forum_id], [topic_type], [topic_first_post_id], [topic_last_post_id]) ON [PRIMARY]";
 346  
 347                                  $sql[] = "ALTER TABLE " . SEARCH_WORD_TABLE . " DROP
 348                                          CONSTRAINT [PK_" . $table_prefix . "search_wordlist]";
 349                                  $sql[] = "CREATE UNIQUE INDEX [IX_" . $table_prefix . "search_wordlist]
 350                                          ON [" . SEARCH_WORD_TABLE . "]([word_text]) WITH IGNORE_DUP_KEY ON [PRIMARY]";
 351                                  $sql[] = "CREATE  INDEX [IX_" . $table_prefix . "search_wordlist_1]
 352                                          ON [" . SEARCH_WORD_TABLE . "]([word_common]) ON [PRIMARY]";
 353  
 354                                  $sql[] = "CREATE INDEX [IX_" . $table_prefix . "search_wordmatch_1]
 355                                          ON [" . SEARCH_MATCH_TABLE . "]([word_id]) ON [PRIMARY]";
 356  
 357                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . " ADD
 358                                          tr_class1_name varchar(50) NULL,
 359                                          tr_class2_name varchar(50) NULL,
 360                                          tr_class3_name varchar(50) NULL,
 361                                          th_class1_name varchar(50) NULL,
 362                                          th_class2_name varchar(50) NULL,
 363                                          th_class3_name varchar(50) NULL,
 364                                          td_class1_name varchar(50) NULL,
 365                                          td_class2_name varchar(50) NULL,
 366                                          td_class3_name varchar(50) NULL,
 367                                          span_class1_name varchar(50) NULL,
 368                                          span_class2_name varchar(50) NULL,
 369                                          span_class3_name varchar(50) NULL";
 370                                  break;
 371  
 372                          case 'msaccess':
 373                                  $sql[] = "ALTER TABLE " . USERS_TABLE . " DROP
 374                                          COLUMN user_autologin_key";
 375  
 376                                  $sql[] = "ALTER TABLE " . USERS_TABLE . " ADD
 377                                          user_session_time int NOT NULL,
 378                                          user_session_page smallint NOT NULL";
 379                                  $sql[] = "CREATE INDEX user_session_time
 380                                          ON " . USERS_TABLE . " (user_session_time)";
 381  
 382                                  $sql[] = "ALTER TABLE " . TOPICS_TABLE . " ADD
 383                                          topic_first_post_id int NULL";
 384                                  $sql[] = "CREATE INDEX topic_first_post_id
 385                                          ON " . TOPICS_TABLE . " (topic_first_post_id)";
 386  
 387                                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . " ADD
 388                                          tr_class1_name varchar(50) NULL,
 389                                          tr_class2_name varchar(50) NULL,
 390                                          tr_class3_name varchar(50) NULL,
 391                                          th_class1_name varchar(50) NULL,
 392                                          th_class2_name varchar(50) NULL,
 393                                          th_class3_name varchar(50) NULL,
 394                                          td_class1_name varchar(50) NULL,
 395                                          td_class2_name varchar(50) NULL,
 396                                          td_class3_name varchar(50) NULL,
 397                                          span_class1_name varchar(50) NULL,
 398                                          span_class2_name varchar(50) NULL,
 399                                          span_class3_name varchar(50) NULL";
 400                                  break;
 401  
 402                          default:
 403                                  die("No DB LAYER found!");
 404                                  break;
 405                  }
 406  
 407          case 'RC-3':
 408          case 'RC-4':
 409          case '.0.0':
 410                  switch (SQL_LAYER)
 411                  {
 412                          case 'mysql':
 413                          case 'mysql4':
 414                                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
 415                                          MODIFY COLUMN user_id  mediumint(8) NOT NULL,
 416                                          MODIFY COLUMN user_timezone decimal(5,2) DEFAULT '0' NOT NULL";
 417                                  break;
 418                          case 'postgresql':
 419                                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
 420                                          RENAME COLUMN user_timezone TO user_timezone_old";
 421                                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
 422                                          ADD COLUMN user_timezone decimal(5)";
 423                                  break;
 424                          case 'mssql':
 425                          case 'mssql-odbc':
 426                                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
 427                                          ALTER COLUMN [user_timezone] [decimal] (5,2) NOT NULL";
 428                                  break;
 429                  }
 430  
 431          case '.0.1':
 432                  switch (SQL_LAYER)
 433                  {
 434                          case 'mysql':
 435                          case 'mysql4':
 436                                  $sql[] = "ALTER TABLE " . GROUPS_TABLE . "
 437                                          MODIFY COLUMN group_id mediumint(8) NOT NULL auto_increment";
 438                                  break;
 439                          case 'mssql':
 440                          case 'mssql-odbc':
 441                                  /* ---------------------------------------------------------------------
 442                                          DROP GROUP TABLE -- if this may cause you problems you can safely
 443                                          comment it out, remember to manually add the IDENTITY setting on
 444                                          the group_id column
 445                                     ---------------------------------------------------------------------
 446                                  $sql[] = "CREATE TABLE Tmp_" . GROUPS_TABLE . "
 447                                          (group_id int IDENTITY (1, 1) NOT NULL, group_type smallint NULL, group_name varchar(50) NOT NULL, group_description varchar(255) NOT NULL, group_moderator int NULL, group_single_user smallint NOT NULL) ON [PRIMARY]";
 448                                  $sql[] = "SET IDENTITY_INSERT " . GROUPS_TABLE . " ON";
 449                                  $sql[] = "INSERT INTO Tmp_" . GROUPS_TABLE . " (group_id, group_type, group_name, group_description, group_moderator, group_single_user)
 450                                          SELECT group_id, group_type, group_name, group_description, group_moderator, group_single_user FROM " . GROUPS_TABLE . " TABLOCKX";
 451                                  $sql[] = "SET IDENTITY_INSERT " . GROUPS_TABLE . " OFF";
 452                                  $sql[] = "DROP TABLE " . GROUPS_TABLE;
 453                                  $sql[] = "EXECUTE sp_rename N'Tmp_" . GROUPS_TABLE . "', N'" . GROUPS_TABLE . "', 'OBJECT'";
 454                                  $sql[] = "ALTER TABLE " . GROUPS_TABLE . " ADD
 455                                          CONSTRAINT [PK_" . $table_prefix . "groups] PRIMARY KEY CLUSTERED (group_id) ON [PRIMARY]";
 456                                  $sql[] = "CREATE INDEX [IX_" . $table_prefix . "groups]
 457                                          ON " . GROUPS_TABLE . " (group_single_user) ON [PRIMARY]";
 458                                  --------------------------------------------------------------
 459                                          END OF DROP GROUP -- don't remove anything after this point!
 460                                     -------------------------------------------------------------- */
 461                                  break;
 462  
 463                  }
 464  
 465          case '.0.3':
 466  
 467                  switch (SQL_LAYER)
 468                  {
 469                          case 'mysql':
 470                          case 'mysql4':
 471                                  // Add indexes to post_id in search match table (+ word_id for MS Access)
 472                                  $sql[] = "ALTER TABLE " . SEARCH_MATCH_TABLE . "
 473                                          ADD INDEX post_id (post_id)";
 474  
 475                                  // Modify user_timezone to decimal(5,2) for mysql ... mysql4/mssql/pgsql/msaccess
 476                                  // should be completely unaffected
 477                                  // Change default user_notify to 0
 478                                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
 479                                          MODIFY COLUMN user_timezone decimal(5,2) DEFAULT '0' NOT NULL,
 480                                          MODIFY COLUMN user_notify tinyint(1) DEFAULT '0' NOT NULL";
 481  
 482                                  // Adjust field type for prune_days, prune_freq ... was too small
 483                                  $sql[] = "ALTER TABLE " . PRUNE_TABLE . "
 484                                          MODIFY COLUMN prune_days smallint(5) UNSIGNED NOT NULL,
 485                                          MODIFY COLUMN prune_freq smallint(5) UNSIGNED NOT NULL";
 486                                  break;
 487  
 488                          case 'msaccess':
 489                                  // Add indexes to post_id in search match table (+ word_id for MS Access)
 490                                  $sql[] = "CREATE INDEX " . SEARCH_MATCH_TABLE . "
 491                                          ON " . SEARCH_MATCH_TABLE . " ([post_id])";
 492                                  $sql[] = "CREATE INDEX " . SEARCH_MATCH_TABLE . "_1
 493                                          ON " . SEARCH_MATCH_TABLE . " ([word_id])";
 494                                  break;
 495  
 496                          case 'postgresql':
 497                                  // Add indexes to post_id in search match table (+ word_id for MS Access)
 498                                  $sql[] = "CREATE INDEX post_id_" . SEARCH_MATCH_TABLE . "
 499                                          ON " . SEARCH_MATCH_TABLE . " (post_id)";
 500  
 501                                  // Regenerate groups table with incremented group_id for pgsql
 502                                  // ... missing in 2.0.3 ...
 503                                  $sql[] = "CREATE SEQUENCE " . GROUPS_TABLE . "_id_seq start 3 increment 1 maxvalue 2147483647 minvalue 1 cache 1";
 504                                  $sql[] = "CREATE TABLE tmp_" . GROUPS_TABLE . "
 505                                          AS SELECT group_id, group_name, group_type, group_description, group_moderator, group_single_user
 506                                                  FROM " . GROUPS_TABLE;
 507                                  $sql[] = "DROP TABLE " . GROUPS_TABLE;
 508                                  $sql[] = "CREATE TABLE phpbb_groups (group_id int DEFAULT nextval('" . GROUPS_TABLE . "_id_seq'::text) NOT NULL, group_name varchar(40) NOT NULL, group_type int2 DEFAULT '1' NOT NULL, group_description varchar(255) NOT NULL, group_moderator int4 DEFAULT '0' NOT NULL, group_single_user int2 DEFAULT '0' NOT NULL, CONSTRAINT phpbb_groups_pkey PRIMARY KEY (group_id))";
 509                                  $sql[] = "INSERT INTO " . GROUPS_TABLE . " (group_id, group_name, group_type, group_description, group_moderator, group_single_user)
 510                                          SELECT group_id, group_name, group_type, group_description, group_moderator, group_single_user
 511                                                  FROM tmp_" . GROUPS_TABLE;
 512                                  $sql[] = "DROP TABLE tmp_" . GROUPS_TABLE;
 513                                  break;
 514                  }
 515  
 516          case '.0.4':
 517  
 518                  switch (SQL_LAYER)
 519                  {
 520                          case 'mssql':
 521                          case 'mssql-odbc':
 522                                  // Add missing defaults to MSSQL post table schema, failed in previous updates
 523                                  $sql[] = "ALTER TABLE [" . POSTS_TABLE . "] WITH NOCHECK ADD
 524                                          CONSTRAINT [DF_" . POSTS_TABLE . "_enable_bbcode] DEFAULT (1) FOR [enable_bbcode],
 525                                          CONSTRAINT [DF_" . POSTS_TABLE . "_enable_html] DEFAULT (0) FOR [enable_html],
 526                                          CONSTRAINT [DF_" . POSTS_TABLE . "_enable_smilies] DEFAULT (1) FOR [enable_smilies],
 527                                          CONSTRAINT [DF_" . POSTS_TABLE . "_enable_sig] DEFAULT (1) FOR [enable_sig],
 528                                          CONSTRAINT [DF_" . POSTS_TABLE . "_post_edit_count] DEFAULT (0) FOR [post_edit_count]";
 529                                  break;
 530                  }
 531  
 532                  // Add tables for visual confirmation ... saves me the trouble of writing a seperate
 533                  // script :D
 534                  switch (SQL_LAYER)
 535                  {
 536                          case 'mysql':
 537                          case 'mysql4':
 538                                  $sql[] = 'CREATE TABLE ' . $table_prefix . 'confirm (confirm_id char(32) DEFAULT \'\' NOT NULL, session_id char(32) DEFAULT \'\' NOT NULL, code char(6) DEFAULT \'\' NOT NULL, PRIMARY KEY (session_id, confirm_id))';
 539                                  break;
 540  
 541                          case 'mssql':
 542                          case 'mssql-odbc':
 543                                  $sql[] = 'CREATE TABLE [' . $table_prefix . 'confirm] ([confirm_id] [char] (32) NOT NULL , [session_id] [char] (32) NOT NULL , [code] [char] (6) NOT NULL ) ON [PRIMARY]';
 544                                  $sql[] = 'ALTER TABLE [' . $table_prefix . 'confirm] WITH NOCHECK ADD CONSTRAINT [PK_' . $table_prefix . 'confirm] PRIMARY KEY  CLUSTERED ( [session_id,confirm_id])  ON [PRIMARY]';
 545                                  $sql[] = 'ALTER TABLE [' . $table_prefix . 'confirm] WITH NOCHECK ADD CONSTRAINT [DF_' . $table_prefix . 'confirm_confirm_id] DEFAULT (\'\') FOR [confirm_id], CONSTRAINT [DF_' . $table_prefix . 'confirm_session_id] DEFAULT (\'\') FOR [session_id], CONSTRAINT [DF_' . $table_prefix . 'confirm_code] DEFAULT (\'\') FOR [code]';
 546                                  break;
 547  
 548                          case 'msaccess':
 549                                  $sql[] = 'CREATE TABLE ' . $table_prefix . 'confirm (confirm_id char(32) NOT NULL, session_id char(32) NOT NULL, code char(6) NOT NULL)';
 550                                  $sql[] = 'ALTER TABLE ' . $table_prefix . 'confirm ADD (PRIMARY KEY (session_id, confirm_id))';
 551                                  break;
 552  
 553                          case 'postgresql':
 554                                  $sql[] = 'CREATE TABLE ' . $table_prefix . 'confirm (confirm_id char(32) DEFAULT \'\' NOT NULL,  session_id char(32) DEFAULT \'\' NOT NULL, code char(6) DEFAULT \'\' NOT NULL, CONSTRAINT phpbb_confirm_pkey PRIMARY KEY (session_id, confirm_id))';
 555                                  break;
 556                  }
 557  
 558                  break;
 559  }
 560  
 561  echo "<h2>Updating database schema</h2>\n";
 562  echo "<p>Progress :: <b>";
 563  flush();
 564  
 565  $error_ary = array();
 566  $errored = false;
 567  if (count($sql))
 568  {
 569          for ($i = 0; $i < count($sql); $i++)
 570          {
 571                  _sql($sql[$i], $errored, $error_ary);
 572          }
 573  
 574          echo "</b> <b class=\"ok\">Done</b><br />Result &nbsp; :: \n";
 575  
 576          if ($errored)
 577          {
 578                  echo " <b>Some queries failed, the statements and errors are listing below</b>\n<ul>";
 579  
 580                  for ($i = 0; $i < count($error_ary['sql']); $i++)
 581                  {
 582                          echo "<li>Error :: <b>" . $error_ary['error_code'][$i]['message'] . "</b><br />";
 583                          echo "SQL &nbsp; :: <b>" . $error_ary['sql'][$i] . "</b><br /><br /></li>";
 584                  }
 585  
 586                  echo "</ul>\n<p>This is probably nothing to worry about, update will continue. Should this fail to complete you may need to seek help at our development board. See <a href=\"docs\README.html\">README</a> for details on how to obtain advice.</p>\n";
 587          }
 588          else
 589          {
 590                  echo "<b>No errors</b>\n";
 591          }
 592  }
 593  else
 594  {
 595          echo " No updates required</b></p>\n";
 596  }
 597  
 598  //
 599  // Data updates
 600  //
 601  unset($sql);
 602  $error_ary = array();
 603  $errored = false;
 604  
 605  echo "<h2>Updating data</h2>\n";
 606  echo "<p>Progress :: <b>";
 607  flush();
 608  
 609  switch ($row['config_value'])
 610  {
 611          case '':
 612                  $sql = "SELECT themes_id
 613                          FROM " . THEMES_TABLE . "
 614                          WHERE template_name = 'subSilver'";
 615                  $result = _sql($sql, $errored, $error_ary);
 616  
 617                  if ($row = $db->sql_fetchrow($result))
 618                  {
 619                          $theme_id = $row['themes_id'];
 620  
 621                          $sql = "UPDATE " . THEMES_TABLE . "
 622                                  SET head_stylesheet = 'subSilver.css', body_background = '', body_bgcolor = 'E5E5E5', body_text = '000000', body_link = '006699', body_vlink = '5493B4', body_alink = '', body_hlink = 'DD6900', tr_color1 = 'EFEFEF', tr_color2 = 'DEE3E7', tr_color3 = 'D1D7DC', tr_class1 = '', tr_class2 = '', tr_class3 = '', th_color1 = '98AAB1', th_color2 = '006699', th_color3 = 'FFFFFF', th_class1 = 'cellpic1.gif', th_class2 = 'cellpic3.gif', th_class3 = 'cellpic2.jpg', td_color1 = 'FAFAFA', td_color2 = 'FFFFFF', td_color3 = '', td_class1 = 'row1', td_class2 = 'row2', td_class3 = '', fontface1 = 'Verdana, Arial, Helvetica, sans-serif', fontface2 = 'Trebuchet MS', fontface3 = 'Courier, ''Courier New'', sans-serif', fontsize1 = 10, fontsize2 = 11, fontsize3 = 12, fontcolor1 = '444444', fontcolor2 = '006600', fontcolor3 = 'FFA34F', span_class1 = '', span_class2 = '', span_class3 = ''
 623                                  WHERE themes_id = $theme_id";
 624                          _sql($sql, $errored, $error_ary);
 625  
 626                          $sql = "DELETE FROM " . THEMES_NAME_TABLE . "
 627                                  WHERE themes_id = $theme_id";
 628                          _sql($sql, $errored, $error_ary);
 629  
 630                          $sql = "INSERT INTO " . THEMES_NAME_TABLE . " (themes_id, tr_color1_name, tr_color2_name, tr_color3_name, tr_class1_name, tr_class2_name, tr_class3_name, th_color1_name, th_color2_name, th_color3_name, th_class1_name, th_class2_name, th_class3_name, td_color1_name, td_color2_name, td_color3_name, td_class1_name, td_class2_name, td_class3_name, fontface1_name, fontface2_name, fontface3_name, fontsize1_name, fontsize2_name, fontsize3_name, fontcolor1_name, fontcolor2_name, fontcolor3_name, span_class1_name, span_class2_name, span_class3_name)
 631                                  VALUES ($theme_id, 'The lightest row colour', 'The medium row color', 'The darkest row colour', '', '', '', 'Border round the whole page', 'Outer table border', 'Inner table border', 'Silver gradient picture', 'Blue gradient picture', 'Fade-out gradient on index', 'Background for quote boxes', 'All white areas', '', 'Background for topic posts', '2nd background for topic posts', '', 'Main fonts', 'Additional topic title font', 'Form fonts', 'Smallest font size', 'Medium font size', 'Normal font size (post body etc)', 'Quote & copyright text', 'Code text colour', 'Main table header text colour', '', '', '')";
 632                          _sql($sql, $errored, $error_ary);
 633                  }
 634                  $db->sql_freeresult($result);
 635  
 636                  $sql = "SELECT MIN(post_id) AS first_post_id, topic_id
 637                          FROM " . POSTS_TABLE . "
 638                          GROUP BY topic_id
 639                          ORDER BY topic_id ASC";
 640                  $result = _sql($sql, $errored, $error_ary);
 641  
 642                  if ($row = $db->sql_fetchrow($result))
 643                  {
 644                          do
 645                          {
 646                                  $sql = "UPDATE " . TOPICS_TABLE . "
 647                                          SET topic_first_post_id = " . $row['first_post_id'] . "
 648                                          WHERE topic_id = " . $row['topic_id'];
 649                                  _sql($sql, $errored, $error_ary);
 650                          }
 651                          while ($row = $db->sql_fetchrow($result));
 652                  }
 653                  $db->sql_freeresult($result);
 654  
 655                  $sql = "SELECT DISTINCT u.user_id
 656                          FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug, " . AUTH_ACCESS_TABLE . " aa
 657                          WHERE aa.auth_mod = 1
 658                                  AND ug.group_id = aa.group_id
 659                                  AND u.user_id = ug.user_id
 660                                  AND u.user_level <> " . ADMIN;
 661                  $result = _sql($sql, $errored, $error_ary);
 662  
 663                  $mod_user = array();
 664                  while ($row = $db->sql_fetchrow($result))
 665                  {
 666                          $mod_user[] = $row['user_id'];
 667                  }
 668                  $db->sql_freeresult($result);
 669  
 670                  if (count($mod_user))
 671                  {
 672                          $sql = "UPDATE " . USERS_TABLE . "
 673                                  SET user_level = " . MOD . "
 674                                  WHERE user_id IN (" . implode(', ', $mod_user) . ")";
 675                          _sql($sql, $errored, $error_ary);
 676                  }
 677  
 678                  $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
 679                          VALUES ('server_name', 'www.myserver.tld')";
 680                  _sql($sql, $errored, $error_ary);
 681  
 682                  $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
 683                          VALUES ('script_path', '/phpBB2/')";
 684                  _sql($sql, $errored, $error_ary);
 685  
 686                  $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
 687                          VALUES ('server_port', '80')";
 688                  _sql($sql, $errored, $error_ary);
 689  
 690                  $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
 691                          VALUES ('record_online_users', '1')";
 692                  _sql($sql, $errored, $error_ary);
 693  
 694                  $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
 695                          VALUES ('record_online_date', '" . time() . "')";
 696                  _sql($sql, $errored, $error_ary);
 697  
 698          case 'RC-3':
 699          case 'RC-4':
 700          case '.0.0':
 701          case '.0.1':
 702                  if (SQL_LAYER == 'postgresql')
 703                  {
 704                          $sql = "SELECT user_id, user_timezone_old
 705                                  FROM " . USERS_TABLE;
 706                          $result = _sql($sql, $errored, $error_ary);
 707  
 708                          while ($row = $db->sql_fetchrow($result))
 709                          {
 710                                  $sql = "UPDATE " . USERS_TABLE . "
 711                                          SET user_timezone = " . $row['user_timezone_old'] . "
 712                                          WHERE user_id = " . $row['user_id'];
 713                                  _sql($sql, $errored, $error_ary);
 714                          }
 715                          $db->sql_freeresult($result);
 716                  }
 717  
 718                  $sql = "SELECT topic_id, topic_moved_id
 719                          FROM " . TOPICS_TABLE . "
 720                          WHERE topic_moved_id <> 0
 721                                  AND topic_status = " . TOPIC_MOVED;
 722                  $result = _sql($sql, $errored, $error_ary);
 723  
 724                  $topic_ary = array();
 725                  while ($row = $db->sql_fetchrow($result))
 726                  {
 727                          $topic_ary[$row['topic_id']] = $row['topic_moved_id'];
 728                  }
 729                  $db->sql_freeresult($result);
 730  
 731                  while (list($topic_id, $topic_moved_id) = each($topic_ary))
 732                  {
 733                          $sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts
 734                                  FROM " . POSTS_TABLE . "
 735                                  WHERE topic_id = $topic_moved_id";
 736                          $result = _sql($sql, $errored, $error_ary);
 737  
 738                          $sql = ($row = $db->sql_fetchrow($result)) ? "UPDATE " . TOPICS_TABLE . "        SET topic_replies = " . ($row['total_posts'] - 1) . ", topic_first_post_id = " . $row['first_post'] . ", topic_last_post_id = " . $row['last_post'] . " WHERE topic_id = $topic_id" : "DELETE FROM " . TOPICS_TABLE . " WHERE topic_id = " . $row['topic_id'];
 739                          _sql($sql, $errored, $error_ary);
 740                  }
 741  
 742                  unset($sql);
 743  
 744                  sync('all forums');
 745  
 746          case '.0.2':
 747  
 748          case '.0.3':
 749  
 750                  // Topics will resync automatically
 751  
 752                  // Remove stop words from search match and search words
 753                  $dirname = 'language';
 754                  $dir = opendir($phpbb_root_path . $dirname);
 755  
 756                  while ($file = readdir($dir))
 757                  {
 758                          if (preg_match("#^lang_#i", $file) && !is_file($phpbb_root_path . $dirname . "/" . $file) && !is_link($phpbb_root_path . $dirname . "/" . $file) && file_exists($phpbb_root_path . $dirname . "/" . $file . '/search_stopwords.txt'))
 759                          {
 760  
 761                                  $stopword_list = trim(preg_replace('#([\w\.\-_\+\'±µ-ÿ\\\]+?)[ \n\r]*?(,|$)#', '\'\1\'\2', str_replace("'", "\'", implode(', ', file($phpbb_root_path . $dirname . "/" . $file . '/search_stopwords.txt')))));
 762  
 763                                  $sql = "SELECT word_id
 764                                          FROM " . SEARCH_WORD_TABLE . "
 765                                          WHERE word_text IN ($stopword_list)";
 766                                  $result = _sql($sql, $errored, $error_ary);
 767  
 768                                  $word_id_sql = '';
 769                                  if ($row = $db->sql_fetchrow($result))
 770                                  {
 771                                          do
 772                                          {
 773                                                  $word_id_sql .= (($word_id_sql != '') ? ', ' : '') . $row['word_id'];
 774                                          }
 775                                          while ($row = $db->sql_fetchrow($result));
 776  
 777                                          $sql = "DELETE FROM " . SEARCH_WORD_TABLE . "
 778                                                  WHERE word_id IN ($word_id_sql)";
 779                                          _sql($sql, $errored, $error_ary);
 780  
 781                                          $sql = "DELETE FROM " . SEARCH_MATCH_TABLE . "
 782                                                  WHERE word_id IN ($word_id_sql)";
 783                                          _sql($sql, $errored, $error_ary);
 784                                  }
 785                                  $db->sql_freeresult($result);
 786                          }
 787                  }
 788                  closedir($dir);
 789  
 790                  // Mark common words ...
 791                  remove_common('global', 4/10);
 792  
 793                  // remove superfluous polls ... grab polls with topics then delete polls
 794                  // not in that list
 795                  $sql = "SELECT v.vote_id
 796                          FROM " . TOPICS_TABLE . " t, " . VOTE_DESC_TABLE . " v
 797                          WHERE v.topic_id = t.topic_id";
 798                  $result = _sql($sql, $errored, $error_ary);
 799  
 800                  $vote_id_sql = '';
 801                  if ($row = $db->sql_fetchrow($result))
 802                  {
 803                          do
 804                          {
 805                                  $vote_id_sql .= (($vote_id_sql != '') ? ', ' : '') . $row['vote_id'];
 806                          }
 807                          while ($row = $db->sql_fetchrow($result));
 808  
 809                          $sql = "DELETE FROM " . VOTE_DESC_TABLE . "
 810                                  WHERE vote_id NOT IN ($vote_id_sql)";
 811                          _sql($sql, $errored, $error_ary);
 812  
 813                          $sql = "DELETE FROM " . VOTE_RESULTS_TABLE . "
 814                                  WHERE vote_id NOT IN ($vote_id_sql)";
 815                          _sql($sql, $errored, $error_ary);
 816  
 817                          $sql = "DELETE FROM " . VOTE_USERS_TABLE . "
 818                                  WHERE vote_id NOT IN ($vote_id_sql)";
 819                          _sql($sql, $errored, $error_ary);
 820                  }
 821                  $db->sql_freeresult($result);
 822  
 823                  // update pm counters
 824                  $sql = "SELECT privmsgs_to_userid, COUNT(privmsgs_id) AS unread_count
 825                          FROM " . PRIVMSGS_TABLE . "
 826                          WHERE privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . "
 827                          GROUP BY privmsgs_to_userid";
 828                  $result = _sql($sql, $errored, $error_ary);
 829  
 830                  if ($row = $db->sql_fetchrow($result))
 831                  {
 832                          $update_users = array();
 833                          do
 834                          {
 835                                  $update_users[$row['unread_count']][] = $row['privmsgs_to_userid'];
 836                          }
 837                          while ($row = $db->sql_fetchrow($result));
 838  
 839                          while (list($num, $user_ary) = each($update_users))
 840                          {
 841                                  $user_ids = implode(', ', $user_ary);
 842  
 843                                  $sql = "UPDATE " . USERS_TABLE . "
 844                                          SET user_unread_privmsg = $num
 845                                          WHERE user_id IN ($user_ids)";
 846                                  _sql($sql, $errored, $error_ary);
 847                          }
 848                          unset($update_list);
 849                  }
 850                  $db->sql_freeresult($result);
 851  
 852                  $sql = "SELECT privmsgs_to_userid, COUNT(privmsgs_id) AS new_count
 853                          FROM " . PRIVMSGS_TABLE . "
 854                          WHERE privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
 855                          GROUP BY privmsgs_to_userid";
 856                  $result = _sql($sql, $errored, $error_ary);
 857  
 858                  if ($row = $db->sql_fetchrow($result))
 859                  {
 860                          $update_users = array();
 861                          do
 862                          {
 863                                  $update_users[$row['new_count']][] = $row['privmsgs_to_userid'];
 864                          }
 865                          while ($row = $db->sql_fetchrow($result));
 866  
 867                          while (list($num, $user_ary) = each($update_users))
 868                          {
 869                                  $user_ids = implode(', ', $user_ary);
 870  
 871                                  $sql = "UPDATE " . USERS_TABLE . "
 872                                          SET user_new_privmsg = $num
 873                                          WHERE user_id IN ($user_ids)";
 874                                  _sql($sql, $errored, $error_ary);
 875                          }
 876                          unset($update_list);
 877                  }
 878                  $db->sql_freeresult($result);
 879  
 880                  // Remove superfluous watched topics
 881                  $sql = "SELECT t.topic_id
 882                          FROM " . TOPICS_TABLE . " t, " . TOPICS_WATCH_TABLE . " w
 883                          WHERE w.topic_id = t.topic_id";
 884                  $result = _sql($sql, $errored, $error_ary);
 885  
 886                  $topic_id_sql = '';
 887                  if ($row = $db->sql_fetchrow($result))
 888                  {
 889                          do
 890                          {
 891                                  $topic_id_sql .= (($topic_id_sql != '') ? ', ' : '') . $row['topic_id'];
 892                          }
 893                          while ($row = $db->sql_fetchrow($result));
 894  
 895                          $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
 896                                  WHERE topic_id NOT IN ($topic_id_sql)";
 897                          _sql($sql, $errored, $error_ary);
 898                  }
 899                  $db->sql_freeresult($result);
 900  
 901                  // Reset any email addresses which are non-compliant ... something
 902                  // not done in the upgrade script and thus which may affect some
 903                  // mysql users
 904                  switch (SQL_LAYER)
 905                  {
 906                          case 'mysql':
 907                                  $sql = "UPDATE " . USERS_TABLE . "
 908                                          SET user_email = ''
 909                                          WHERE user_email NOT REGEXP '^[a-zA-Z0-9_\+\.\-]+@.*[a-zA-Z0-9_\-]+\.[a-zA-Z]{2,}$'";
 910                                  _sql($sql, $errored, $error_ary);
 911                  }
 912  
 913          case '.0.4':
 914  
 915                  // Add the confirmation code switch ... save time and trouble elsewhere
 916                  $sql = 'INSERT INTO ' . CONFIG_TABLE . " (config_name, config_value)
 917                          VALUES ('enable_confirm', '0')";
 918                  _sql($sql, $errored, $error_ary);
 919  
 920                  $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
 921                          VALUES ('sendmail_fix', '0')";
 922                  _sql($sql, $errored, $error_ary);
 923  
 924                  break;
 925  
 926          default:
 927                  echo " No updates where required</b></p>\n";
 928                  break;
 929  }
 930  
 931  echo "<h2>Updating version and optimizing tables</h2>\n";
 932  echo "<p>Progress :: <b>";
 933  flush();
 934  
 935  // update the version
 936  $sql = "UPDATE " . CONFIG_TABLE . "
 937          SET config_value = '$updates_to_version'
 938          WHERE config_name = 'version'";
 939  _sql($sql, $errored, $error_ary);
 940  
 941  // Optimize/vacuum analyze the tables where appropriate
 942  // this should be done for each version in future along with
 943  // the version number update
 944  switch (SQL_LAYER)
 945  {
 946          case 'mysql':
 947          case 'mysql4':
 948                  $sql = 'OPTIMIZE TABLE ' . $table_prefix . 'auth_access, ' . $table_prefix . 'banlist, ' . $table_prefix . 'categories, ' . $table_prefix . 'config, ' . $table_prefix . 'disallow, ' . $table_prefix . 'forum_prune, ' . $table_prefix . 'forums, ' . $table_prefix . 'groups, ' . $table_prefix . 'posts, ' . $table_prefix . 'posts_text, ' . $table_prefix . 'privmsgs, ' . $table_prefix . 'privmsgs_text, ' . $table_prefix . 'ranks, ' . $table_prefix . 'search_results, ' . $table_prefix . 'search_wordlist, ' . $table_prefix . 'search_wordmatch, ' . $table_prefix . 'smilies, ' . $table_prefix . 'themes, ' . $table_prefix . 'themes_name, ' . $table_prefix . 'topics, ' . $table_prefix . 'topics_watch, ' . $table_prefix . 'user_group, ' . $table_prefix . 'users, ' . $table_prefix . 'vote_desc, ' . $table_prefix . 'vote_results, ' . $table_prefix . 'vote_voters, ' . $table_prefix . 'words';
 949                  _sql($sql, $errored, $error_ary);
 950                  break;
 951  
 952          case 'postgresql':
 953                  _sql("VACUUM ANALYZE", $errored, $error_ary);
 954                  break;
 955  }
 956  
 957  echo "</b> <b class=\"ok\">Done</b><br />Result &nbsp; :: \n";
 958  
 959  if ($errored)
 960  {
 961          echo " <b>Some queries failed, the statements and errors are listing below</b>\n<ul>";
 962  
 963          for ($i = 0; $i < count($error_ary['sql']); $i++)
 964          {
 965                  echo "<li>Error :: <b>" . $error_ary['error_code'][$i]['message'] . "</b><br />";
 966                  echo "SQL &nbsp; :: <b>" . $error_ary['sql'][$i] . "</b><br /><br /></li>";
 967          }
 968  
 969          echo "</ul>\n<p>This is probably nothing to worry about, update will continue. Should this fail to complete you may need to seek help at our development board. See <a href=\"docs\README.html\">README</a> for details on how to obtain advice.</p>\n";
 970  }
 971  else
 972  {
 973          echo "<b>No errors</b>\n";
 974  }
 975  
 976  echo "<h2>Update completed</h2>\n";
 977  echo "\n<p>You should now visit the General Configuration settings page in the <a href=\"modules/Forums/admin/index.php?admin=1\">Administration Panel</a> and check the General Configuration of the board. If you updated from versions prior to RC-3 you <b>must</b> update some entries. If you do not do this emails sent from the board will contain incorrect information.<br><br><center><b>Don't forget to delete this file!!!</b><br><i>(/modules/Forums/update_to_205.php)</i></center></p>\n";
 978  
 979  ?>
 980  
 981  <br clear="all" />
 982  
 983  </body>
 984  </html>


Généré le : Sun Apr 1 11:11:59 2007 par Balluche grâce à PHPXref 0.7