/** * Implemented for {@see XenForo_DataWriter_DiscussionContainerInterface}. */ public function updateCountersAfterDiscussionSave(XenForo_DataWriter_Discussion $discussionDw, $forceInsert = false) { if ($discussionDw->get('discussion_type') == 'redirect') { // note: this assumes the discussion type will never change to/from this except at creation return; } if ($discussionDw->get('discussion_state') == 'visible' && ($discussionDw->getExisting('discussion_state') != 'visible' || $forceInsert)) { $this->set('discussion_count', $this->get('discussion_count') + 1); $this->set('message_count', $this->get('message_count') + $discussionDw->get('reply_count') + 1); } else { if ($discussionDw->getExisting('discussion_state') == 'visible' && $discussionDw->get('discussion_state') != 'visible') { $this->set('discussion_count', $this->get('discussion_count') - 1); $this->set('message_count', $this->get('message_count') - $discussionDw->get('reply_count') - 1); if ($discussionDw->get('last_post_id') == $this->get('last_post_id')) { $this->updateLastPost(); } } else { if ($discussionDw->get('discussion_state') == 'visible' && $discussionDw->getExisting('discussion_state') == 'visible') { // no state change, probably just a reply $messageChange = $discussionDw->get('reply_count') - $discussionDw->getExisting('reply_count'); $this->set('message_count', $this->get('message_count') + $messageChange); } } } if ($discussionDw->get('discussion_state') == 'visible' && $discussionDw->get('last_post_date') >= $this->get('last_post_date')) { $this->set('last_post_date', $discussionDw->get('last_post_date')); $this->set('last_post_id', $discussionDw->get('last_post_id')); $this->set('last_post_user_id', $discussionDw->get('last_post_user_id')); $this->set('last_post_username', $discussionDw->get('last_post_username')); $this->set('last_thread_title', $discussionDw->get('title')); } else { if ($discussionDw->get('discussion_state') == 'visible' && $discussionDw->getExisting('discussion_state') == 'visible' && $discussionDw->getExisting('last_post_id') == $this->get('last_post_id') && ($discussionDw->isChanged('last_post_id') || $discussionDw->isChanged('title'))) { $this->updateLastPost(); } } }