Skip to content

How to use Blameable Behaviour if activeRecord is created by Queue Job? #19845

Answered by gb5256
gb5256 asked this question in Q&A
Discussion options

You must be logged in to vote

After more digging I am using this approach now:

In console/config/main adding this to the components:

'user' => [
        'class' => 'yii\web\User',
        'identityClass' => 'common\models\User',
    ],

then inside the job we can do this:

$user = User::findIdentity($this->user_id);
Yii::$app->user->setIdentity($user);

'setIdentity' does not create session and also does not use Authentification etc. So for this user case perfect.

Thanks @tomaszkane for thinking with me on solutions.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by gb5256
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants