Not a bug Error when creating attachment key for profile post if profile_user_id context is not correctly provided

Jake B.

Well-known member
Affected version
2.2.4
Looks like a check is missing because it's not something you can encounter under normal usage

PHP:
    protected function getUserFromContext(array $context)
    {
        $em = \XF::em();
        if (!empty($context['profile_post_id']))
        {
            /** @var \XF\Entity\ProfilePost $profilePost */
            $profilePost = $em->find('XF:ProfilePost', intval($context['profile_post_id']), ['ProfileUser']);
            if (!$profilePost || !$profilePost->canView() || !$profilePost->canEdit())
            {
                return null;
            }
            $user = $profilePost->ProfileUser;
        }
        else if (!empty($context['profile_user_id']))
        {
            /** @var \XF\Entity\User $user */
            $user = $em->find('XF:User', intval($context['profile_user_id']));
            if (!$user)
            {
                return null;
            }
        }
        return $user;
    }

to

PHP:
    protected function getUserFromContext(array $context)
    {
        $em = \XF::em();
        if (!empty($context['profile_post_id']))
        {
            /** @var \XF\Entity\ProfilePost $profilePost */
            $profilePost = $em->find('XF:ProfilePost', intval($context['profile_post_id']), ['ProfileUser']);
            if (!$profilePost || !$profilePost->canView() || !$profilePost->canEdit())
            {
                return null;
            }
            $user = $profilePost->ProfileUser;
            if (!$user)
            {
                return null;
            }
        }
        else if (!empty($context['profile_user_id']))
        {
            /** @var \XF\Entity\User $user */
            $user = $em->find('XF:User', intval($context['profile_user_id']));
            if (!$user)
            {
                return null;
            }
        }
        return $user;
    }
 
The code you've cited here is a bit different than what's actually in 2.2.4 (the last return line is has changed), so I'm not sure if you're running the latest code.

A full backtrace of the error you received would be helpful.
 
Nope, you're entirely correct. Ran that first call for the attachment key portion on a 2.2.3 install accidentally. Forgot to reply here and ask for this to be closed after I noticed when the rest didn't work :)
 
Back
Top Bottom