As designed Moving closed thread does not updates the redirect

Floren

Well-known member
Try this:
1) Close a thread and move it to a different forum.
2) Open the thread for posting and go to the old forum where the redirect link is present.

The redirect displays a Closed status.
 

ENF

Well-known member
It does display the lock on the redirect in the original forum.

But I guess as long as the target thread is open, then this more just cosmetic that function. Never really noticed before you post this.
 

Jake Bunce

XenForo moderator
Staff member
Confirmed in 1.1.2

I offer this code fix to the devs, that they may find it worthy.


XenForo_DataWriter_Discussion_Thread

Add the red code:

Rich (BB code):
	/**
	 * Specific discussion post-save behaviors.
	 */
	protected function _discussionPostSave(array $messages)
	{
		$threadId = $this->get('thread_id');

		if ($this->isUpdate() && $this->isChanged('discussion_state') && $this->get('discussion_state') != 'visible')
		{
			$this->_deleteRedirects('thread-' . $threadId . '-%', true);
		}
		else if ($this->isUpdate() && $this->isChanged('node_id'))
		{
			if ($this->get('discussion_type') == 'redirect')
			{
				$threadRedirectModel = $this->getModelFromCache('XenForo_Model_ThreadRedirect');
				$redirect = $threadRedirectModel->getThreadRedirectById($threadId);
				if ($redirect && $redirect['redirect_key'])
				{
					$redirectKey = preg_replace('/^(thread-\d+)-(\d+)$/', '$1-' . $this->get('node_id'), $redirect['redirect_key']);
					if ($redirectKey != $redirect['redirect_key'])
					{
						$threadRedirectModel->updateThreadRedirect($this->get('thread_id'), array('redirect_key' => $redirectKey));
					}
				}
			}
			else
			{
				// delete redirects if moving back to forum that already had it
				$this->_deleteRedirects('thread-' . $threadId . '-' . $this->get('node_id') . '-');
			}
		}

		if ($this->isUpdate() && $this->isChanged('discussion_open'))
		{
			$threadRedirectModel = $this->getModelFromCache('XenForo_Model_ThreadRedirect');

			$redirectThreadIds = array();
			$threadRedirects = $threadRedirectModel->getThreadRedirectsByKey('thread-' . $threadId . '-%', true);

			foreach ($threadRedirects AS $threadRedirect)
			{
				$redirectThreadIds[] = $threadRedirect['thread_id'];
			}

			if ($redirectThreadIds)
			{
				$db = $this->_db;

				$db->update('xf_thread',
					array('discussion_open' => $this->get('discussion_open')),
					'thread_id IN (' . $db->quote($redirectThreadIds) . ')'
				);
			}
		}

		if ($this->isUpdate() && $this->get('discussion_state') == 'visible' && $this->isChanged('node_id'))
		{
			$indexer = new XenForo_Search_Indexer();

			$messageHandler = $this->_messageDefinition->getSearchDataHandler();
			if ($messageHandler)
			{
				$thread = $this->getMergedData();
				$fullMessages = $this->_getMessagesInDiscussionSimple(true); // re-get with message contents
				foreach ($fullMessages AS $key => $message)
				{
					$messageHandler->insertIntoIndex($indexer, $message, $thread);
					unset($fullMessages[$key]);
				}
			}

			$this->_handleForumMove($messages, $this->getExisting('node_id'), $this->get('node_id'));
		}
	}
Works fine in my testing.
 

Mike

XenForo developer
Staff member
Really, redirects represent snap shots at the time - you can say the same about sticky state, visibility state, prefix, reply/view count, etc.

So, as designed.
 
Top