Conflicting Event Listeners?

Jaxel

Well-known member
I have two mods which extend the same model:
Code:
<?php

class EWRporta_Listener_Post
{
    public static function listen($class, array &$extend)
    {
        if ($class == 'XenForo_Model_Post')
        {
            $extend[] = 'EWRporta_Model_Post';
        }
    }
}
Code:
<?php

class EWRporta_Model_Post extends XenForo_Model_Post
{
    public function getPostsInThread($threadId, array $fetchOptions = array())
    {
        $options = XenForo_Application::get('options');

        if ($options->EWRporta_articleforum)
        {
            $limitOptions = $this->prepareLimitFetchOptions($fetchOptions);
            $stateLimit = $this->prepareStateLimitFromConditions($fetchOptions, 'post');
            $joinOptions = $this->preparePostJoinOptions($fetchOptions);

            return $this->fetchAllKeyed('
                SELECT post.*
                    ' . $joinOptions['selectFields'] . '
                FROM xf_post AS post
                ' . $joinOptions['joinTables'] . '
                    LEFT JOIN xf_thread AS thread ON (thread.thread_id = post.thread_id)
                WHERE post.thread_id = ?
                    AND (((' . $stateLimit . ')
                    ' . $this->addPositionLimit('post', $limitOptions['limit'], $limitOptions['offset']) . ')
                    OR post.post_id = thread.first_post_id)
                ORDER BY post.position ASC, post.post_date ASC
            ', 'post_id', $threadId);
        }

        return parent::getPostsInThread($threadId, $fetchOptions);
    }
}

Then the other addon...
Code:
<?php

class EWRcarta_Listener_Post
{
    public static function listen($class, array &$extend)
    {
        if ($class == 'XenForo_Model_Post')
        {
            $extend[] = 'EWRcarta_Model_Post';
        }
    }
}
Code:
<?php

class EWRcarta_Model_Post extends XFCP_EWRcarta_Model_Post
{
    public function getQuoteTextForPost(array $post, $maxQuoteDepth = 0)
    {
        $response = parent::getQuoteTextForPost($post, $maxQuoteDepth);
        $response = str_ireplace('[wiki=full]', '[wiki]', $response);
        return $response;
    }
}

The problem is that the second listener is not called. Both listeners have a priority of 10. If I set the listener priority of the EWRcarta listener to 11, it works (but not 9)... Why doesn't it work at 10 or less? Where is the conflict?
 
You probably have another add-on that is returning that function early.
That is what you are doing with getPostsInThread().
You should be using $fetchOptions to grab what you need instead of returning the function without calling the parent.
If I am also calling that function from my add-on and my listener's priority is one less that yours, then my function will not work because you returned it early.
 
You probably have another add-on that is returning that function early.
That is what you are doing with getPostsInThread().
You should be using $fetchOptions to grab what you need instead of returning the function without calling the parent.
If I am also calling that function from my add-on and my listener's priority is one less that yours, then my function will not work because you returned it early.
the issue is not the getpostinthreads... the issue is getquotetextforposts.
 
It doesn't look like you are extending the right class? Aren't you meant to be extending XFCP_Your_Class_Name?
 
Top Bottom