Skip to content

Engauge Sessions

Intro

All Engauge user sessions are managed in a separate system called the Engauge Hub. Eventually they will all exist in Envoy, but for a period these sessions will be stored in the Engauge Hub database. In order to access these sessions within Envoy, a specific database connection is setup to link to the Engauge Hub DB.

Engauge Hub DB Connection

The Engauge Hub DB connection is mysql_engauge. In order to use this connection, it must be specified in the DB call: DB::connection('mysql_engauge')-> or in the model:

class EngaugeSession extends Model
{
    use HasFactory;
    protected $connection = 'mysql_engauge';
}

| NB: It's important to remember that certain data manipulations are required when accessing sessions from a separate system. Data columns like user_id will need to be adjusted to the related user_id in the Envoy system.

Environment variables

New environment variables need to be added to allow this connection to work. They can be retrieved from the associated Engauge Hub environment .env file.

ENGAUGE_DB_HOST=
ENGAUGE_DB_PORT=
ENGAUGE_DB_DATABASE=
ENGAUGE_DB_USERNAME=
ENGAUGE_DB_PASSWORD=

Engauge User model

We first ensure that we have access to the Engauge Hub users to enable user matching. This model links to the user table on the mysql_engauge connection and is called EngaugeUser.

Engauge Session model

The Engauge Session model allows us to access the sessions from the Engauge Hub. When retrieving the sessions for a particular user we need to make sure we run the manipulations to ensure we are taking into account the different system user_ids. To handle this we use a specific scope that handles the conversion.

Engauge User Scope

The Engauge User scope returns the sessions for an Envoy user from the Engauge Hub via the Engauge User model.

public function scopeOfEngaugeUser($query, $user_id) {
    // Custom logic to manipulate the user data
}

In order to collect the sessions for an Envoy user we can just use the scope and the Envoy user ID:

$user = auth()->user();
$engauge_sessions = EngaugeSession::ofEngaugeUser($user->id)->get();

Read only trait

Both the EngaugeSession & EngaugeUser models have a ReadOnlyTrait to prevent erroneous changes from Envoy to Engauge