Fixed XF\Service\Tag\Changer::removeTagsInternal suffers from type-confusion leading to potential error


Well-known member
Affected version
In XF\Service\Tag\Changer::removeTagsInternal expects $removeTags to be an array of TagContent entities, but the caller (In XF\Service\Tag\Changer::removeTags) only passes in an array of Tag
public function removeTags($tagList, $ignoreNonRemovable = true)
   if (!is_array($tagList))
      $tagList = $this->splitTags($tagList);

   $removeTags = $this->tagRepo->getTags($tagList);
   $this->removeTagsInternal($removeTags, $ignoreNonRemovable);

protected function removeTagsInternal(array $removeTags, $ignoreNonRemovable = true)
   $visitorUserId = \XF::visitor()->user_id;

   foreach ($removeTags AS $tag)
      if ($ignoreNonRemovable
         && !$this->getPermission('removeOthers')
         && $tag->add_user_id != $visitorUserId
         // can't remove but told to ignore

This can then cause the error;
InvalidArgumentException: Accessed unknown getter 'add_user_id' on XF:Tag[10522]

When $ignoreNonRemovable is true (the default), and the user doesn't have permission to remove tags from others, it will error instead of ignore.

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.2).

Change log:
Fix permission check when removing tags with the tag changer service
There may be a delay before changes are rolled out to the XenForo Community.