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

Fixed XenForo_Model_Warning::triggerWarningAction always returns 0

Discussion in 'Resolved Bug Reports' started by Jon W, Sep 18, 2013.

  1. Jon W

    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;
     
    Alluidh likes this.
  2. Mike

    Mike XenForo Developer Staff Member

    Good catch, fixed now thanks.
     
    Jon W likes this.

Share This Page