Can't fix Odd Problem with an extended Controller and addSessionActivityDetailsToList

  • Thread starter Thread starter ragtek
  • Start date Start date
R

ragtek

Guest
I'm extending the thread controller with an own class
class Ragtek_PLOTV_ControllerPublic_Thread extends
PHP:
class Ragtek_PLOTV_ControllerPublic_Thread extends

    XFCP_Ragtek_PLOTV_ControllerPublic_Thread
{
    public function actionIndex()
    {
        $response = parent::actionIndex();

        $thread = $response->params['thread'];

...
        return $response;
    }

    public function actionAddReply()
    {
        $this->_assertPostOnly();

        if ($this->_input->inRequest('more_options')) {
            return $this->responseReroute(__CLASS__, 'reply');
        }

        $threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT);

        $ftpHelper = $this->getHelper('ForumThreadPost');
        list($thread, $forum) = $ftpHelper->assertThreadValidAndViewable($threadId);

      ...
        if (
            foo()
        ) {

            throw $this->getErrorOrNoPermissionResponseException('ragtek_otw_errormessage');
        }
        else

            return parent::actionAddReply();
    }

    /**
    * @return Ragtek_PLOTV_Model
    */
    protected function _getHelperModel()
    {
        return $this->getModelFromCache('Ragtek_PLOTV_Model');
    }
}
It's working fine and while i'm reading the thread(i see the additional fields, this means the controller is extended and adds additional data to the response ), i can see me on the online list with action ( Viewing thread Welcome ragtekfsdfs to XenForo! A moment ago )

BUT if i'm on the reply page (add-reply) i can't load the online page anymore.

Code:
#0 [internal function]: XenForo_Autoloader->autoload('XFCP_Ragtek_PLO...')
#1 /home/www/doc/11759/ragtek.org/pl/library/Ragtek/PLOTV/ControllerPublic/Thread.php(18): spl_autoload_call('XFCP_Ragtek_PLO...')
#2 /home/www/doc/11759/ragtek.org/pl/library/XenForo/Autoloader.php(119): include('/home/www/doc/1...')
#3 /home/www/doc/11759/ragtek.org/pl/library/XenForo/Application.php(852): XenForo_Autoloader->autoload('Ragtek_PLOTV_Co...')
#4 /home/www/doc/11759/ragtek.org/pl/library/XenForo/Model/Session.php(303): XenForo_Application::autoload('Ragtek_PLOTV_Co...')
#5 /home/www/doc/11759/ragtek.org/pl/library/XenForo/ControllerPublic/Online.php(50): XenForo_Model_Session->addSessionActivityDetailsToList(Array)
#6 /home/www/doc/11759/ragtek.org/pl/library/XenForo/FrontController.php(310): XenForo_ControllerPublic_Online->actionIndex()
#7 /home/www/doc/11759/ragtek.org/pl/library/XenForo/FrontController.php(132): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
#8 /home/www/doc/11759/ragtek.org/pl/index.php(13): XenForo_FrontController->run()
#9 {main}

Anybody run into a similar problem and knows what's wrong?
The strange thing is:
On Dev Server it's working fine
On Stage Server it's also working fine
Only on the Live System i'm getting this....

Stage + Live system have the same setup & add-ons installed
 

Attachments

  • sess.webp
    sess.webp
    46.1 KB · Views: 29
This is sort of tricky, though I'm surprised it hasn't come up before. The instantiated controller is an XFCP class, so it can't be instantiated normally. The XFCP class is likely the class that is written into the session activity, so we don't have the base class to even try to instantiate the XFCP.

I think we have to move to ensuring that we always store the base class here, and make the code go through the load class handling.
 
This is sort of tricky, though I'm surprised it hasn't come up before. The instantiated controller is an XFCP class, so it can't be instantiated normally. The XFCP class is likely the class that is written into the session activity, so we don't have the base class to even try to instantiate the XFCP.

I think we have to move to ensuring that we always store the base class here, and make the code go through the load class handling.
I thought this too, but then i thought that it's my fault, because the error never came up in the past, so it has to be a problem with my code again:D
 
Ok, I've worked around this as much as possible - at least, it shouldn't throw an error.

But a good part of this is "can't fix". Since you're using a controller reroute, it's rerouting to your XFCP class. The code works because of the order of instantiation - independently, with just the class name, the code won't work. You shouldn't use __CLASS__ in your XFCP class redirects - use the original base class.
 
Just to be sure, because the problem isn't reproducable where often:D

if class Ragtek_PLOTV_ControllerPublic_Thread extends XFCP_Ragtek_PLOTV_ControllerPublic_Thread (=> XenForo_ControllerPublic_Thread)

i should use
PHP:
  if ($this->_input->inRequest('more_options')) {
            return $this->responseReroute(XenForo_ControllerPublic_Thread, 'reply');
        }
inside of my class?
 
Ok, I've worked around this as much as possible - at least, it shouldn't throw an error.

But a good part of this is "can't fix". Since you're using a controller reroute, it's rerouting to your XFCP class. The code works because of the order of instantiation - independently, with just the class name, the code won't work. You shouldn't use __CLASS__ in your XFCP class redirects - use the original base class.
To re-procedure this error.
- Firstly, at least one addon that extending XenForo_ControllerPublic_Thread
- You just open 2 browsers: one accesses user member page, eg: members/{id}. Remain one access Online page, this would throw error since it could not able to load class with XFCP_.

PHP:
/**
    * Adds details about session activity to a list of session activity records.
    *
    * @param array $activities
    *
    * @return array Activity records (in same order), with details in activityDescription/activityItemTitle/activityItemUrl keys.
    */
    public function addSessionActivityDetailsToList(array $activities)
    {
        // TODO: in the future, probably remove dependence on the visitor object (via called controllers)
 
        $controllerGroups = array();
        foreach ($activities AS $key => $activity)
        {
            $activity['params'] = XenForo_Application::parseQueryString($activity['params']);
 
            $controllerGroups[$activity['controller_name']][$key] = $activity;
        }
 
        foreach ($controllerGroups AS $controller => $controllerGroup)
        {
            $controller = XenForo_Application::resolveDynamicClass($controller, 'controller');
            try
            {
                $canLoad = ($controller && XenForo_Application::autoload($controller));
            }
            catch (XenForo_Exception $e) {} // likely an XFCP autoload error - skip this
 
            if ($canLoad)
            {
                $result = call_user_func(array($controller, 'getSessionActivityDetailsForList'), $controllerGroup);
            }
            else
            {
                $result = false;
            }
 
            if (is_array($result))
            {
                foreach ($result AS $resultKey => $resultInfo)
                {
                    if (!isset($controllerGroup[$resultKey]))
                    {
                        continue;
                    }
 
                    if (is_array($resultInfo))
                    {
                        $activities[$resultKey]['activityDescription'] = $resultInfo[0];
                        $activities[$resultKey]['activityItemTitle'] = $resultInfo[1];
                        $activities[$resultKey]['activityItemUrl'] = $resultInfo[2];
                        $activities[$resultKey]['activityItemPreviewUrl'] = $resultInfo[3];
                    }
                    else
                    {
                        $activities[$resultKey]['activityDescription'] = $resultInfo;
                        $activities[$resultKey]['activityItemTitle'] = false;
                        $activities[$resultKey]['activityItemUrl'] = false;
                        $activities[$resultKey]['activityItemPreviewUrl'] = false;
                    }
                }
            }
            else
            {
                foreach ($controllerGroup AS $key => $activity)
                {
                    $activities[$key]['activityDescription'] = $result;
                    $activities[$key]['activityItemTitle'] = false;
                    $activities[$key]['activityItemUrl'] = false;
                    $activities[$key]['activityItemPreviewUrl'] = false;
                }
            }
        }
 
        return $activities;
    }

Even though this function has already catched Excetion with
PHP:
$canLoad = ($controller && XenForo_Application::autoload($controller));
But since
PHP:
$controller = XenForo_Application::resolveDynamicClass($controller, 'controller');
also call XenForo_Application::autoload that lead this exception could not be catched.

Sorry for bump up very old thread :)
 
Back
Top Bottom