1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

As Designed Moving closed thread does not updates the redirect

Discussion in 'Resolved Bug Reports' started by Floren, May 10, 2012.

  1. Floren

    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.
     
  2. ENF

    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.
     
  3. Rob

    Rob Well-Known Member

    *confirmed*
     
  4. Jake Bunce

    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. [​IMG]

    XenForo_DataWriter_Discussion_Thread

    Add the red code:

    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.
     
    mrGTB and CyclingTribe like this.
  5. mrGTB

    mrGTB Well-Known Member

    Dam, and there was nobody to "Ninja" you. :unsure:
     
  6. Mike

    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.
     

Share This Page