[freeside-commits] freeside/FS/FS Schema.pm, 1.44.2.2, 1.44.2.3 cust_svc.pm, 1.66, 1.66.2.1 svc_acct.pm, 1.217.2.4, 1.217.2.5 svc_Common.pm, 1.39, 1.39.2.1 cust_pkg.pm, 1.73.2.1, 1.73.2.2
Jeff Finucane,420,,
jeff at wavetail.420.am
Tue Apr 10 21:29:51 PDT 2007
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv15232/FS/FS
Modified Files:
Tag: FREESIDE_1_7_BRANCH
Schema.pm cust_svc.pm svc_acct.pm svc_Common.pm cust_pkg.pm
Log Message:
usage suspend vs admin suspend -- avoid actual cust_pkg::suspend except legacy cases (backport)
Index: svc_Common.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_Common.pm,v
retrieving revision 1.39
retrieving revision 1.39.2.1
diff -u -d -r1.39 -r1.39.2.1
--- svc_Common.pm 29 Dec 2006 08:51:32 -0000 1.39
+++ svc_Common.pm 11 Apr 2007 04:29:48 -0000 1.39.2.1
@@ -735,6 +735,17 @@
}
+=item overlimit
+
+Sets or retrieves overlimit date.
+
+=cut
+
+sub overlimit {
+ my $self = shift;
+ $self->cust_svc->overlimit(@_);
+}
+
=item cancel
Stub - returns false (no error) so derived classes don't need to define this
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.44.2.2
retrieving revision 1.44.2.3
diff -u -d -r1.44.2.2 -r1.44.2.3
--- Schema.pm 6 Apr 2007 19:41:57 -0000 1.44.2.2
+++ Schema.pm 11 Apr 2007 04:29:48 -0000 1.44.2.3
@@ -722,6 +722,7 @@
'svcnum', 'serial', '', '', '', '',
'pkgnum', 'int', 'NULL', '', '', '',
'svcpart', 'int', '', '', '', '',
+ 'overlimit', @date_type, '', '',
],
'primary_key' => 'svcnum',
'unique' => [],
Index: svc_acct.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_acct.pm,v
retrieving revision 1.217.2.4
retrieving revision 1.217.2.5
diff -u -d -r1.217.2.4 -r1.217.2.5
--- svc_acct.pm 8 Apr 2007 01:18:55 -0000 1.217.2.4
+++ svc_acct.pm 11 Apr 2007 04:29:48 -0000 1.217.2.5
@@ -1535,7 +1535,7 @@
if ( &{$op2condition{$op}}($self, $column, $amount) ) {
foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
- if ($part_export->option('overlimit_groups')) {
+ if ($part_export->option('overlimit_groups'), 1) {
my ($new,$old);
my $other = new FS::svc_acct $self->hashref;
my $groups = &{ $self->_fieldhandlers->{'usergroup'} }
@@ -1547,6 +1547,7 @@
$new = $self; $old = $other;
}
my $error = $part_export->export_replace($new, $old);
+ $error ||= $self->overlimit($action);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return "Error replacing radius groups in export, ${op}: $error";
@@ -1559,6 +1560,7 @@
&& &{$op2condition{$op}}($self, $column, $amount) ) {
#my $error = $self->$action();
my $error = $self->cust_svc->cust_pkg->$action();
+ $error ||= $self->overlimit($action);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return "Error ${action}ing: $error";
@@ -1652,8 +1654,22 @@
if $rv == 0;
}
- if ( $conf->exists("svc_acct-usage_unsuspend") && $reset ) {
- my $error = $self->cust_svc->cust_pkg->unsuspend;
+ if ( $reset ) {
+ my $error = $self->overlimit('unsuspend');
+
+ foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
+ if ($part_export->option('overlimit_groups'), 1) {
+ my $old = new FS::svc_acct $self->hashref;
+ my $groups = &{ $self->_fieldhandlers->{'usergroup'} }
+ ($self, $part_export->option('overlimit_groups'));
+ $old->usergroup( $groups );
+ $error ||= $part_export->export_replace($self, $old);
+ }
+ }
+
+ if ( $conf->exists("svc_acct-usage_unsuspend")) {
+ $error ||= $self->cust_svc->cust_pkg->unsuspend;
+ }
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return "Error unsuspending: $error";
Index: cust_svc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_svc.pm,v
retrieving revision 1.66
retrieving revision 1.66.2.1
diff -u -d -r1.66 -r1.66.2.1
--- cust_svc.pm 29 Dec 2006 08:51:32 -0000 1.66
+++ cust_svc.pm 11 Apr 2007 04:29:48 -0000 1.66.2.1
@@ -68,6 +68,8 @@
=item svcpart - Service definition (see L<FS::part_svc>)
+=item overlimit - date the service exceeded its usage limit
+
=back
=head1 METHODS
@@ -154,6 +156,54 @@
}
+=item overlimit [ ACTION ]
+
+Retrieves or sets the overlimit date. If ACTION is absent, return
+the present value of overlimit. If ACTION is present, it can
+have the value 'suspend' or 'unsuspend'. In the case of 'suspend' overlimit
+is set to the current time if it is not already set. The 'unsuspend' value
+causes the time to be cleared.
+
+If there is an error on setting, returns the error, otherwise returns false.
+
+=cut
+
+sub overlimit {
+ my $self = shift;
+ my $action = shift or return $self->getfield('overlimit');
+
+ 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;
+
+ if ( $action eq 'suspend' ) {
+ $self->setfield('overlimit', time) unless $self->getfield('overlimit');
+ }elsif ( $action eq 'unsuspend' ) {
+ $self->setfield('overlimit', '');
+ }else{
+ die "unexpected action value: $action";
+ }
+
+ local $ignore_quantity = 1;
+ my $error = $self->replace;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error setting overlimit: $error";
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+ ''; #no errors
+
+}
+
=item replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error,
@@ -175,6 +225,8 @@
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
+ $old = $new->replace_old unless defined($old);
+
if ( $new->svcpart != $old->svcpart ) {
my $svc_x = $new->svc_x;
my $new_svc_x = ref($svc_x)->new({$svc_x->hash, svcpart=>$new->svcpart });
@@ -212,6 +264,7 @@
$self->ut_numbern('svcnum')
|| $self->ut_numbern('pkgnum')
|| $self->ut_number('svcpart')
+ || $self->ut_numbern('overlimit')
;
return $error if $error;
Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.73.2.1
retrieving revision 1.73.2.2
diff -u -d -r1.73.2.1 -r1.73.2.2
--- cust_pkg.pm 13 Mar 2007 09:21:36 -0000 1.73.2.1
+++ cust_pkg.pm 11 Apr 2007 04:29:48 -0000 1.73.2.2
@@ -799,6 +799,19 @@
}
+=item overlimit [ SVCPART ]
+
+Returns the services for this package which have exceeded their
+usage limit as FS::cust_svc objects (see L<FS::cust_svc>). If a svcpart
+is specified, return only the matching services.
+
+=cut
+
+sub overlimit {
+ my $self = shift;
+ grep { $_->overlimit } $self->cust_svc;
+}
+
=item h_cust_svc END_TIMESTAMP [ START_TIMESTAMP ]
Returns historical services for this package created before END TIMESTAMP and
More information about the freeside-commits
mailing list