Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-7834

Correctly update topic_time when deleting first post in topic

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 3.0.2
    • 3.0.9-RC1
    • Posting
    • None
    • PHP Environment: 5.2.0
      Database: MySQL 5.0.27

    Description

      in functions_posting.php, when the first post of the topic is deleted, the first topic poster details are updated, yet not the topic time.

      		case 'delete_first_post':
      			$sql = 'SELECT p.post_id, p.poster_id, p.post_username, u.username, u.user_colour
      				FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
      				WHERE p.topic_id = $topic_id
      					AND p.poster_id = u.user_id
      				ORDER BY p.post_time ASC";
      			$result = $db->sql_query_limit($sql, 1);
      			$row = $db->sql_fetchrow($result);
      			$db->sql_freeresult($result);
       
      			if ($data['topic_type'] != POST_GLOBAL)
      			{
      				$sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : '';
      			}
       
      			$sql_data[TOPICS_TABLE] = 'topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "'";
       
      			// Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply"
      			$sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : '');
       
      			$next_post_id = (int) $row['post_id'];
      		break;

      in my opinion should rather be something like this

      		case 'delete_first_post':
      			$sql = 'SELECT p.post_id, p.poster_id, p.post_username, p.post_time, u.username, u.user_colour
      				FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
      				WHERE p.topic_id = $topic_id
      					AND p.poster_id = u.user_id
      				ORDER BY p.post_time ASC";
      			$result = $db->sql_query_limit($sql, 1);
      			$row = $db->sql_fetchrow($result);
      			$db->sql_freeresult($result);
       
      			if ($data['topic_type'] != POST_GLOBAL)
      			{
      				$sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : '';
      			}
       
      			$sql_data[TOPICS_TABLE] = 'topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "', topic_time = " . (int) $row['post_time'];
       
      			// Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply"
      			$sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : '');
       
      			$next_post_id = (int) $row['post_id'];
      		break;

      Attachments

        Activity

          People

            Oleg Oleg [X] (Inactive)
            lefty74 lefty74 [X] (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: