You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * Class AbstractJob * * An abstract class for jobs that require the user context of the creator. * This class captures and stores the `userId` of the user creating the job and sets * the application's user identity during job execution. */abstractclass AbstractJob extends BaseObject
{
/** * @var int|null $userId Stores the ID of the user who created the job */public$userId;
/** * AbstractJob constructor. * Automatically sets the `userId` based on the currently logged-in user. * * @param array $config The configuration array */publicfunction__construct($config = [])
{
$this->userId = Yii::$app->user->id; // Capture the current user IDparent::__construct($config);
}
/** * Sets the user identity in Yii based on the `userId` property. * This method can be called in the child class to set the current user context. * * @return bool Returns true if the user was successfully impersonated, false otherwise. */protectedfunctionsetUserContext()
{
$user = \app\models\User::findOne($this->userId);
if ($user) {
Yii::$app->user->setIdentity($user); // Impersonate the userreturntrue;
}
Yii::error("User with ID {$this->userId} not found for impersonation.");
returnfalse;
}
}
Hi,
Great Extension! What about storing the user id of the user, who created the job a this time? Could be helpful in case of userstamp, grants etc.
Best,
Tobi
The text was updated successfully, but these errors were encountered: