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


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