Fixed XenForo_Model_Warning::triggerWarningAction always returns 0

Jon W

Well-known member
The return value for the above method always returns 0, despite looking like it is supposed to return the last insert ID if an insert is successful. This is because the request to get the last insert ID is called after the transaction is committed, which doesn't seem to work.

I've checked everywhere else and this seems to be dealt with correctly in all other places.

The solution is to replace:
PHP:
        if ($insertTrigger)
        {
            $this->_getDb()->insert('xf_warning_action_trigger', array(
                'warning_action_id' => $action['warning_action_id'],
                'user_id' => $userId,
                'action_date' => XenForo_Application::$time,
                'trigger_points' => $action['points'],
                'action' => $action['action'],
                'min_unban_date' => $minUnbanDate
            ));
        }

        XenForo_Db::commit($db);

        return ($insertTrigger ? $this->_getDb()->lastInsertId() : 0);
with:
PHP:
        $actionTriggerId = 0;
        if ($insertTrigger)
        {
            $this->_getDb()->insert('xf_warning_action_trigger', array(
                'warning_action_id' => $action['warning_action_id'],
                'user_id' => $userId,
                'action_date' => XenForo_Application::$time,
                'trigger_points' => $action['points'],
                'action' => $action['action'],
                'min_unban_date' => $minUnbanDate
            ));
            $actionTriggerId = $this->_getDb()->lastInsertId();
        }

        XenForo_Db::commit($db);

        return $actionTriggerId;
 
Top Bottom