X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fh_cust_svc.pm;h=7b565adde5285dc191f0cff9638e98c4eaabe0f4;hb=3cbdd85a96348a287623e3b97c937c7749e99392;hp=8cee68a14024c31c2a20522d8eb0c57b66e9b9e6;hpb=682ee3e4f99ab79e40978843aa2be37bc74b2247;p=freeside.git diff --git a/FS/FS/h_cust_svc.pm b/FS/FS/h_cust_svc.pm index 8cee68a14..7b565adde 100644 --- a/FS/FS/h_cust_svc.pm +++ b/FS/FS/h_cust_svc.pm @@ -41,17 +41,28 @@ 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 =cut -sub label { +sub label { shift->_label('svc_label', @_); } +sub label_long { shift->_label('svc_label_long', @_); } + +sub _label { my $self = shift; - carp "FS::h_cust_svc::label called on $self" if $DEBUG; + my $method = shift; + + #carp "FS::h_cust_svc::_label called on $self" if $DEBUG; + warn "FS::h_cust_svc::_label called on $self for $method" if $DEBUG; my $svc_x = $self->h_svc_x(@_); + return () unless $svc_x; my $part_svc = $self->part_svc; unless ($svc_x) { @@ -60,7 +71,7 @@ sub label { } my @label; - eval { @label = $self->_svc_label($svc_x, @_); }; + eval { @label = $self->$method($svc_x, @_); }; if ($@) { carp 'while resolving history record for svcdb/svcnum ' . @@ -87,6 +98,7 @@ sub h_svc_x { warn "requiring FS/h_$svcdb.pm" if $DEBUG; require "FS/h_$svcdb.pm"; + local($FS::Record::qsearch_qualify_columns) = 0; my $svc_x = qsearchs( "h_$svcdb", { 'svcnum' => $self->svcnum, }, @@ -103,6 +115,42 @@ 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