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

Fixed Error handling in XenForo_DataWriter_DiscussionMessage_Post

R

ragtek

Guest
#1
method setExtraData checks if the value is an array for DATA_FORUM

PHP:
public function setExtraData($name, $value)
{
if ($name == self::DATA_FORUM)
{
if (!is_array($value))
{
return;
}
 
XenForo_DataWriter_Discussion_Thread::setForumCacheItem($value);
}
 
return parent::setExtraData($name, $value);
}
BUT that's IMO NOT optimal, because these variable will ALWAYS be a array.

The reason for this is, that you're using XenForo_Model_Forum::getForumByThreadId to get the forum data
PHP:
public function getForumByThreadId($threadId)
{
if ($forums = $this->getForums(array('thread_id' => $threadId)))
{
return reset($forums);
}
 
return array();
}
and this returns an empty array if non forum was found.

So it will always call XenForo_DataWriter_Discussion_Thread::setForumCacheItem($value);
PHP:
public static function setForumCacheItem(array $forum)
{
self::$forumCache[$forum['node_id']] = $forum;
}
which will result in an error if $value is a empty array


To sum it up: THE POST DATAWRITER DOESN'T check, if the thread exists


Probably it shouldn't come to this error, because normally the data should be validated (and checked for the existing thread) BEFORE being sent to the post datawriter, but it's still a ugly implemention:p
 

Attachments

#2
What would happen if you turned error reporting off just for that one function, and how would you do that? Is that something that is OK to do until this is fixed?

Neither moderators nor admins can give infractions without this error.

PHP:
public static function setForumCacheItem(array $forum)
{
self::$forumCache[$forum['node_id']] = $forum;
}