1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-11 10:05:19 +02:00

[ticket/11691] Stagger the convertion of soft delete updates

PHPBB3-11691
This commit is contained in:
Joas Schilling 2013-07-14 10:35:19 -04:00
parent 8da3133238
commit a7af736b97

View File

@ -101,7 +101,8 @@ class softdelete_p1 extends \phpbb\db\migration\migration
return array( return array(
array('custom', array(array($this, 'update_post_visibility'))), array('custom', array(array($this, 'update_post_visibility'))),
array('custom', array(array($this, 'update_topic_visibility'))), array('custom', array(array($this, 'update_topic_visibility'))),
array('custom', array(array($this, 'update_topic_forum_counts'))), array('custom', array(array($this, 'update_topics_post_counts'))),
array('custom', array(array($this, 'update_forums_topic_and_post_counts'))),
array('permission.add', array('f_softdelete', false)), array('permission.add', array('f_softdelete', false)),
array('permission.add', array('m_softdelete', false)), array('permission.add', array('m_softdelete', false)),
@ -122,7 +123,7 @@ class softdelete_p1 extends \phpbb\db\migration\migration
$this->sql_query($sql); $this->sql_query($sql);
} }
public function update_topic_forum_counts() public function update_topics_post_counts()
{ {
$sql = 'UPDATE ' . $this->table_prefix . 'topics $sql = 'UPDATE ' . $this->table_prefix . 'topics
SET topic_posts_approved = topic_replies + 1, SET topic_posts_approved = topic_replies + 1,
@ -135,15 +136,24 @@ class softdelete_p1 extends \phpbb\db\migration\migration
topic_posts_unapproved = (topic_replies_real - topic_replies) + 1 topic_posts_unapproved = (topic_replies_real - topic_replies) + 1
WHERE topic_visibility = ' . ITEM_UNAPPROVED; WHERE topic_visibility = ' . ITEM_UNAPPROVED;
$this->sql_query($sql); $this->sql_query($sql);
}
public function update_forums_topic_and_post_counts($start)
{
$start = (int) $start;
$limit = 2;
$i = 0;
$sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts_approved) AS sum_posts_approved, SUM(topic_posts_unapproved) AS sum_posts_unapproved $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts_approved) AS sum_posts_approved, SUM(topic_posts_unapproved) AS sum_posts_unapproved
FROM ' . $this->table_prefix . 'topics FROM ' . $this->table_prefix . 'topics
GROUP BY forum_id, topic_visibility'; GROUP BY forum_id, topic_visibility';
$result = $this->db->sql_query($sql); $result = $this->db->sql_query_limit($sql, $start, $limit);
$update_forums = array(); $update_forums = array();
while ($row = $this->db->sql_fetchrow($result)) while ($row = $this->db->sql_fetchrow($result))
{ {
$i++;
$forum_id = (int) $row['forum_id']; $forum_id = (int) $row['forum_id'];
if (!isset($update_forums[$forum_id])) if (!isset($update_forums[$forum_id]))
{ {
@ -169,5 +179,15 @@ class softdelete_p1 extends \phpbb\db\migration\migration
WHERE forum_id = ' . $forum_id; WHERE forum_id = ' . $forum_id;
$this->sql_query($sql); $this->sql_query($sql);
} }
if ($i < $limit)
{
// There are no more topics, we are done
return;
}
// There are still more topics to query, return the next start value
return $start + $limit;
} }
} }