mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-04 06:37:55 +08:00 
			
		
		
		
	fix bugs of BlameableBehavior in console application. In console application, \yii\console\Application doesn't have getUser() method. Use BlameableBehavior in console application will cause an exception.
				
					
				
			This commit is contained in:
		@ -102,9 +102,12 @@ class BlameableBehavior extends AttributeBehavior
 | 
				
			|||||||
    protected function getValue($event)
 | 
					    protected function getValue($event)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if ($this->value === null) {
 | 
					        if ($this->value === null) {
 | 
				
			||||||
            $user = Yii::$app->getUser();
 | 
					            if (Yii::$app->hasMethod('getUser')) {
 | 
				
			||||||
 | 
					                $user = Yii::$app->getUser();
 | 
				
			||||||
            return $user && !$user->isGuest ? $user->id : null;
 | 
					                return $user && !$user->isGuest ? $user->id : null;
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                return null;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            return call_user_func($this->value, $event);
 | 
					            return call_user_func($this->value, $event);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user