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

How to update this statement to PHP 5.4

Discussion in 'General PHP and MySQL Discussions' started by OakleyForum, Apr 28, 2013.

  1. OakleyForum

    OakleyForum Active Member

    I am working on getting XenTrader up and running again on my forum. Slavik is very busy lately and he provided me with the changes I had to make for the

    But, now I am getting errors on this code:

    I assume it has to be updated for PHP5.4

    Can anyone help?

    For the record this is the error I am getting:
     
  2. Jeremy P

    Jeremy P Well-Known Member

    It seems like you're not passing a user to standardizeViewingUserReference(). How is the $user variable being set?
     
  3. OakleyForum

    OakleyForum Active Member

    I believe it is this:
     
  4. Jeremy P

    Jeremy P Well-Known Member

    If you var_dump($user); before passing it to that method, what do you get?
     
  5. OakleyForum

    OakleyForum Active Member

    Where would I be putting the var_dump? Sorry, I have very little PHP experience.
     
  6. Jeremy

    Jeremy XenForo Moderator Staff Member

    Do you have a full stack trace for when you are getting this error? It seems like at some point, XenTrader_Model_Feedback::hasPermission is being called where $user is being passed in as true. Try changing line 21 to this:

    PHP:
    if(!$user || is_bool($user))
     
  7. OakleyForum

    OakleyForum Active Member

    I added that in, but still get the error. Here is the full error:

    Full Stack Trace
    FYI

    Right now(after upgrading to PHP 5.4), the XenTrader tab doesn't show up in the Navigation bar, the feedback ratings don't show up in Users profiles or post profiles. So their is no way for them to leave or view feedback. I added the tab /Xentrader.php manually, but there is no way to search members either.

    The error above is what I get when I navigate to /Xentrader/leave-feedback
     
  8. Jeremy

    Jeremy XenForo Moderator Staff Member

    #1 - 3 are showing its having false passed in versus a valid user or numeric.

    Code:
    if(!$user || is_bool($user))
    should have caught that.

    Can you post your full XenTrader_Model_Feedback::hasPermission function?
     
  9. OakleyForum

    OakleyForum Active Member

    Here is the entire function:

    Code:
        public function hasPermission($permission = '', $user = null)
        {
            if (is_numeric($user))
            {
                $user = $this->getModelFromCache('XenForo_Model_User')->getUserById(
                    $user, array('join' => XenForo_Model_User::FETCH_USER_PERMISSIONS)
                );
     
        if(!$user || is_bool($user))
                    return false;
            }
     
            $this->standardizeViewingUserReference($user);
     
            if (is_array($user['permissions']) && XenForo_Permission::hasPermission($user['permissions'], 'xentrader', $permission))
            {
                $userModel = $this->getModelFromCache('XenTrader_Model_User');
     
                if ($user2 = $userModel->getUserById($user['user_id']))
                    $user = array_merge($user, $user2);
     
                if ($permission == 'leaveFeedback' && $userModel->getUserType($user) == XenTrader_Model_User::TRADER_TYPE_NEW)
                {
                    $numFeedback = $this->countFeedback(array(
                        'newer_than' => XenForo_Application::$time - 86400,
                        'from_user' => $user['user_id'],
                    ));
     
                    if ($numFeedback >= XenForo_Application::get('options')->xentraderNewTraderDailySubmissions)
                        return false;
                }
     
                return true;
            }
     
            return false;
        }
    
     
  10. Jeremy

    Jeremy XenForo Moderator Staff Member

    Change the first few lines too...
    PHP:
            if (is_numeric($user))
             {
                 
    $user $this->getModelFromCache('XenForo_Model_User')->getUserById(
                     
    $user, array('join' => XenForo_Model_User::FETCH_USER_PERMISSIONS)
                 );
             }

         if(!
    $user || is_bool($user))
                     return 
    false;
     
  11. OakleyForum

    OakleyForum Active Member

    That caused permission errors. Per slovaks instructions:


    But now I have a new error:

    Code:
    Argument 1 passed to XenForo_Model::standardizeViewingUserReference() must be of the type array, boolean given, called in /home/oakleyfo/public_html/library/XenTrader/Model/Feedback.php on line 53 and defined
     
    XenForo_Application::handlePhpError() in XenForo/Model.php at line 511
    XenForo_Model->standardizeViewingUserReference() in XenTrader/Model/Feedback.php at line 53
    XenTrader_Model_Feedback->standardizeViewingUserReference() in XenTrader/Model/Feedback.php at line 25
    XenTrader_Model_Feedback->hasPermission() in XenTrader/ControllerPublic/Abstract.php at line 12
    XenTrader_ControllerPublic_Abstract->_assertHasPermission() in XenTrader/ControllerPublic/Index.php at line 171
    XenTrader_ControllerPublic_Index->actionLeaveFeedback() in XenForo/FrontController.php at line 310
    XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
    XenForo_FrontController->run() in /home/oakleyfo/public_html/index.php at line 13
     
  12. Jeremy

    Jeremy XenForo Moderator Staff Member

    His fix is wrong. XenForo_Model::standardizeViewingUserReference() requires an array passed by reference, so changing XenTrader_Model_Feedback::standardizeViewingUserReference() to use one is incorrect. It needs to remain array &user = null.
     
  13. tyteen4a03

    tyteen4a03 Well-Known Member

    What happens when you add an else clause to the first condition?

    Code:
            if (is_numeric($user))
            {
                $user = $this->getModelFromCache('XenForo_Model_User')->getUserById(
                    $user, array('join' => XenForo_Model_User::FETCH_USER_PERMISSIONS)
                );
     
                if (!$user)
                    return false;
            } else {
                die(var_dump($user));
            }
    
     
  14. OakleyForum

    OakleyForum Active Member

    The whole website just says "Null" when I put that in.
     
  15. tyteen4a03

    tyteen4a03 Well-Known Member

    The problem comes from XenTrader_ControllerPublic_Abstract:L7. It doesn't pass a $user parameter, causing this error.

    Change the whole _preDispatch function into this:

    Code:
        protected function _preDispatch($action)
        {
            $this->_assertHasPermission('viewFeedback', XenForo_Visitor::getInstance()->toArray());
        }
    
     
  16. Jeremy

    Jeremy XenForo Moderator Staff Member

    Most of the file doesn't pass a $user array.
     
  17. tyteen4a03

    tyteen4a03 Well-Known Member

    I can't seem to find a standardizeViewingUserReference call that doesn't pass a $user array, or a permission check at _preDispatch that uses the standardizeViewingUserReference method.
     
  18. Jeremy

    Jeremy XenForo Moderator Staff Member

    I'm still on a phone but the call the $this->hasPermission seemed to be missing the $user array in most parts in ControllerPublic_Index. Then again, I could be misremembering.
     
  19. OakleyForum

    OakleyForum Active Member

    Added this, then added the previous fix but still got NULL.
     
  20. tyteen4a03

    tyteen4a03 Well-Known Member

    You might be thinking about XenForo_Visitor::hasPermission.
     

Share This Page