Fork me on GitHub

Changes for #905

Description changed by Storlek (2013-09-28 08:41:03)

 1:  1:
-If someone is subscribed to a topic that's being merged, the process grinds to a halt because [code]$db->result[/code] returns the first row repeatedly. I can confirm that this breaks with both Postgres and SQLite. I'm guessing behavior is different with the MySQL backend, or else this probably would have been noticed and fixed by this point.+If someone is subscribed to a topic that's being merged, the process grinds to a halt because $db->result returns the first row repeatedly. I can confirm that this breaks with both Postgres and SQLite. I'm guessing behavior is different with the MySQL backend, or else this probably would have been noticed and fixed by this point.
  
 Here's a patch: Here's a patch:
  
 [code]  [code]
 diff -r 7311cd9bbb32 -r c6081db4ac0b moderate.php  diff -r 7311cd9bbb32 -r c6081db4ac0b moderate.php
 --- a/moderate.php      Wed Sep 18 16:07:00 2013 -0400  --- a/moderate.php      Wed Sep 18 16:07:00 2013 -0400
 +++ b/moderate.php      Sat Sep 28 04:23:39 2013 -0400  +++ b/moderate.php      Sat Sep 28 04:23:39 2013 -0400
 @@ -580,12 +580,11 @@  @@ -580,12 +580,11 @@
                 $db->query('UPDATE '.$db->prefix.'posts SET topic_id='.$merge_to_tid.' WHERE topic_id IN('.implode(',', $topics).')') or error('Unable to merge the posts into the topic', __FILE__, __LINE__, $db->error());                  $db->query('UPDATE '.$db->prefix.'posts SET topic_id='.$merge_to_tid.' WHERE topic_id IN('.implode(',', $topics).')') or error('Unable to merge the posts into the topic', __FILE__, __LINE__, $db->error());
   
                 // Update any subscriptions                  // Update any subscriptions
 -               $result = $db->query('SELECT user_id FROM '.$db->prefix.'topic_subscriptions WHERE topic_id IN ('.implode(',', $topics).')') or error('Unable to fetch subscriptions of merged topics', __FILE__, __LINE__, $db->error());  -               $result = $db->query('SELECT user_id FROM '.$db->prefix.'topic_subscriptions WHERE topic_id IN ('.implode(',', $topics).')') or error('Unable to fetch subscriptions of merged topics', __FILE__, __LINE__, $db->error());
 +                $result = $db->query('SELECT DISTINCT user_id FROM '.$db->prefix.'topic_subscriptions WHERE topic_id IN ('.implode(',', $topics).')') or error('Unable to fetch subscriptions of merged topics', __FILE__, __LINE__, $db->error());  +                $result = $db->query('SELECT DISTINCT user_id FROM '.$db->prefix.'topic_subscriptions WHERE topic_id IN ('.implode(',', $topics).')') or error('Unable to fetch subscriptions of merged topics', __FILE__, __LINE__, $db->error());
   
 -               $subscribed_users = array();  -               $subscribed_users = array();
 -               while ($cur_user_id = $db->result($result))  -               while ($cur_user_id = $db->result($result))
 -                       $subscribed_users[] = $cur_user_id;  -                       $subscribed_users[] = $cur_user_id;
 -               $subscribed_users = array_unique($subscribed_users);  -               $subscribed_users = array_unique($subscribed_users);
 +                $subscribed_users = array();  +                $subscribed_users = array();
 +                while ($row = $db->fetch_row($result))  +                while ($row = $db->fetch_row($result))
 +                        $subscribed_users[] = $row[0];  +                        $subscribed_users[] = $row[0];
   
                 $db->query('DELETE FROM '.$db->prefix.'topic_subscriptions WHERE topic_id IN ('.implode(',', $topics).')') or error('Unable to delete subscriptions of merged topics', __FILE__, __LINE__, $db->error());                  $db->query('DELETE FROM '.$db->prefix.'topic_subscriptions WHERE topic_id IN ('.implode(',', $topics).')') or error('Unable to delete subscriptions of merged topics', __FILE__, __LINE__, $db->error());
 [/code] [/code]
  
 (See also ticket #599 where this code was introduced) (See also ticket #599 where this code was introduced)