Confirmed getModeratorsWhoCanActionItem has a bad type hint type, and is missing a null check

Xon

Well-known member
Licensed customer
Affected version
2.3.12
PHP:
/**
 * @param $type
 * @param bool $throw
 *
 * @return \XF\ApprovalQueue\AbstractHandler|null
 */
public function getApprovalQueueHandler($type, $throw = false)
...
public function getModeratorsWhoCanActionItem(
    Entity $content,
    bool $notifiableOnly = false
)
...
public function getModeratorsWhoCanActionItem(
    Entity $content,
    bool $notifiableOnly = false
)
{
    $moderatorRepo = $this->repository(ModeratorRepository::class);

    $moderators = $moderatorRepo
        ->findModeratorsForList()
        ->with('User.PermissionCombination')
        ->fetch();

    if ($moderators->count())
    {
        /** @var \XF\ApprovalQueue\AbstractHandler $handler */
        $handler = $this->getApprovalQueueHandler($content->getEntityContentType());

The explicit type hint on type hint on $handler is overriding that getApprovalQueueHandler() can return null.

This should be done at the start of the function and return if there is no handler instead of causing an internal server error;
Code:
Error: Call to a member function canView() on null in src/XF/Repository/ApprovalQueueRepository.php at line 239
 
The getModeratorsWhoCanActionItem finder really should push the notify_approval check into the finder query rather than as part of the php processing side

As there is no point doing the view check if no one has actually requested to be notified
 
This was challenging to debug as another XF error made this not get logged;
 
Back
Top Bottom