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

Fixed [minor] [v1.1.1] XenForo_Model_User::ban() doesn't respect $viewingUser variable

Discussion in 'Resolved Bug Reports' started by Mike Tougeron, Dec 3, 2011.

  1. Mike Tougeron

    Mike Tougeron Well-Known Member

    The user ban method is defined as:
    PHP:
    XenForo_Model_User::ban($userId$endDate$reason$update false, &$errorKey null, array $viewingUser null
    but it doesn't use the $viewingUser variable; it always uses XenForo_Visitor.
    Suggested fix
    PHP:
    //Line 838
    if ( !empty($viewingUser) && isset($viewingUser['user_id']) ) {
        
    $banUserId $viewingUser['user_id'];
    } else {
        
    $banUserId XenForo_Visitor::getUserId();
    }
    $dw->set('ban_user_id'$banUserId);
    Thanks,
    Mike
     
    ragtek likes this.
  2. Kier

    Kier XenForo Developer Staff Member

    Fixed.
     
  3. Pepelac

    Pepelac Well-Known Member

    Hmm.

    Sorry to disturb you with this, but it seems to be broken in XF 1.1.1.

    After upgrading forums to version 1.1.1 I can see, that all new ban records have 0 in the ban_user_id field.

    And, as I can see, you call method XenForo_Model_User::ban() only in XenForo_ControllerAdmin_Banning and XenForo_Model_SpamCleaner. And none of this classes doesn't pass $viewingUser array to the XenForo_Model_User::ban()

    ban_problem.png
     
    Mike, ragtek, Vincent and 2 others like this.
  4. ragtek

    ragtek Guest

    I can confirm that it's still missing:(
    I've changed it on my board to
    PHP:
        public function ban($userId$endDate$reason$update false, &$errorKey null, array $viewingUser null)
        {
            if (
    $endDate XenForo_Application::$time && $endDate !== self::PERMANENT_BAN)
            {
                
    $errorKey 'please_enter_a_date_in_the_future';
                return 
    false;
            }

            
    $dw XenForo_DataWriter::create('XenForo_DataWriter_UserBan');
            if (
    $update)
            {
                
    $dw->setExistingData($userId);
            }
            else
            {
                
    $dw->set('user_id'$userId);
                
    $dw->set('ban_user_id', ($viewingUser == null) ? XenForo_Visitor::getUserId() : $viewingUser['user_id']);
            }

            
    $dw->set('end_date'$endDate);
            
    $dw->set('user_reason'$reason);
            
    $dw->preSave();

            if (
    $dw->hasErrors())
            {
                
    $errors $dw->getErrors();
                
    $errorKey reset($errors);
                return 
    false;
            }

            
    $dw->save();
            return 
    true;
        }
     
    Pepelac likes this.
  5. Mike

    Mike XenForo Developer Staff Member

    Fixed properly now. Thanks. :)
     
    Pepelac and Fuhrmann like this.

Share This Page