X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fh_cust_svc.pm;h=d280d53fe6d09c53aceb1dc7d8c014b23be37704;hb=f9a181e4c2e505df84de16190ee3b75011326f3f;hp=dbb16a292d9ec3176749400746f1fbd55e804891;hpb=60e238561db85ef177934640caab3c02694afb3f;p=freeside.git diff --git a/FS/FS/h_cust_svc.pm b/FS/FS/h_cust_svc.pm index dbb16a292..d280d53fe 100644 --- a/FS/FS/h_cust_svc.pm +++ b/FS/FS/h_cust_svc.pm @@ -9,7 +9,7 @@ use FS::cust_svc; @ISA = qw( FS::h_Common FS::cust_svc ); -$DEBUG = 1; +$DEBUG = 0; sub table { 'h_cust_svc'; } @@ -28,19 +28,41 @@ inherits from FS::h_Common and FS::cust_svc. =over 4 +=item date_deleted + +Returns the date this service was deleted, if any. + +=cut + +sub date_deleted { + my $self = shift; + $self->h_date('delete'); +} + =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) { @@ -49,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 ' . @@ -80,13 +102,51 @@ sub h_svc_x { "h_$svcdb", { 'svcnum' => $self->svcnum, }, "FS::h_$svcdb"->sql_h_searchs(@_), - ) || $self->SUPER::svc_x - or die "no history ${svcdb}.svcnum for cust_svc.svcnum ". $self->svcnum; + ) || $self->SUPER::svc_x; - carp "Using $svcdb in place of missing h_${svcdb} record." - if ($svc_x->isa('FS::' . $svcdb) and $DEBUG); + if ($svc_x) { + carp "Using $svcdb in place of missing h_${svcdb} record." + if ($svc_x->isa('FS::' . $svcdb) and $DEBUG); + return $svc_x; + } else { + return ''; + } + +} - return $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; }