Verzeichnisstruktur phpBB-2.0.0


Veröffentlicht
03.04.2002

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

update_to_latest.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 45.84 KiB


0001  <?php
0002  /***************************************************************************
0003   *                             update_to_xxx.php
0004   *                            -------------------
0005   *   begin                : Wednesday, May 16, 2002
0006   *   copyright            : (C) 2001 The phpBB Group
0007   *   email                : support@phpbb.com
0008   *
0009   *   $Id$
0010   *
0011   ***************************************************************************/
0012   
0013  /***************************************************************************
0014   *
0015   *   This program is free software; you can redistribute it and/or modify
0016   *   it under the terms of the GNU General Public License as published by
0017   *   the Free Software Foundation; either version 2 of the License, or
0018   *   (at your option) any later version.
0019   *
0020   ***************************************************************************/
0021   
0022  function _sql($sql, &$errored, &$error_ary, $echo_dot = true)
0023  {
0024      global $db;
0025   
0026      if (!($result = $db->sql_query($sql)))
0027      {
0028          $errored = true;
0029          $error_ary['sql'][] = (is_array($sql)) ? $sql[$i] : $sql;
0030          $error_ary['error_code'][] = $db->sql_error();
0031      }
0032   
0033      if ($echo_dot)
0034      {
0035          echo ". \n";
0036          flush();
0037      }
0038   
0039      return $result;
0040  }
0041   
0042  @set_time_limit(120);
0043   
0044  define('IN_PHPBB', 1);
0045  $phpbb_root_path = './../';
0046  include($phpbb_root_path . 'extension.inc');
0047  include($phpbb_root_path . 'config.'.$phpEx);
0048  if(!isset($dbms))
0049  {
0050      die("Please read: <a href='../docs/INSTALL.html'>INSTALL.html</a> before attempting to update.");
0051  }
0052  include($phpbb_root_path . 'includes/constants.'.$phpEx);
0053  include($phpbb_root_path . 'includes/functions.'.$phpEx);
0054  include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
0055  include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
0056  include($phpbb_root_path . 'includes/db.'.$phpEx);
0057   
0058   
0059  //
0060  //
0061  //
0062  $updates_to_version = '.0.24';
0063  //
0064  //
0065  //
0066   
0067  ?>
0068  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
0069  <html>
0070  <head>
0071  <meta http-equiv="Content-Type" content="text/html;">
0072  <meta http-equiv="Content-Style-Type" content="text/css">
0073  <style type="text/css">
0074  <!--
0075   
0076  font,th,td,p,body { font-family: "Courier New", courier; font-size: 11pt }
0077   
0078  a:link,a:active,a:visited { color : #006699; }
0079  a:hover        { text-decoration: underline; color : #DD6900;}
0080   
0081  hr    { height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;}
0082   
0083  .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;}
0084   
0085  .ok {color:green}
0086   
0087  /* Import the fancy styles for IE only (NS4.x doesn't use the @import function) */
0088  @import url("../templates/subSilver/formIE.css");
0089  -->
0090  </style>
0091  </head>
0092  <body bgcolor="#FFFFFF" text="#000000" link="#006699" vlink="#5584AA">
0093   
0094  <table width="100%" border="0" cellspacing="0" cellpadding="10" align="center">
0095      <tr>
0096          <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
0097              <tr>
0098                  <td><img src="../templates/subSilver/images/logo_phpBB.gif" border="0" alt="Forum Home" vspace="1" /></td>
0099                  <td align="center" width="100%" valign="middle"><span class="maintitle">Updating to latest stable release</span></td>
0100              </tr>
0101          </table></td>
0102      </tr>
0103  </table>
0104   
0105  <br clear="all" />
0106   
0107  <h2>Information</h2>
0108   
0109  <?php
0110   
0111  echo '<p>Database type &nbsp; &nbsp;:: <b>' . SQL_LAYER . '</b><br />';
0112   
0113  $sql = "SELECT config_value
0114      FROM " . CONFIG_TABLE . "
0115      WHERE config_name = 'version'";
0116  if (!($result = $db->sql_query($sql)))
0117  {
0118      die("Couldn't obtain version info");
0119  }
0120   
0121  $row = $db->sql_fetchrow($result);
0122   
0123  $sql = array();
0124   
0125  switch ($row['config_value'])
0126  {
0127      case '':
0128          echo 'Previous version :: <b>&lt; RC-3</b></p><br />';
0129          break;
0130      case 'RC-3':
0131          echo 'Previous version :: <b>RC-3</b></p><br />';
0132          break;
0133      case 'RC-4':
0134          echo 'Previous version :: <b>RC-4</b></p><br />';
0135          break;
0136      default:
0137          echo 'Previous version :: <b>2' . $row['config_value'] . '</b><br />';
0138          break;
0139  }
0140   
0141  echo 'Updated version &nbsp;:: <b>2' . $updates_to_version . '</b></p>' ."\n";
0142   
0143  //
0144  // Schema updates
0145  //
0146  switch ($row['config_value'])
0147  {
0148      case '':
0149          switch (SQL_LAYER)
0150          {
0151              case 'mysql':
0152              case 'mysql4':
0153                  $sql[] = "ALTER TABLE " . USERS_TABLE . " DROP
0154                      COLUMN user_autologin_key";
0155   
0156                  $sql[] = "ALTER TABLE " . RANKS_TABLE . " DROP
0157                      COLUMN rank_max";
0158   
0159                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0160                      ADD COLUMN user_session_time int(11) DEFAULT '0' NOT NULL,
0161                      ADD COLUMN user_session_page smallint(5) DEFAULT '0' NOT NULL,
0162                      ADD INDEX (user_session_time)";
0163                  $sql[] = "ALTER TABLE " . SEARCH_TABLE . "
0164                      MODIFY search_id int(11) NOT NULL";
0165   
0166                  $sql[] = "ALTER TABLE " . TOPICS_TABLE . "
0167                      MODIFY topic_moved_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
0168                      ADD COLUMN topic_first_post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
0169                      ADD INDEX (topic_first_post_id)";
0170   
0171                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
0172                      ADD COLUMN tr_class1_name varchar(50) NULL,
0173                      ADD COLUMN tr_class2_name varchar(50) NULL,
0174                      ADD COLUMN tr_class3_name varchar(50) NULL,
0175                      ADD COLUMN th_class1_name varchar(50) NULL,
0176                      ADD COLUMN th_class2_name varchar(50) NULL,
0177                      ADD COLUMN th_class3_name varchar(50) NULL,
0178                      ADD COLUMN td_class1_name varchar(50) NULL,
0179                      ADD COLUMN td_class2_name varchar(50) NULL,
0180                      ADD COLUMN td_class3_name varchar(50) NULL,
0181                      ADD COLUMN span_class1_name varchar(50) NULL,
0182                      ADD COLUMN span_class2_name varchar(50) NULL,
0183                      ADD COLUMN span_class3_name varchar(50) NULL";
0184                  break;
0185              case 'postgresql':
0186                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0187                      ADD COLUMN user_session_time int4";
0188                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0189                      ADD COLUMN user_session_page int2";
0190                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0191                      ALTER COLUMN user_session_time SET DEFAULT '0'";
0192                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0193                      ALTER COLUMN user_session_page SET DEFAULT '0'";
0194                  $sql[] = "CREATE INDEX user_session_time_" . $table_prefix . "users_index
0195                      ON " . USERS_TABLE . " (user_session_time)";
0196   
0197                  $sql[] = "ALTER TABLE " . TOPICS_TABLE . "
0198                      ADD COLUMN topic_first_post_id int4";
0199                  $sql[] = "CREATE INDEX topic_first_post_id_" . $table_prefix . "topics_index
0200                      ON " . TOPICS_TABLE . " (topic_first_post_id)";
0201   
0202                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
0203                      ADD COLUMN tr_class1_name varchar(50) NULL";
0204                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
0205                      ADD COLUMN tr_class2_name varchar(50) NULL";
0206                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
0207                      ADD COLUMN tr_class3_name varchar(50) NULL";
0208                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
0209                      ADD COLUMN th_class1_name varchar(50) NULL";
0210                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
0211                      ADD COLUMN th_class2_name varchar(50) NULL";
0212                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
0213                      ADD COLUMN th_class3_name varchar(50) NULL";
0214                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
0215                      ADD COLUMN td_class1_name varchar(50) NULL";
0216                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
0217                      ADD COLUMN td_class2_name varchar(50) NULL";
0218                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
0219                      ADD COLUMN td_class3_name varchar(50) NULL";
0220                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
0221                      ADD COLUMN span_class1_name varchar(50) NULL";
0222                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
0223                      ADD COLUMN span_class2_name varchar(50) NULL";
0224                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . "
0225                      ADD COLUMN span_class3_name varchar(50) NULL";
0226                  break;
0227   
0228              case 'mssql-odbc':
0229              case 'mssql':
0230                  $sql[] = "ALTER TABLE " . USERS_TABLE . " DROP
0231                      COLUMN user_autologin_key";
0232   
0233                  $sql[] = "ALTER TABLE " . USERS_TABLE . " ADD
0234                      user_session_time int NOT NULL,
0235                      user_session_page smallint NOT NULL,
0236                      CONSTRAINT [DF_" . $table_prefix . "users_user_session_time] DEFAULT (0) FOR [user_session_time],
0237                      CONSTRAINT [DF_" . $table_prefix . "users_user_session_page] DEFAULT (0) FOR [user_session_page]";
0238                  $sql[] = "CREATE INDEX [IX_" . $table_prefix . "users]
0239                      ON [" . USERS_TABLE . "]([user_session_time]) ON [PRIMARY]";
0240   
0241                  /* ---------------------------------------------------------------------
0242                      DROP FORUM TABLE -- if this may cause you problems you can safely
0243                      comment it out, remember to manually remove the IDENTITY setting on
0244                      the forum_id column
0245                     --------------------------------------------------------------------- */
0246                  $sql [] = "ALTER TABLE " . FORUMS_TABLE . " DROP
0247                      CONSTRAINT [DF_" . $table_prefix . "forums_forum_posts],
0248                      CONSTRAINT [DF_" . $table_prefix . "forums_forum_topics],
0249                      CONSTRAINT [DF_" . $table_prefix . "forums_forum_last_post_id],
0250                      CONSTRAINT [DF_" . $table_prefix . "forums_prune_enable],
0251                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_view],
0252                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_read],
0253                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_post],
0254                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_reply],
0255                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_edit],
0256                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_delete],
0257                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_sticky],
0258                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_announce],
0259                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_vote],
0260                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_pollcreate],
0261                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_attachments]";
0262                  $sql[] = "CREATE TABLE Tmp_" . FORUMS_TABLE . "
0263                      (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]";
0264                  $sql[] = "ALTER TABLE [Tmp_" . FORUMS_TABLE . "] WITH NOCHECK ADD
0265                      CONSTRAINT [DF_" . $table_prefix . "forums_forum_posts] DEFAULT (0) FOR [forum_posts],
0266                      CONSTRAINT [DF_" . $table_prefix . "forums_forum_topics] DEFAULT (0) FOR [forum_topics],
0267                      CONSTRAINT [DF_" . $table_prefix . "forums_forum_last_post_id] DEFAULT (0) FOR [forum_last_post_id],
0268                      CONSTRAINT [DF_" . $table_prefix . "forums_prune_enable] DEFAULT (0) FOR [prune_enable],
0269                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_view] DEFAULT (0) FOR [auth_view],
0270                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_read] DEFAULT (0) FOR [auth_read],
0271                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_post] DEFAULT (0) FOR [auth_post],
0272                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_reply] DEFAULT (0) FOR [auth_reply],
0273                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_edit] DEFAULT (0) FOR [auth_edit],
0274                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_delete] DEFAULT (0) FOR [auth_delete],
0275                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_sticky] DEFAULT (0) FOR [auth_sticky],
0276                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_announce] DEFAULT (0) FOR [auth_announce],
0277                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_vote] DEFAULT (0) FOR [auth_vote],
0278                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_pollcreate] DEFAULT (0) FOR [auth_pollcreate],
0279                      CONSTRAINT [DF_" . $table_prefix . "forums_auth_attachments] DEFAULT (0) FOR [auth_attachments]";
0280                  $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)
0281                          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";
0282                  $sql[] = "DROP TABLE " . FORUMS_TABLE;
0283                  $sql[] = "EXECUTE sp_rename N'Tmp_" . FORUMS_TABLE . "', N'" . FORUMS_TABLE . "', 'OBJECT'";
0284                  $sql[] = "ALTER TABLE " . FORUMS_TABLE . " ADD
0285                      CONSTRAINT [PK_" . $table_prefix . "forums] PRIMARY KEY CLUSTERED (forum_id) ON [PRIMARY]";
0286                  $sql[] = "CREATE NONCLUSTERED INDEX [IX_" . $table_prefix . "forums]
0287                      ON " . FORUMS_TABLE . " (cat_id, forum_order, forum_last_post_id) ON [PRIMARY]";
0288                  /* --------------------------------------------------------------
0289                      END OF DROP FORUM -- don't remove anything after this point!
0290                     -------------------------------------------------------------- */
0291   
0292                  $sql[] = "DROP INDEX " . RANKS_TABLE . ".IX_" . $table_prefix . "ranks";
0293                  $sql[] = "ALTER TABLE " . RANKS_TABLE . " DROP
0294                      COLUMN rank_max";
0295                  $sql[] = "CREATE  INDEX [IX_" . $table_prefix . "ranks]
0296                      ON [" . RANKS_TABLE . "]([rank_min], [rank_special]) ON [PRIMARY]";
0297   
0298                  $sql[] = "DROP INDEX " . TOPICS_TABLE . ".IX_" . $table_prefix . "topics";
0299                  $sql[] = "ALTER TABLE " . TOPICS_TABLE . " ADD
0300                      topic_first_post_id int NULL,
0301                      CONSTRAINT [DF_" . $table_prefix . "topics_topic_first_post_id] FOR [topic_first_post_id]";
0302                  $sql[] = "CREATE  INDEX [IX_" . $table_prefix . "topics]
0303                      ON [" . TOPICS_TABLE . "]([forum_id], [topic_type], [topic_first_post_id], [topic_last_post_id]) ON [PRIMARY]";
0304   
0305                  $sql[] = "ALTER TABLE " . SEARCH_WORD_TABLE . " DROP
0306                      CONSTRAINT [PK_" . $table_prefix . "search_wordlist]";
0307                  $sql[] = "CREATE UNIQUE INDEX [IX_" . $table_prefix . "search_wordlist]
0308                      ON [" . SEARCH_WORD_TABLE . "]([word_text]) WITH IGNORE_DUP_KEY ON [PRIMARY]";
0309                  $sql[] = "CREATE  INDEX [IX_" . $table_prefix . "search_wordlist_1]
0310                      ON [" . SEARCH_WORD_TABLE . "]([word_common]) ON [PRIMARY]";
0311   
0312                  $sql[] = "CREATE INDEX [IX_" . $table_prefix . "search_wordmatch_1]
0313                      ON [" . SEARCH_MATCH_TABLE . "]([word_id]) ON [PRIMARY]";
0314   
0315                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . " ADD
0316                      tr_class1_name varchar(50) NULL,
0317                      tr_class2_name varchar(50) NULL,
0318                      tr_class3_name varchar(50) NULL,
0319                      th_class1_name varchar(50) NULL,
0320                      th_class2_name varchar(50) NULL,
0321                      th_class3_name varchar(50) NULL,
0322                      td_class1_name varchar(50) NULL,
0323                      td_class2_name varchar(50) NULL,
0324                      td_class3_name varchar(50) NULL,
0325                      span_class1_name varchar(50) NULL,
0326                      span_class2_name varchar(50) NULL,
0327                      span_class3_name varchar(50) NULL";
0328                  break;
0329   
0330              case 'msaccess':
0331                  $sql[] = "ALTER TABLE " . USERS_TABLE . " DROP
0332                      COLUMN user_autologin_key";
0333   
0334                  $sql[] = "ALTER TABLE " . USERS_TABLE . " ADD
0335                      user_session_time int NOT NULL,
0336                      user_session_page smallint NOT NULL";
0337                  $sql[] = "CREATE INDEX user_session_time
0338                      ON " . USERS_TABLE . " (user_session_time)";
0339   
0340                  $sql[] = "ALTER TABLE " . TOPICS_TABLE . " ADD
0341                      topic_first_post_id int NULL";
0342                  $sql[] = "CREATE INDEX topic_first_post_id
0343                      ON " . TOPICS_TABLE . " (topic_first_post_id)";
0344   
0345                  $sql[] = "ALTER TABLE " . THEMES_NAME_TABLE . " ADD
0346                      tr_class1_name varchar(50) NULL,
0347                      tr_class2_name varchar(50) NULL,
0348                      tr_class3_name varchar(50) NULL,
0349                      th_class1_name varchar(50) NULL,
0350                      th_class2_name varchar(50) NULL,
0351                      th_class3_name varchar(50) NULL,
0352                      td_class1_name varchar(50) NULL,
0353                      td_class2_name varchar(50) NULL,
0354                      td_class3_name varchar(50) NULL,
0355                      span_class1_name varchar(50) NULL,
0356                      span_class2_name varchar(50) NULL,
0357                      span_class3_name varchar(50) NULL";
0358                  break;
0359   
0360              default:
0361                  die("No DB LAYER found!");
0362                  break;
0363          }
0364   
0365      case 'RC-3':
0366      case 'RC-4':
0367      case '.0.0':
0368          switch (SQL_LAYER)
0369          {
0370              case 'mysql':
0371              case 'mysql4':
0372                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0373                      MODIFY COLUMN user_id  mediumint(8) NOT NULL,
0374                      MODIFY COLUMN user_timezone decimal(5,2) DEFAULT '0' NOT NULL";
0375                  break;
0376              case 'postgresql':
0377                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0378                      RENAME COLUMN user_timezone TO user_timezone_old";
0379                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0380                      ADD COLUMN user_timezone decimal(5)";
0381                  break;
0382              case 'mssql':
0383              case 'mssql-odbc':
0384                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0385                      ALTER COLUMN [user_timezone] [decimal] (5,2) NOT NULL";
0386                  break;
0387          }
0388   
0389      case '.0.1':
0390          switch (SQL_LAYER)
0391          {
0392              case 'mysql':
0393              case 'mysql4':
0394                  $sql[] = "ALTER TABLE " . GROUPS_TABLE . "
0395                      MODIFY COLUMN group_id mediumint(8) NOT NULL auto_increment";
0396                  break;
0397              case 'mssql':
0398              case 'mssql-odbc':
0399                  /* ---------------------------------------------------------------------
0400                      DROP GROUP TABLE -- if this may cause you problems you can safely
0401                      comment it out, remember to manually add the IDENTITY setting on
0402                      the group_id column
0403                     --------------------------------------------------------------------- */
0404                  $sql[] = "CREATE TABLE Tmp_" . GROUPS_TABLE . "
0405                      (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]";
0406                  $sql[] = "SET IDENTITY_INSERT " . GROUPS_TABLE . " ON";
0407                  $sql[] = "INSERT INTO Tmp_" . GROUPS_TABLE . " (group_id, group_type, group_name, group_description, group_moderator, group_single_user)
0408                      SELECT group_id, group_type, group_name, group_description, group_moderator, group_single_user FROM " . GROUPS_TABLE . " TABLOCKX";
0409                  $sql[] = "SET IDENTITY_INSERT " . GROUPS_TABLE . " OFF";
0410                  $sql[] = "DROP TABLE " . GROUPS_TABLE;
0411                  $sql[] = "EXECUTE sp_rename N'Tmp_" . GROUPS_TABLE . "', N'" . GROUPS_TABLE . "', 'OBJECT'";
0412                  $sql[] = "ALTER TABLE " . GROUPS_TABLE . " ADD
0413                      CONSTRAINT [PK_" . $table_prefix . "groups] PRIMARY KEY CLUSTERED (group_id) ON [PRIMARY]";
0414                  $sql[] = "CREATE INDEX [IX_" . $table_prefix . "groups]
0415                      ON " . GROUPS_TABLE . " (group_single_user) ON [PRIMARY]";
0416                  /* --------------------------------------------------------------
0417                      END OF DROP GROUP -- don't remove anything after this point!
0418                     -------------------------------------------------------------- */
0419                  break;
0420              
0421          }
0422   
0423      case '.0.2':
0424   
0425      case '.0.3':
0426   
0427          switch (SQL_LAYER)
0428          {
0429              case 'mysql':
0430              case 'mysql4':
0431                  // Add indexes to post_id in search match table (+ word_id for MS Access)
0432                  $sql[] = "ALTER TABLE " . SEARCH_MATCH_TABLE . 
0433                      ADD INDEX post_id (post_id)";
0434   
0435                  // Modify user_timezone to decimal(5,2) for mysql ... mysql4/mssql/pgsql/msaccess
0436                  // should be completely unaffected
0437                  // Change default user_notify to 0 
0438                  $sql[] = "ALTER TABLE " . USERS_TABLE . 
0439                      MODIFY COLUMN user_timezone decimal(5,2) DEFAULT '0' NOT NULL, 
0440                      MODIFY COLUMN user_notify tinyint(1) DEFAULT '0' NOT NULL";
0441   
0442                  // Adjust field type for prune_days, prune_freq ... was too small
0443                  $sql[] = "ALTER TABLE " . PRUNE_TABLE . 
0444                      MODIFY COLUMN prune_days smallint(5) UNSIGNED NOT NULL, 
0445                      MODIFY COLUMN prune_freq smallint(5) UNSIGNED NOT NULL";
0446                  break;
0447   
0448              case 'msaccess':
0449                  // Add indexes to post_id in search match table (+ word_id for MS Access)
0450                  $sql[] = "CREATE INDEX " . SEARCH_MATCH_TABLE . 
0451                      ON " . SEARCH_MATCH_TABLE . " ([post_id])";
0452                  $sql[] = "CREATE INDEX " . SEARCH_MATCH_TABLE . "_1 
0453                      ON " . SEARCH_MATCH_TABLE . " ([word_id])";
0454                  break;
0455   
0456              case 'postgresql':
0457                  // Add indexes to post_id in search match table (+ word_id for MS Access)
0458                  $sql[] = "CREATE INDEX post_id_" . SEARCH_MATCH_TABLE . 
0459                      ON " . SEARCH_MATCH_TABLE . " (post_id)";
0460   
0461                  // Regenerate groups table with incremented group_id for pgsql 
0462                  // ... missing in 2.0.3 ...
0463                  $sql[] = "CREATE SEQUENCE " . GROUPS_TABLE . "_id_seq start 3 increment 1 maxvalue 2147483647 minvalue 1 cache 1";
0464                  $sql[] = "CREATE TABLE tmp_" . GROUPS_TABLE . 
0465                      AS SELECT group_id, group_name, group_type, group_description, group_moderator, group_single_user 
0466                          FROM " . GROUPS_TABLE;
0467                  $sql[] = "DROP TABLE " . GROUPS_TABLE;
0468                  $sql[] = "CREATE TABLE {$table_prefix}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 {$table_prefix}groups_pkey PRIMARY KEY (group_id))";
0469                  $sql[] = "INSERT INTO " . GROUPS_TABLE . " (group_id, group_name, group_type, group_description, group_moderator, group_single_user) 
0470                      SELECT group_id, group_name, group_type, group_description, group_moderator, group_single_user 
0471                          FROM tmp_" . GROUPS_TABLE;
0472                  $sql[] = "DROP TABLE tmp_" . GROUPS_TABLE;
0473                  break;
0474          }
0475   
0476      case '.0.4':
0477   
0478          switch (SQL_LAYER)
0479          {
0480              case 'mssql':
0481              case 'mssql-odbc':
0482                  // Add missing defaults to MSSQL post table schema, failed in previous updates
0483                  $sql[] = "ALTER TABLE [" . POSTS_TABLE . "] WITH NOCHECK ADD
0484                      CONSTRAINT [DF_" . POSTS_TABLE . "_enable_bbcode] DEFAULT (1) FOR [enable_bbcode],
0485                      CONSTRAINT [DF_" . POSTS_TABLE . "_enable_html] DEFAULT (0) FOR [enable_html],
0486                      CONSTRAINT [DF_" . POSTS_TABLE . "_enable_smilies] DEFAULT (1) FOR [enable_smilies],
0487                      CONSTRAINT [DF_" . POSTS_TABLE . "_enable_sig] DEFAULT (1) FOR [enable_sig],
0488                      CONSTRAINT [DF_" . POSTS_TABLE . "_post_edit_count] DEFAULT (0) FOR [post_edit_count]";
0489                  break;
0490          }
0491   
0492          // Add tables for visual confirmation ... saves me the trouble of writing a seperate
0493          // script :D
0494          switch (SQL_LAYER)
0495          {
0496              case 'mysql':
0497              case 'mysql4':
0498                  $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))';
0499                  break;
0500   
0501              case 'mssql':
0502              case 'mssql-odbc':
0503                  $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]';
0504                  $sql[] = 'ALTER TABLE [' . $table_prefix . 'confirm] WITH NOCHECK ADD CONSTRAINT [PK_' . $table_prefix . 'confirm] PRIMARY KEY  CLUSTERED ( [session_id],[confirm_id])  ON [PRIMARY]';
0505                  $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]';
0506                  break;
0507   
0508              case 'msaccess':
0509                  $sql[] = 'CREATE TABLE ' . $table_prefix . 'confirm (confirm_id char(32) NOT NULL, session_id char(32) NOT NULL, code char(6) NOT NULL)';
0510                  $sql[] = 'ALTER TABLE ' . $table_prefix . 'confirm ADD (PRIMARY KEY (session_id, confirm_id))';
0511                  break;
0512   
0513              case 'postgresql':
0514                  $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 {$table_prefix}confirm_pkey PRIMARY KEY (session_id, confirm_id))';
0515                  break;
0516          }
0517   
0518      case '.0.5':
0519      case '.0.6':
0520      case '.0.7':
0521      case '.0.8':
0522      case '.0.9':
0523      case '.0.10':
0524      case '.0.11':
0525      case '.0.12':
0526      case '.0.13':
0527      case '.0.14':
0528   
0529          switch (SQL_LAYER)
0530          {
0531              case 'mysql':
0532              case 'mysql4':
0533                  $sql[] = "ALTER TABLE " . SESSIONS_TABLE . "
0534                      ADD COLUMN session_admin tinyint(2) DEFAULT '0' NOT NULL";
0535                  break;
0536   
0537              case 'postgresql':
0538                  $sql[] = "ALTER TABLE " . SESSIONS_TABLE . "
0539                      ADD COLUMN session_admin int2";
0540                  $sql[] = "ALTER TABLE " . SESSIONS_TABLE . "
0541                      ALTER COLUMN session_admin SET DEFAULT '0'";
0542                  break;
0543   
0544              case 'mssql-odbc':
0545              case 'mssql':
0546                  $sql[] = "ALTER TABLE " . SESSIONS_TABLE . " ADD
0547                      session_admin smallint NOT NULL,
0548                      CONSTRAINT [DF_" . $table_prefix . "sessions_session_admin] DEFAULT (0) FOR [session_admin]";
0549                  break;
0550   
0551              case 'msaccess':
0552                  $sql[] = "ALTER TABLE " . SESSIONS_TABLE . " ADD
0553                      session_admin smallint NOT NULL";
0554                  break;
0555          }
0556   
0557      case '.0.15':
0558      case '.0.16':
0559      case '.0.17':
0560          // Add tables for session keys
0561          switch (SQL_LAYER)
0562          {
0563              case 'mysql':
0564              case 'mysql4':
0565                  $sql[] = 'CREATE TABLE ' . $table_prefix . 'sessions_keys (key_id varchar(32) DEFAULT \'0\' NOT NULL, user_id mediumint(8) DEFAULT \'0\' NOT NULL, last_ip varchar(8) DEFAULT \'0\' NOT NULL, last_login int(11) DEFAULT \'0\' NOT NULL, PRIMARY KEY (key_id, user_id), KEY last_login (last_login))';
0566                  break;
0567   
0568              case 'mssql':
0569              case 'mssql-odbc':
0570                  $sql[] = 'CREATE TABLE [' . $table_prefix . 'sessions_keys] ([key_id] [char] (32) NOT NULL , [user_id] [int] NOT NULL , [last_ip] [char] (8) NOT NULL , [last_login] [int] NOT NULL) ON [PRIMARY]';
0571   
0572                  $sql[] = 'CREATE INDEX [IX_' . $table_prefix . 'sessions_keys] ON [' . $table_prefix . 'sessions_keys]([key_id], [user_id]) ON [PRIMARY]';
0573                  $sql[] = 'CREATE  INDEX [IX_' . $table_prefix . 'sessions_keys_1] ON [' . $table_prefix . 'sessions_keys]([last_login]) ON [PRIMARY]';
0574                  break;
0575   
0576              case 'msaccess':
0577                  $sql[] = 'CREATE TABLE ' . $table_prefix . 'sessions_keys (key_id char(32) NOT NULL, user_id int NOT NULL, last_ip char(8) NOT NULL, last_login int NOT NULL)';
0578                  $sql[] = 'ALTER TABLE ' . $table_prefix . 'sessions_keys ADD PRIMARY KEY (key_id, user_id)';
0579                  break;
0580   
0581              case 'postgresql':
0582                  $sql[] = 'CREATE TABLE ' . $table_prefix . 'sessions_keys (key_id char(32) DEFAULT \'0\' NOT NULL, user_id int4 DEFAULT \'0\' NOT NULL, last_ip char(8) DEFAULT \'0\' NOT NULL, last_login int4 DEFAULT \'0\' NOT NULL, CONSTRAINT ' . $table_prefix . 'sessions_keys_pkey PRIMARY KEY (key_id, user_id))';
0583                  $sql[] = 'CREATE INDEX last_login_' . $table_prefix . 'sessions_keys_index ON ' . $table_prefix . 'sessions_keys (last_login)';
0584                  break;
0585          }
0586   
0587      case '.0.18':
0588   
0589          // Add login columns to user table
0590          switch (SQL_LAYER)
0591          {
0592              case 'mysql':
0593              case 'mysql4':
0594                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0595                      ADD COLUMN user_login_tries smallint(5) UNSIGNED DEFAULT '0' NOT NULL";
0596                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0597                      ADD COLUMN user_last_login_try int(11) DEFAULT '0' NOT NULL";
0598                  break;
0599   
0600              case 'postgresql':
0601                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0602                      ADD COLUMN user_login_tries int2";
0603                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0604                      ALTER COLUMN user_login_tries SET DEFAULT '0'";
0605                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0606                      ADD COLUMN user_last_login_try int4";
0607                  $sql[] = "ALTER TABLE " . USERS_TABLE . "
0608                      ALTER COLUMN user_last_login_try SET DEFAULT '0'";
0609                  break;
0610   
0611              case 'mssql-odbc':
0612              case 'mssql':
0613                  $sql[] = "ALTER TABLE " . USERS_TABLE . " ADD
0614                      user_login_tries smallint NOT NULL,
0615                      CONSTRAINT [DF_" . $table_prefix . "users_user_login_tries] DEFAULT (0) FOR [user_login_tries]";
0616                  $sql[] = "ALTER TABLE " . USERS_TABLE . " ADD
0617                      user_last_login_try int NOT NULL,
0618                      CONSTRAINT [DF_" . $table_prefix . "users_user_last_login_try] DEFAULT (0) FOR [user_last_login_try]";
0619                  break;
0620   
0621              case 'msaccess':
0622                  $sql[] = "ALTER TABLE " . USERS_TABLE . " ADD
0623                      user_login_tries smallint NOT NULL";
0624                  $sql[] = "ALTER TABLE " . USERS_TABLE . " ADD
0625                      user_last_login_try int NOT NULL";
0626                  break;
0627          }
0628   
0629      case '.0.19':
0630   
0631          // Add search time to the search table
0632          switch (SQL_LAYER)
0633          {
0634              case 'mysql':
0635              case 'mysql4':
0636                  $sql[] = "ALTER TABLE " . SEARCH_TABLE . "
0637                      ADD COLUMN search_time int(11) DEFAULT '0' NOT NULL";
0638                  break;
0639   
0640              case 'postgresql':
0641                  $sql[] = "ALTER TABLE " . SEARCH_TABLE . "
0642                      ADD COLUMN search_time int4";
0643                  $sql[] = "ALTER TABLE " . SEARCH_TABLE . "
0644                      ALTER COLUMN search_time SET DEFAULT '0'";
0645                  break;
0646   
0647              case 'mssql-odbc':
0648              case 'mssql':
0649                  $sql[] = "ALTER TABLE " . SEARCH_TABLE . " ADD
0650                      search_time int NOT NULL,
0651                      CONSTRAINT [DF_" . $table_prefix . "search_results_search_time] DEFAULT (0) FOR [search_time]";
0652                  break;
0653   
0654              case 'msaccess':
0655                  $sql[] = "ALTER TABLE " . SEARCH_TABLE . " ADD
0656                      search_time int NOT NULL";
0657                  break;
0658          }
0659   
0660          break;
0661   
0662      case '.0.21':
0663   
0664          // MySQL only change
0665          switch (SQL_LAYER)
0666          {
0667              case 'mysql':
0668              case 'mysql4':
0669                  $sql[] = 'ALTER TABLE ' . SEARCH_TABLE . '
0670                      MODIFY COLUMN search_array MEDIUMTEXT NOT NULL';
0671          }
0672   
0673          break;
0674   
0675      case '.0.22':
0676      case '.0.23':
0677   
0678          switch (SQL_LAYER)
0679          {
0680              case 'mysql':
0681              case 'mysql4':
0682                  $sql[] = "ALTER TABLE " . SESSIONS_TABLE . "
0683                      ADD COLUMN priv_session_id char(32) DEFAULT '' NOT NULL";
0684                  break;
0685   
0686              case 'postgresql':
0687                  $sql[] = "ALTER TABLE " . SESSIONS_TABLE . "
0688                      ADD COLUMN priv_session_id char(32)";
0689                  $sql[] = "ALTER TABLE " . SESSIONS_TABLE . "
0690                      ALTER COLUMN priv_session_id SET DEFAULT ''";
0691                  break;
0692   
0693              case 'mssql-odbc':
0694              case 'mssql':
0695                  $sql[] = "ALTER TABLE " . SESSIONS_TABLE . " ADD
0696                      priv_session_id char (32) NOT NULL";
0697                  break;
0698   
0699              case 'msaccess':
0700                  $sql[] = "ALTER TABLE " . SESSIONS_TABLE . " ADD
0701                      priv_session_id char (32) NOT NULL";
0702                  break;
0703          }
0704   
0705  }
0706   
0707  echo "<h2>Updating database schema</h2>\n";
0708  echo "<p>Progress :: <b>";
0709  flush();
0710   
0711  $error_ary = array();
0712  $errored = false;
0713  if (count($sql))
0714  {
0715      for ($i = 0; $i < count($sql); $i++)
0716      {
0717          _sql($sql[$i], $errored, $error_ary);
0718      }
0719   
0720      echo "</b> <b class=\"ok\">Done</b><br />Result &nbsp; :: \n";
0721   
0722      if ($errored)
0723      {
0724          echo " <b>Some queries failed, the statements and errors are listing below</b>\n<ul>";
0725   
0726          for ($i = 0; $i < count($error_ary['sql']); $i++)
0727          {
0728              echo "<li>Error :: <b>" . $error_ary['error_code'][$i]['message'] . "</b><br />";
0729              echo "SQL &nbsp; :: <b>" . $error_ary['sql'][$i] . "</b><br /><br /></li>";
0730          }
0731   
0732          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";
0733      }
0734      else
0735      {
0736          echo "<b>No errors</b>\n";
0737      }
0738  }
0739  else
0740  {
0741      echo " No updates required</b></p>\n";
0742  }
0743   
0744  //
0745  // Data updates
0746  //
0747  unset($sql);
0748  $error_ary = array();
0749  $errored = false;
0750   
0751  echo "<h2>Updating data</h2>\n";
0752  echo "<p>Progress :: <b>";
0753  flush();
0754   
0755  switch ($row['config_value'])
0756  {
0757      case '':
0758          $sql = "SELECT themes_id
0759              FROM " . THEMES_TABLE . "
0760              WHERE template_name = 'subSilver'";
0761          $result = _sql($sql, $errored, $error_ary);
0762   
0763          if ($row = $db->sql_fetchrow($result))
0764          {
0765              $theme_id = $row['themes_id'];
0766   
0767              $sql = "UPDATE " . THEMES_TABLE . "
0768                  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 = ''
0769                  WHERE themes_id = $theme_id";
0770              _sql($sql, $errored, $error_ary);
0771   
0772              $sql = "DELETE FROM " . THEMES_NAME_TABLE . "
0773                  WHERE themes_id = $theme_id";
0774              _sql($sql, $errored, $error_ary);
0775   
0776              $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)
0777                  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', '', '', '')";
0778              _sql($sql, $errored, $error_ary);
0779          }
0780          $db->sql_freeresult($result);
0781   
0782          $sql = "SELECT MIN(post_id) AS first_post_id, topic_id
0783              FROM " . POSTS_TABLE . "
0784              GROUP BY topic_id
0785              ORDER BY topic_id ASC";
0786          $result = _sql($sql, $errored, $error_ary);
0787   
0788          if ($row = $db->sql_fetchrow($result))
0789          {
0790              do
0791              {
0792                  $sql = "UPDATE " . TOPICS_TABLE . "
0793                      SET topic_first_post_id = " . $row['first_post_id'] . "
0794                      WHERE topic_id = " . $row['topic_id'];
0795                  _sql($sql, $errored, $error_ary);
0796              }
0797              while ($row = $db->sql_fetchrow($result));
0798          }
0799          $db->sql_freeresult($result);
0800   
0801          $sql = "SELECT DISTINCT u.user_id
0802              FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug, " . AUTH_ACCESS_TABLE . " aa
0803              WHERE aa.auth_mod = 1
0804                  AND ug.group_id = aa.group_id
0805                  AND u.user_id = ug.user_id
0806                  AND u.user_level <> " . ADMIN;
0807          $result = _sql($sql, $errored, $error_ary);
0808   
0809          $mod_user = array();
0810          while ($row = $db->sql_fetchrow($result))
0811          {
0812              $mod_user[] = $row['user_id'];
0813          }
0814          $db->sql_freeresult($result);
0815   
0816          if (count($mod_user))
0817          {
0818              $sql = "UPDATE " . USERS_TABLE . "
0819                  SET user_level = " . MOD . "
0820                  WHERE user_id IN (" . implode(', ', $mod_user) . ")";
0821              _sql($sql, $errored, $error_ary);
0822          }
0823   
0824          $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
0825              VALUES ('server_name', 'www.myserver.tld')";
0826          _sql($sql, $errored, $error_ary);
0827   
0828          $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
0829              VALUES ('script_path', '/phpBB2/')";
0830          _sql($sql, $errored, $error_ary);
0831   
0832          $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
0833              VALUES ('server_port', '80')";
0834          _sql($sql, $errored, $error_ary);
0835   
0836          $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
0837              VALUES ('record_online_users', '1')";
0838          _sql($sql, $errored, $error_ary);
0839   
0840          $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
0841              VALUES ('record_online_date', '" . time() . "')";
0842          _sql($sql, $errored, $error_ary);
0843   
0844      case 'RC-3':
0845      case 'RC-4':
0846      case '.0.0':
0847      case '.0.1':
0848          if (SQL_LAYER == 'postgresql')
0849          {
0850              $sql = "SELECT user_id, user_timezone_old
0851                  FROM " . USERS_TABLE;
0852              $result = _sql($sql, $errored, $error_ary);
0853   
0854              while ($row = $db->sql_fetchrow($result))
0855              {
0856                  $sql = "UPDATE " . USERS_TABLE . "
0857                      SET user_timezone = " . $row['user_timezone_old'] . "
0858                      WHERE user_id = " . $row['user_id'];
0859                  _sql($sql, $errored, $error_ary);
0860              }
0861              $db->sql_freeresult($result);
0862          }
0863   
0864          $sql = "SELECT topic_id, topic_moved_id
0865              FROM " . TOPICS_TABLE . "
0866              WHERE topic_moved_id <> 0
0867                  AND topic_status = " . TOPIC_MOVED;
0868          $result = _sql($sql, $errored, $error_ary);
0869   
0870          $topic_ary = array();
0871          while ($row = $db->sql_fetchrow($result))
0872          {
0873              $topic_ary[$row['topic_id']] = $row['topic_moved_id'];
0874          }
0875          $db->sql_freeresult($result);
0876   
0877          while (list($topic_id, $topic_moved_id) = each($topic_ary))
0878          {
0879              $sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts
0880                  FROM " . POSTS_TABLE . "
0881                  WHERE topic_id = $topic_moved_id";
0882              $result = _sql($sql, $errored, $error_ary);
0883   
0884              $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'];
0885              _sql($sql, $errored, $error_ary);
0886          }
0887   
0888          unset($sql);
0889   
0890          sync('all forums');
0891   
0892      case '.0.2':
0893   
0894      case '.0.3':
0895   
0896          // Topics will resync automatically
0897   
0898          // Remove stop words from search match and search words
0899          $dirname = 'language';
0900          $dir = opendir($phpbb_root_path . $dirname);
0901   
0902          while ($file = readdir($dir))
0903          {
0904              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'))
0905              {
0906   
0907                  $stopword_list = trim(preg_replace('#([\w\.\-_\+\'-\\\]+?)[ \n\r]*?(,|$)#', '\'\1\'\2', str_replace("'", "\'", implode(', ', file($phpbb_root_path . $dirname . "/" . $file . '/search_stopwords.txt')))));
0908   
0909                  $sql = "SELECT word_id 
0910                      FROM " . SEARCH_WORD_TABLE . " 
0911                      WHERE word_text IN ($stopword_list)";
0912                  $result = _sql($sql, $errored, $error_ary);
0913   
0914                  $word_id_sql = '';
0915                  if ($row = $db->sql_fetchrow($result))
0916                  {
0917                      do
0918                      {
0919                          $word_id_sql .= (($word_id_sql != '') ? ', ' : '') . $row['word_id'];
0920                      }
0921                      while ($row = $db->sql_fetchrow($result));
0922   
0923                      $sql = "DELETE FROM " . SEARCH_WORD_TABLE . " 
0924                          WHERE word_id IN ($word_id_sql)";
0925                      _sql($sql, $errored, $error_ary);
0926   
0927                      $sql = "DELETE FROM " . SEARCH_MATCH_TABLE . " 
0928                          WHERE word_id IN ($word_id_sql)";
0929                      _sql($sql, $errored, $error_ary);
0930                  }
0931                  $db->sql_freeresult($result);
0932              }
0933          }
0934          closedir($dir);
0935   
0936          // Mark common words ...
0937          remove_common('global', 4/10);
0938   
0939          // remove superfluous polls ... grab polls with topics then delete polls
0940          // not in that list
0941          $sql = "SELECT v.vote_id 
0942              FROM " . TOPICS_TABLE . " t, " . VOTE_DESC_TABLE . " v
0943              WHERE v.topic_id = t.topic_id";
0944          $result = _sql($sql, $errored, $error_ary);
0945   
0946          $vote_id_sql = '';
0947          if ($row = $db->sql_fetchrow($result))
0948          {
0949              do
0950              {
0951                  $vote_id_sql .= (($vote_id_sql != '') ? ', ' : '') . $row['vote_id'];
0952              }
0953              while ($row = $db->sql_fetchrow($result));
0954   
0955              $sql = "DELETE FROM " . VOTE_DESC_TABLE . " 
0956                  WHERE vote_id NOT IN ($vote_id_sql)";
0957              _sql($sql, $errored, $error_ary);
0958   
0959              $sql = "DELETE FROM " . VOTE_RESULTS_TABLE . " 
0960                  WHERE vote_id NOT IN ($vote_id_sql)";
0961              _sql($sql, $errored, $error_ary);
0962   
0963              $sql = "DELETE FROM " . VOTE_USERS_TABLE . " 
0964                  WHERE vote_id NOT IN ($vote_id_sql)";
0965              _sql($sql, $errored, $error_ary);
0966          }
0967          $db->sql_freeresult($result);
0968   
0969          // update pm counters
0970          $sql = "SELECT privmsgs_to_userid, COUNT(privmsgs_id) AS unread_count 
0971              FROM " . PRIVMSGS_TABLE . 
0972              WHERE privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . 
0973              GROUP BY privmsgs_to_userid";
0974          $result = _sql($sql, $errored, $error_ary);
0975   
0976          if ($row = $db->sql_fetchrow($result))
0977          {
0978              $update_users = array();
0979              do
0980              {
0981                  $update_users[$row['unread_count']][] = $row['privmsgs_to_userid'];
0982              }
0983              while ($row = $db->sql_fetchrow($result));
0984   
0985              while (list($num, $user_ary) = each($update_users))
0986              {
0987                  $user_ids = implode(', ', $user_ary);
0988   
0989                  $sql = "UPDATE " . USERS_TABLE . " 
0990                      SET user_unread_privmsg = $num 
0991                      WHERE user_id IN ($user_ids)";
0992                  _sql($sql, $errored, $error_ary);
0993              }
0994              unset($update_list);
0995          }
0996          $db->sql_freeresult($result);
0997   
0998          $sql = "SELECT privmsgs_to_userid, COUNT(privmsgs_id) AS new_count 
0999              FROM " . PRIVMSGS_TABLE . 
1000              WHERE privmsgs_type = " . PRIVMSGS_NEW_MAIL . 
1001              GROUP BY privmsgs_to_userid";
1002          $result = _sql($sql, $errored, $error_ary);
1003   
1004          if ($row = $db->sql_fetchrow($result))
1005          {
1006              $update_users = array();
1007              do
1008              {
1009                  $update_users[$row['new_count']][] = $row['privmsgs_to_userid'];
1010              }
1011              while ($row = $db->sql_fetchrow($result));
1012   
1013              while (list($num, $user_ary) = each($update_users))
1014              {
1015                  $user_ids = implode(', ', $user_ary);
1016   
1017                  $sql = "UPDATE " . USERS_TABLE . " 
1018                      SET user_new_privmsg = $num 
1019                      WHERE user_id IN ($user_ids)";
1020                  _sql($sql, $errored, $error_ary);
1021              }
1022              unset($update_list);
1023          }
1024          $db->sql_freeresult($result);
1025   
1026          // Remove superfluous watched topics
1027          $sql = "SELECT t.topic_id 
1028              FROM " . TOPICS_TABLE . " t, " . TOPICS_WATCH_TABLE . " w
1029              WHERE w.topic_id = t.topic_id";
1030          $result = _sql($sql, $errored, $error_ary);
1031   
1032          $topic_id_sql = '';
1033          if ($row = $db->sql_fetchrow($result))
1034          {
1035              do
1036              {
1037                  $topic_id_sql .= (($topic_id_sql != '') ? ', ' : '') . $row['topic_id'];
1038              }
1039              while ($row = $db->sql_fetchrow($result));
1040   
1041              $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " 
1042                  WHERE topic_id NOT IN ($topic_id_sql)";
1043              _sql($sql, $errored, $error_ary);
1044          }
1045          $db->sql_freeresult($result);
1046   
1047          // Reset any email addresses which are non-compliant ... something
1048          // not done in the upgrade script and thus which may affect some 
1049          // mysql users
1050          switch (SQL_LAYER)
1051          {
1052              case 'mysql':
1053                  $sql = "UPDATE " . USERS_TABLE . 
1054                      SET user_email = '' 
1055                      WHERE user_email NOT REGEXP '^[a-zA-Z0-9_\+\.\-]+@.*[a-zA-Z0-9_\-]+\.[a-zA-Z]{2,}$'";
1056                  _sql($sql, $errored, $error_ary);
1057          }
1058   
1059      case '.0.4':
1060   
1061          // Add the confirmation code switch ... save time and trouble elsewhere
1062          $sql = 'INSERT INTO ' . CONFIG_TABLE . " (config_name, config_value)
1063              VALUES ('enable_confirm', '0')";
1064          _sql($sql, $errored, $error_ary);
1065   
1066          $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
1067              VALUES ('sendmail_fix', '0')";
1068          _sql($sql, $errored, $error_ary);
1069   
1070      case '.0.5':
1071          
1072          $sql = "SELECT user_id, username 
1073              FROM " . USERS_TABLE;
1074          $result = _sql($sql, $errored, $error_ary);
1075   
1076          while ($row = $db->sql_fetchrow($result))
1077          {
1078              if (!preg_match('#(&gt;)|(&lt;)|(&quot)|(&amp;)#', $row['username']))
1079              {
1080                  if ($row['username'] != htmlspecialchars($row['username']))
1081                  {
1082                      $sql = "UPDATE " . USERS_TABLE . "
1083                          SET username = '" . str_replace("'", "''", htmlspecialchars($row['username'])) . "'
1084                          WHERE user_id = " . $row['user_id'];
1085                      _sql($sql, $errored, $error_ary);
1086                  }
1087              }
1088          }
1089          $db->sql_freeresult($result);
1090          
1091      case '.0.6':
1092      case '.0.7':
1093      case '.0.8':
1094      case '.0.9':
1095      case '.0.10':
1096      case '.0.11':
1097      case '.0.12':
1098      case '.0.13':
1099      case '.0.14':
1100   
1101          $sql = 'UPDATE ' . USERS_TABLE . ' SET user_allowhtml = 1 WHERE user_id = ' . ANONYMOUS;
1102          _sql($sql, $errored, $error_ary);
1103   
1104      case '.0.15':
1105      case '.0.16':
1106      case '.0.17':
1107   
1108          $sql = 'UPDATE ' . USERS_TABLE . ' SET user_active = 0 WHERE user_id = ' . ANONYMOUS;
1109          _sql($sql, $errored, $error_ary);
1110   
1111          $sql = 'INSERT INTO ' . CONFIG_TABLE . " (config_name, config_value)
1112              VALUES ('allow_autologin', '1')";
1113          _sql($sql, $errored, $error_ary);
1114   
1115          $sql = 'INSERT INTO ' . CONFIG_TABLE . " (config_name, config_value)
1116              VALUES ('max_autologin_time', '0')";
1117          _sql($sql, $errored, $error_ary);
1118          
1119      case '.0.18':
1120   
1121          $sql = 'INSERT INTO ' . CONFIG_TABLE . " (config_name, config_value)
1122              VALUES ('max_login_attempts', '5')";
1123          _sql($sql, $errored, $error_ary);
1124   
1125          $sql = 'INSERT INTO ' . CONFIG_TABLE . " (config_name, config_value)
1126              VALUES ('login_reset_time', '30')";
1127          _sql($sql, $errored, $error_ary);
1128   
1129      case '.0.19':
1130   
1131          $sql = 'INSERT INTO ' . CONFIG_TABLE . " (config_name, config_value)
1132              VALUES ('search_flood_interval', '15')";
1133          _sql($sql, $errored, $error_ary);
1134   
1135          $sql = 'INSERT INTO ' . CONFIG_TABLE . " (config_name, config_value)
1136              VALUES ('rand_seed', '0')";
1137          _sql($sql, $errored, $error_ary);
1138   
1139      case '.0.20':
1140   
1141          $sql = 'INSERT INTO ' . CONFIG_TABLE . " (config_name, config_value)
1142              VALUES ('search_min_chars', '3')";
1143          _sql($sql, $errored, $error_ary);
1144   
1145          // We reset those having autologin enabled and forcing the re-assignment of a session id
1146          // since there have been changes to the way these are handled from previous versions
1147          $sql = 'DELETE FROM ' . SESSIONS_TABLE;
1148          _sql($sql, $errored, $error_ary);
1149   
1150          $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE;
1151          _sql($sql, $errored, $error_ary);
1152   
1153          break;
1154   
1155      case '.0.21':
1156      case '.0.22':
1157      case '.0.23':
1158          $sql = 'DELETE FROM ' . SESSIONS_TABLE;
1159          _sql($sql, $errored, $error_ary);
1160      break;
1161   
1162      default:
1163          echo " No updates were required</b></p>\n";
1164          break;
1165  }
1166   
1167  echo "<h2>Updating version and optimizing tables</h2>\n";
1168  echo "<p>Progress :: <b>";
1169  flush();
1170   
1171  // update the version
1172  $sql = "UPDATE " . CONFIG_TABLE . "
1173      SET config_value = '$updates_to_version'
1174      WHERE config_name = 'version'";
1175  _sql($sql, $errored, $error_ary);
1176   
1177  // Optimize/vacuum analyze the tables where appropriate 
1178  // this should be done for each version in future along with 
1179  // the version number update
1180  switch (SQL_LAYER)
1181  {
1182      case 'mysql':
1183      case 'mysql4':
1184          $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 . 'sessions_keys, ' . $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';
1185          _sql($sql, $errored, $error_ary);
1186          break;
1187   
1188      case 'postgresql':
1189          _sql("VACUUM ANALYZE", $errored, $error_ary);
1190          break;
1191  }
1192   
1193  echo "</b> <b class=\"ok\">Done</b><br />Result &nbsp; :: \n";
1194   
1195  if ($errored)
1196  {
1197      echo " <b>Some queries failed, the statements and errors are listing below</b>\n<ul>";
1198   
1199      for ($i = 0; $i < count($error_ary['sql']); $i++)
1200      {
1201          echo "<li>Error :: <b>" . $error_ary['error_code'][$i]['message'] . "</b><br />";
1202          echo "SQL &nbsp; :: <b>" . $error_ary['sql'][$i] . "</b><br /><br /></li>";
1203      }
1204   
1205      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";
1206  }
1207  else
1208  {
1209      echo "<b>No errors</b>\n";
1210  }
1211   
1212  echo "<h2>Update completed</h2>\n";
1213  echo "\n" . '<p style="color:red">Please make sure you have updated your board files too, this file is only updating your database.</p>';
1214  echo "\n<p>You should now visit the General Configuration settings page in the <a href=\"../admin/\">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. Don't forget to delete this file!</p>\n";
1215   
1216  ?>
1217   
1218  <br clear="all" />
1219   
1220  </body>
1221  </html>
1222