Fixed Resource Category Change - Discussion Thread Vanishes

MattW

Well-known member
OK, so to reproduce this.

Create a category which doesn't have anything set for "Automatically Create Thread in Forum:"

With a resource from a category which does have "Automatically Create Thread in Forum:" set, and a current discussion thread associated with it, edit the resource, and move it to the category with no "Automatically Create Thread in Forum:" set.

The discussion thread vanishes, and if you look in xf_thread table, the node_id is set to 0

Discovered this while testing @Bob B 's Showcase as his code uses the same as the RM

code:

PHP:
if ($this->isUpdate() && $this->isChanged('resource_category_id') && $this->get('discussion_thread_id'))
        {
            $catDw = $this->_getCategoryDwForUpdate();

            $nodeId = $this->getOption(self::OPTION_CREATE_THREAD_NODE_ID);
            if ($nodeId === null)
            {
                $nodeId = $catDw->get('thread_node_id');
            }
            $prefixId = $this->getOption(self::OPTION_CREATE_THREAD_PREFIX_ID);
            if ($prefixId === null)
            {
                $prefixId = $catDw->get('thread_prefix_id');
            }

            $threadDw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT);
            if ($threadDw->setExistingData($this->get('discussion_thread_id')) && $threadDw->get('discussion_type') == 'resource')
            {
                $threadDw->set('node_id', $nodeId);
                $threadDw->set('prefix_id', $prefixId);
                $threadDw->save();
            }
        }
 
It will now (soft) delete the thread if moved to a category that doesn't have an associated forum. (It will be restored if moved back.)
 
Top Bottom