5 use FS::Record qw( qsearchs );
10 @ISA = qw(FS::Record);
14 FS::session - Object methods for session records
20 $record = new FS::session \%hash;
21 $record = new FS::session {
24 'login' => $timestamp,
25 'logout' => $timestamp,
28 $error = $record->insert;
30 $error = $new_record->replace($old_record);
32 $error = $record->delete;
34 $error = $record->check;
36 $error = $record->nas_heartbeat($timestamp);
40 An FS::session object represents an user login session. FS::session inherits
41 from FS::Record. The following fields are currently supported:
45 =item sessionnum - primary key
47 =item portnum - NAS port for this session - see L<FS::port>
49 =item svcnum - User for this session - see L<FS::svc_acct>
51 =item login - timestamp indicating the beginning of this user session.
53 =item logout - timestamp indicating the end of this user session. May be null,
54 which indicates a currently open session.
64 Creates a new session. To add the session to the database, see L<"insert">.
66 Note that this stores the hash reference, not a distinct copy of the hash it
67 points to. You can ask the object for a copy with the I<hash> method.
71 # the new method can be inherited from FS::Record, if a table method is defined
73 sub table { 'session'; }
77 Adds this record to the database. If there is an error, returns the error,
78 otherwise returns false. If the `login' field is empty, it is replaced with
87 local $SIG{HUP} = 'IGNORE';
88 local $SIG{INT} = 'IGNORE';
89 local $SIG{QUIT} = 'IGNORE';
90 local $SIG{TERM} = 'IGNORE';
91 local $SIG{TSTP} = 'IGNORE';
92 local $SIG{PIPE} = 'IGNORE';
94 $error = $self->check;
95 return $error if $error;
97 $self->setfield('login', time()) unless $self->getfield('login');
99 $error = $self->SUPER::insert;
100 return $error if $error;
102 $self->nas_heartbeat($self->getfield('login'));
104 #session-starting callback!
112 Delete this record from the database.
116 # the delete method can be inherited from FS::Record
118 =item replace OLD_RECORD
120 Replaces the OLD_RECORD with this one in the database. If there is an error,
121 returns the error, otherwise returns false. If the `logout' field is empty,
122 it is replaced with the current time.
130 local $SIG{HUP} = 'IGNORE';
131 local $SIG{INT} = 'IGNORE';
132 local $SIG{QUIT} = 'IGNORE';
133 local $SIG{TERM} = 'IGNORE';
134 local $SIG{TSTP} = 'IGNORE';
135 local $SIG{PIPE} = 'IGNORE';
137 $error = $self->check;
138 return $error if $error;
140 $self->setfield('logout', time()) unless $self->getfield('logout');
142 $error = $self->SUPER::replace;
143 return $error if $error;
145 $self->nas_heartbeat($self->getfield('logout'));
147 #session-ending callback!
154 Checks all fields to make sure this is a valid session. If there is
155 an error, returns the error, otherwise returns false. Called by the insert
160 # the check method should currently be supplied - FS::Record contains some
161 # data checking routines
166 $self->ut_numbern('sessionnum')
167 || $self->ut_number('portnum')
168 || $self->ut_number('svcnum')
169 || $self->ut_numbern('login')
170 || $self->ut_numbern('logout')
172 return $error if $error;
173 return "Unknown svcnum"
174 unless qsearchs('svc_acct', { 'svcnum' => $self->svcnum } );
180 Heartbeats the nas associated with this session (see L<FS::nas>).
186 my $port = qsearchs('port',{'portnum'=>$self->portnum});
187 my $nas = qsearchs('nas',{'nasnum'=>$port->nasnum});
188 $nas->heartbeat(shift);
195 $Id: session.pm,v 1.2 2000-11-07 15:00:37 ivan Exp $
199 The author forgot to customize this manpage.
203 L<FS::Record>, schema.html from the base documentation.