Freeside:1.7:Documentation:Developer/FS/session

From Freeside
Jump to: navigation, search

NAME

FS::session - Object methods for session records

SYNOPSIS

 use FS::session;

 $record = new FS::session \%hash;
 $record = new FS::session {
   'portnum' => 1,
   'svcnum'  => 2,
   'login'   => $timestamp,
   'logout'  => $timestamp,
 };

 $error = $record->insert;

 $error = $new_record->replace($old_record);

 $error = $record->delete;

 $error = $record->check;

 $error = $record->nas_heartbeat($timestamp);

DESCRIPTION

An FS::session object represents an user login session. FS::session inherits from FS::Record. The following fields are currently supported:

sessionnum - primary key; portnum - NAS port for this session - see FS::port; svcnum - User for this session - see FS::svc_acct; login - timestamp indicating the beginning of this user session.; logout - timestamp indicating the end of this user session. May be null, which indicates a currently open session.

METHODS

new HASHREF
Creates a new session. To add the session to the database, see "insert".
Note that this stores the hash reference, not a distinct copy of the hash it points to. You can ask the object for a copy with the hash method.
insert
Adds this record to the database. If there is an error, returns the error, otherwise returns false. If the `login' field is empty, it is replaced with the current time.
delete
Delete this record from the database.
replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error, returns the error, otherwise returns false. If the `logout' field is empty, it is replaced with the current time.
check
Checks all fields to make sure this is a valid session. If there is an error, returns the error, otherwise returns false. Called by the insert and replace methods.
nas_heartbeat
Heartbeats the nas associated with this session (see FS::nas).
svc_acct
Returns the svc_acct record associated with this session (see FS::svc_acct).

BUGS

Maybe you shouldn't be able to insert a session if there's currently an open session on that port. Or maybe the open session on that port should be flagged as problematic? autoclosed? *sigh*

Hmm, sessions refer to current svc_acct records... probably need to constrain deletions to svc_acct records such that no svc_acct records are deleted which have a session (even if long-closed).

SEE ALSO

FS::Record, schema.html from the base documentation.