1. 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

Discussion in 'Resolved Bug Reports' started by ragtek, Jul 24, 2012.

  1. ragtek

    ragtek Guest

    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
     

    Attached Files:

    Adam Howard likes this.
  2. Segep

    Segep New Member

    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;
    }
     
  3. Mike

    Mike XenForo Developer Staff Member

    I've adjusted this to make more sense.
     
    Slavik likes this.

Share This Page