summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2008-02-11 02:36:53 +0000
committerivan <ivan>2008-02-11 02:36:53 +0000
commit5b2d5b6114e3127afac0af44f40d009fc18ec8de (patch)
tree20e647c47c971edb4b1174ad5d1633a2350b4174
parent7add8407312ec79831adafc06caa01c0fa60f76e (diff)
fix & cleanup duplicate history records
-rw-r--r--FS/FS/Upgrade.pm2
-rw-r--r--FS/FS/cust_svc.pm20
-rw-r--r--FS/FS/h_cust_svc.pm45
3 files changed, 60 insertions, 7 deletions
diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index 55972dd..2e4d2b4 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -83,6 +83,8 @@ sub upgrade_data {
#customer credits
'cust_credit' => [],
+ #duplicate history records
+ 'h_cust_svc' => [],
;
diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm
index bcf66e7..8eecda3 100644
--- a/FS/FS/cust_svc.pm
+++ b/FS/FS/cust_svc.pm
@@ -132,22 +132,30 @@ sub cancel {
my $svc = $self->svc_x;
if ($svc) {
+
my $error = $svc->cancel;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return "Error canceling service: $error";
}
- $error = $svc->delete;
+ $error = $svc->delete; #this deletes this cust_svc record as well
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return "Error deleting service: $error";
}
- }
- my $error = $self->delete;
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return "Error deleting cust_svc: $error";
+ } else {
+
+ #huh?
+ warn "WARNING: no svc_ record found for svcnum ". $self->svcnum.
+ "; deleting cust_svc only\n";
+
+ my $error = $self->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error deleting cust_svc: $error";
+ }
+
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
diff --git a/FS/FS/h_cust_svc.pm b/FS/FS/h_cust_svc.pm
index 8cee68a..921be3a 100644
--- a/FS/FS/h_cust_svc.pm
+++ b/FS/FS/h_cust_svc.pm
@@ -41,7 +41,11 @@ sub date_deleted {
=item label END_TIMESTAMP [ START_TIMESTAMP ]
-Returns a list consisting of:
+Returns a label for this historical service, if the service was created before
+END_TIMESTAMP and (optionally) not deleted before START_TIMESTAMP. Otherwise,
+returns an empty list.
+
+If a service is found, returns a list consisting of:
- The name of this historical service (from part_svc)
- A meaningful identifier (username, domain, or mail alias)
- The table name (i.e. svc_domain) for this historical service
@@ -52,6 +56,7 @@ sub label {
my $self = shift;
carp "FS::h_cust_svc::label called on $self" if $DEBUG;
my $svc_x = $self->h_svc_x(@_);
+ return () unless $svc_x;
my $part_svc = $self->part_svc;
unless ($svc_x) {
@@ -103,6 +108,44 @@ sub h_svc_x {
}
+# _upgrade_data
+#
+# Used by FS::Upgrade to migrate to a new database.
+#
+#
+
+use FS::UID qw( driver_name dbh );
+
+sub _upgrade_data { # class method
+ my ($class, %opts) = @_;
+
+ warn "[FS::h_cust_svc] upgrading $class\n" if $DEBUG;
+
+ return if driver_name =~ /^mysql/; #You can't specify target table 'h_cust_svc' for update in FROM clause
+
+ my $sql = "
+ DELETE FROM h_cust_svc
+ WHERE history_action = 'delete'
+ AND historynum != ( SELECT min(historynum) FROM h_cust_svc AS main
+ WHERE main.history_date = h_cust_svc.history_date
+ AND main.history_user = h_cust_svc.history_user
+ AND main.svcnum = h_cust_svc.svcnum
+ AND main.svcpart = h_cust_svc.svcpart
+ AND ( main.pkgnum = h_cust_svc.pkgnum
+ OR ( main.pkgnum IS NULL AND h_cust_svc.pkgnum IS NULL )
+ )
+ AND ( main.overlimit = h_cust_svc.overlimit
+ OR ( main.overlimit IS NULL AND h_cust_svc.overlimit IS NULL )
+ )
+ )
+ ";
+
+ warn $sql if $DEBUG;
+ my $sth = dbh->prepare($sql) or die dbh->errstr;
+ $sth->execute or die $sth->errstr;
+
+}
+
=back
=head1 BUGS