[freeside-commits] freeside/FS/FS Schema.pm, 1.44.2.18, 1.44.2.19 svc_acct.pm, 1.217.2.15, 1.217.2.16
Jeff Finucane,420,,
jeff at wavetail.420.am
Thu Dec 27 17:32:51 PST 2007
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv26177/FS/FS
Modified Files:
Tag: FREESIDE_1_7_BRANCH
Schema.pm svc_acct.pm
Log Message:
last login reporting (#2952)
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.44.2.18
retrieving revision 1.44.2.19
diff -u -d -r1.44.2.18 -r1.44.2.19
--- Schema.pm 4 Dec 2007 18:19:05 -0000 1.44.2.18
+++ Schema.pm 28 Dec 2007 01:32:47 -0000 1.44.2.19
@@ -973,6 +973,8 @@
'totalbytes','bigint', 'NULL', '', '', '',
'totalbytes_threshold', 'bigint', 'NULL', '', '', '',
'domsvc', 'int', '', '', '', '',
+ 'last_login', @date_type, '', '',
+ 'last_logout', @date_type, '', '',
],
'primary_key' => 'svcnum',
#'unique' => [ [ 'username', 'domsvc' ] ],
Index: svc_acct.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_acct.pm,v
retrieving revision 1.217.2.15
retrieving revision 1.217.2.16
diff -u -d -r1.217.2.15 -r1.217.2.16
--- svc_acct.pm 12 Dec 2007 05:58:15 -0000 1.217.2.15
+++ svc_acct.pm 28 Dec 2007 01:32:48 -0000 1.217.2.16
@@ -221,7 +221,7 @@
{
'name' => 'Account',
'longname_plural' => 'Access accounts and mailboxes',
- 'sorts' => [ 'username', 'uid', ],
+ 'sorts' => [ 'username', 'uid', 'last_login', ],
'display_weight' => 10,
'cancel_weight' => 50,
'fields' => {
@@ -338,6 +338,14 @@
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
},
+ 'last_login'=> {
+ label => 'Last login',
+ type => 'disabled',
+ },
+ 'last_logout'=> {
+ label => 'Last logout',
+ type => 'disabled',
+ },
},
};
}
@@ -360,6 +368,54 @@
};
}
+sub last_login {
+ shift->_lastlog('in', @_);
+}
+
+sub last_logout {
+ shift->_lastlog('out', @_);
+}
+
+sub _lastlog {
+ my( $self, $op, $time ) = @_;
+
+ if ( defined($time) ) {
+ warn "$me last_log$op called on svcnum ". $self->svcnum.
+ ' ('. $self->email. "): $time\n"
+ if $DEBUG;
+
+ local $SIG{HUP} = 'IGNORE';
+ local $SIG{INT} = 'IGNORE';
+ local $SIG{QUIT} = 'IGNORE';
+ local $SIG{TERM} = 'IGNORE';
+ local $SIG{TSTP} = 'IGNORE';
+ local $SIG{PIPE} = 'IGNORE';
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ my $sql = "UPDATE svc_acct SET last_log$op = ? WHERE svcnum = ?";
+ warn "$me $sql\n"
+ if $DEBUG;
+
+ my $sth = $dbh->prepare( $sql )
+ or die "Error preparing $sql: ". $dbh->errstr;
+ my $rv = $sth->execute($time, $self->svcnum);
+ die "Error executing $sql: ". $sth->errstr
+ unless defined($rv);
+ die "Can't update last_log$op for svcnum". $self->svcnum
+ if $rv == 0;
+
+ warn "$me update successful; committing\n"
+ if $DEBUG;
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+ $self->{'Hash'}->{"last_log$op"} = $time;
+ }else{
+ $self->getfield("last_log$op");
+ }
+}
+
=item search_sql STRING
Class method which returns an SQL fragment to search for the given string.
@@ -1862,6 +1918,17 @@
$self->cust_svc->get_session_history(@_);
}
+=item last_login_text
+
+Returns text describing the time of last login.
+
+=cut
+
+sub last_login_text {
+ my $self = shift;
+ $self->last_login ? ctime($self->last_login) : 'unknown';
+}
+
=item get_cdrs TIMESTAMP_START TIMESTAMP_END [ 'OPTION' => 'VALUE ... ]
=cut
More information about the freeside-commits
mailing list