diff --git a/phpBB/update_to_204.php b/phpBB/update_to_204.php
index 1488a03162..095978ca9c 100644
--- a/phpBB/update_to_204.php
+++ b/phpBB/update_to_204.php
@@ -23,15 +23,14 @@ function _sql($sql, &$errored, &$error_ary, $echo_dot = true)
{
global $db;
- if( !($result = $db->sql_query($sql)) )
+ if (!($result = $db->sql_query($sql)))
{
$errored = true;
- $error_ary['sql'][] = ( is_array($sql) ) ? $sql[$i] : $sql;
+ $error_ary['sql'][] = (is_array($sql)) ? $sql[$i] : $sql;
$error_ary['error_code'][] = $db->sql_error();
}
-//echo "\n\n
\n\n$sql\n\n
\n\n";
- if ( $echo_dot )
+ if ($echo_dot)
{
echo ". \n";
flush();
@@ -111,7 +110,7 @@ echo '
Database type :: ' . SQL_LAYER . '
';
$sql = "SELECT config_value
FROM " . CONFIG_TABLE . "
WHERE config_name = 'version'";
-if ( !($result = $db->sql_query($sql)) )
+if (!($result = $db->sql_query($sql)))
{
die("Couldn't obtain version info");
}
@@ -120,7 +119,7 @@ $row = $db->sql_fetchrow($result);
$sql = array();
-switch ( $row['config_value'] )
+switch ($row['config_value'])
{
case '':
echo 'Previous version :: < RC-3
Progress :: ";
flush();
-switch ( $row['config_value'] )
+switch ($row['config_value'])
{
case '':
$sql = "SELECT themes_id
@@ -557,7 +569,7 @@ switch ( $row['config_value'] )
WHERE template_name = 'subSilver'";
$result = _sql($sql, $errored, $error_ary);
- if( $row = $db->sql_fetchrow($result) )
+ if ($row = $db->sql_fetchrow($result))
{
$theme_id = $row['themes_id'];
@@ -582,7 +594,7 @@ switch ( $row['config_value'] )
ORDER BY topic_id ASC";
$result = _sql($sql, $errored, $error_ary);
- if ( $row = $db->sql_fetchrow($result) )
+ if ($row = $db->sql_fetchrow($result))
{
do
{
@@ -591,7 +603,7 @@ switch ( $row['config_value'] )
WHERE topic_id = " . $row['topic_id'];
_sql($sql, $errored, $error_ary);
}
- while ( $row = $db->sql_fetchrow($result) );
+ while ($row = $db->sql_fetchrow($result));
}
$db->sql_freeresult($result);
@@ -604,13 +616,13 @@ switch ( $row['config_value'] )
$result = _sql($sql, $errored, $error_ary);
$mod_user = array();
- while ( $row = $db->sql_fetchrow($result) )
+ while ($row = $db->sql_fetchrow($result))
{
$mod_user[] = $row['user_id'];
}
$db->sql_freeresult($result);
- if ( count($mod_user) )
+ if (count($mod_user))
{
$sql = "UPDATE " . USERS_TABLE . "
SET user_level = " . MOD . "
@@ -642,13 +654,13 @@ switch ( $row['config_value'] )
case 'RC-4':
case '.0.0':
case '.0.1':
- if ( SQL_LAYER == 'postgresql' )
+ if (SQL_LAYER == 'postgresql')
{
$sql = "SELECT user_id, user_timezone_old
FROM " . USERS_TABLE;
$result = _sql($sql, $errored, $error_ary);
- while ( $row = $db->sql_fetchrow($result) )
+ while ($row = $db->sql_fetchrow($result))
{
$sql = "UPDATE " . USERS_TABLE . "
SET user_timezone = " . $row['user_timezone_old'] . "
@@ -665,20 +677,20 @@ switch ( $row['config_value'] )
$result = _sql($sql, $errored, $error_ary);
$topic_ary = array();
- while ( $row = $db->sql_fetchrow($result) )
+ while ($row = $db->sql_fetchrow($result))
{
$topic_ary[$row['topic_id']] = $row['topic_moved_id'];
}
$db->sql_freeresult($result);
- while ( list($topic_id, $topic_moved_id) = each($topic_ary) )
+ while (list($topic_id, $topic_moved_id) = each($topic_ary))
{
$sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts
FROM " . POSTS_TABLE . "
WHERE topic_id = $topic_moved_id";
$result = _sql($sql, $errored, $error_ary);
- $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'];
+ $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'];
_sql($sql, $errored, $error_ary);
}
@@ -763,9 +775,6 @@ switch ( $row['config_value'] )
}
$db->sql_freeresult($result);
- // update post counts? Not sure about this ... will p**s a lot of users
- // off ...
-
// update pm counters
$sql = "SELECT privmsgs_to_userid, COUNT(privmsgs_id) AS unread_count
FROM " . PRIVMSGS_TABLE . "
@@ -823,6 +832,27 @@ switch ( $row['config_value'] )
}
$db->sql_freeresult($result);
+ // Remove superfluous watched topics
+ $sql = "SELECT t.topic_id
+ FROM " . TOPICS_TABLE . " t, " . TOPICS_WATCH_TABLE . " w
+ WHERE w.topic_id = t.topic_id";
+ $result = _sql($sql, $errored, $error_ary);
+
+ $topic_id_sql = '';
+ if ($row = $db->sql_fetchrow($result))
+ {
+ do
+ {
+ $topic_id_sql .= (($topic_id_sql != '') ? ', ' : '') . $row['topic_id'];
+ }
+ while ($row = $db->sql_fetchrow($result));
+
+ $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
+ WHERE topic_id NOT IN ($topic_id_sql)";
+ _sql($sql, $errored, $error_ary);
+ }
+ $db->sql_freeresult($result);
+
// Optimize/vacuum analyze the tables where appropriate
switch (SQL_LAYER)
{
@@ -845,11 +875,11 @@ switch ( $row['config_value'] )
echo " Done
Result :: \n";
- if ( $errored )
+ if ($errored)
{
echo " Some queries failed, the statements and errors are listing below\n
You should now visit the General Configuration settings page in the <