diff options
author | Andreas Fischer <bantu@phpbb.com> | 2010-04-04 18:50:23 +0200 |
---|---|---|
committer | Andreas Fischer <bantu@phpbb.com> | 2010-06-11 21:52:04 +0200 |
commit | 38fc35a497e375797afdce6bc3cba952b9ed5344 (patch) | |
tree | 0898218d30df697cfa3c21353a0c55b17e9f882c /phpBB/install | |
parent | 30891ffb465f9745a6cd3c05957226ef0e600d94 (diff) | |
download | forums-38fc35a497e375797afdce6bc3cba952b9ed5344.tar forums-38fc35a497e375797afdce6bc3cba952b9ed5344.tar.gz forums-38fc35a497e375797afdce6bc3cba952b9ed5344.tar.bz2 forums-38fc35a497e375797afdce6bc3cba952b9ed5344.tar.xz forums-38fc35a497e375797afdce6bc3cba952b9ed5344.zip |
[ticket/9167] Detect and remove any dead left over shadow topics on update.
PHPBB3-9167
Diffstat (limited to 'phpBB/install')
-rw-r--r-- | phpBB/install/database_update.php | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 47d261dc46..7b27363125 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1684,6 +1684,51 @@ function change_database_data(&$no_updates, $version) } $db->sql_freeresult($result); + // Delete shadow topics pointing to not existing topics + $batch_size = 500; + + // Set of affected forums we have to resync + $sync_forum_ids = array(); + + do + { + $sql_array = array( + 'SELECT' => 't1.topic_id, t1.forum_id', + 'FROM' => array( + TOPICS_TABLE => 't1', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(TOPICS_TABLE => 't2'), + 'ON' => 't1.topic_moved_id = t2.topic_id', + ), + ), + 'WHERE' => 't1.topic_moved_id <> 0 + AND t2.topic_id IS NULL', + ); + $sql = $db->sql_build_query('SELECT', $sql_array); + $result = $db->sql_query_limit($sql, $batch_size); + + $topic_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $topic_ids[] = (int) $row['topic_id']; + + $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; + } + $db->sql_freeresult($result); + + if (!empty($topic_ids)) + { + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', $topic_ids); + $db->sql_query($sql); + } + } + while (sizeof($topic_ids) == $batch_size); + + // Sync the forums we have deleted shadow topics from. + sync('forum', 'forum_id', $sync_forum_ids, true, true); $no_updates = false; break; |