[freeside-commits] freeside/FS/FS Upgrade.pm, 1.2, 1.3 h_cust_svc.pm, 1.7, 1.8 cust_svc.pm, 1.70, 1.71
Ivan,,,
ivan at wavetail.420.am
Sun Feb 10 18:36:56 PST 2008
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv28060/FS/FS
Modified Files:
Upgrade.pm h_cust_svc.pm cust_svc.pm
Log Message:
fix & cleanup duplicate history records
Index: h_cust_svc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/h_cust_svc.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- h_cust_svc.pm 1 Dec 2007 01:34:58 -0000 1.7
+++ h_cust_svc.pm 11 Feb 2008 02:36:53 -0000 1.8
@@ -41,7 +41,11 @@
=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 @@
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 @@
}
+# _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
Index: Upgrade.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Upgrade.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Upgrade.pm 4 Dec 2007 18:20:56 -0000 1.2
+++ Upgrade.pm 11 Feb 2008 02:36:52 -0000 1.3
@@ -83,6 +83,8 @@
#customer credits
'cust_credit' => [],
+ #duplicate history records
+ 'h_cust_svc' => [],
;
Index: cust_svc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_svc.pm,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- cust_svc.pm 1 Dec 2007 01:34:31 -0000 1.70
+++ cust_svc.pm 11 Feb 2008 02:36:53 -0000 1.71
@@ -132,22 +132,30 @@
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;
More information about the freeside-commits
mailing list