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 return "a session on that port is already open!"
98 if qsearchs('session', { 'portnum' => $self->portnum, 'logout' => '' } );
100 $self->setfield('login', time()) unless $self->getfield('login');
102 $error = $self->SUPER::insert;
103 return $error if $error;
105 $self->nas_heartbeat($self->getfield('login'));
107 #session-starting callback!
115 Delete this record from the database.
119 # the delete method can be inherited from FS::Record
121 =item replace OLD_RECORD
123 Replaces the OLD_RECORD with this one in the database. If there is an error,
124 returns the error, otherwise returns false. If the `logout' field is empty,
125 it is replaced with the current time.
130 my($self, $old) = @_;
133 local $SIG{HUP} = 'IGNORE';
134 local $SIG{INT} = 'IGNORE';
135 local $SIG{QUIT} = 'IGNORE';
136 local $SIG{TERM} = 'IGNORE';
137 local $SIG{TSTP} = 'IGNORE';
138 local $SIG{PIPE} = 'IGNORE';
140 $error = $self->check;
141 return $error if $error;
143 $self->setfield('logout', time()) unless $self->getfield('logout');
145 $error = $self->SUPER::replace($old);
146 return $error if $error;
148 $self->nas_heartbeat($self->getfield('logout'));
150 #session-ending callback!
157 Checks all fields to make sure this is a valid session. If there is
158 an error, returns the error, otherwise returns false. Called by the insert
163 # the check method should currently be supplied - FS::Record contains some
164 # data checking routines
169 $self->ut_numbern('sessionnum')
170 || $self->ut_number('portnum')
171 || $self->ut_number('svcnum')
172 || $self->ut_numbern('login')
173 || $self->ut_numbern('logout')
175 return $error if $error;
176 return "Unknown svcnum"
177 unless qsearchs('svc_acct', { 'svcnum' => $self->svcnum } );
183 Heartbeats the nas associated with this session (see L<FS::nas>).
189 my $port = qsearchs('port',{'portnum'=>$self->portnum});
190 my $nas = qsearchs('nas',{'nasnum'=>$port->nasnum});
191 $nas->heartbeat(shift);
196 Returns the svc_acct record associated with this session (see L<FS::svc_acct>).
202 qsearchs('svc_acct', { 'svcnum' => $self->svcnum } );
209 $Id: session.pm,v 1.3 2000-12-03 20:25:20 ivan Exp $
213 Maybe you shouldn't be able to insert a session if there's currently an open
214 session on that port. Or maybe the open session on that port should be flagged
215 as problematic? autoclosed? *sigh*
217 Hmm, sessions refer to current svc_acct records... probably need to constrain
218 deletions to svc_acct records such that no svc_acct records are deleted which
219 have a session (even if long-closed).
223 L<FS::Record>, schema.html from the base documentation.