The thing is, you can't use CWebUser in console application.
If you rely on a component, which needs CWebUser, you'll have to detect this in the component and create some kind of workaround for this case. For example, you could genereate in your scope code an exception part where ensures that Yii::app()->user
is not called:
public function scopes(){
if (Yii::app() instanceof CConsoleApplication) {
$user = array(''); //no condition
}else{
$user = array(
'condition'=>'id='.Yii::app()->user->id,
);
}
return array(
'user' => $user,
'active' => array(
'condition'=>'status='.self::STATUS_ACTIVE,
), ...
);
}
Another simple isset() check that works for me:
if (!isset(Yii::app()->user))
echo "username not set
";
return;
Console output: