1 package FS::h_cust_svc;
4 use vars qw( @ISA $DEBUG );
6 use FS::Record qw(qsearchs);
10 @ISA = qw( FS::h_Common FS::cust_svc );
14 sub table { 'h_cust_svc'; }
18 FS::h_cust_svc - Object method for h_cust_svc objects
24 An FS::h_cust_svc object represents a historical service. FS::h_cust_svc
25 inherits from FS::h_Common and FS::cust_svc.
33 Returns the date this service was deleted, if any.
39 $self->h_date('delete');
42 =item label END_TIMESTAMP [ START_TIMESTAMP ]
44 Returns a label for this historical service, if the service was created before
45 END_TIMESTAMP and (optionally) not deleted before START_TIMESTAMP. Otherwise,
46 returns an empty list.
48 If a service is found, returns a list consisting of:
49 - The name of this historical service (from part_svc)
50 - A meaningful identifier (username, domain, or mail alias)
51 - The table name (i.e. svc_domain) for this historical service
57 carp "FS::h_cust_svc::label called on $self" if $DEBUG;
58 my $svc_x = $self->h_svc_x(@_);
59 return () unless $svc_x;
60 my $part_svc = $self->part_svc;
63 carp "can't find h_". $self->part_svc->svcdb. '.svcnum '. $self->svcnum if $DEBUG;
64 return $part_svc->svc, 'n/a', $part_svc->svcdb;
68 eval { @label = $self->_svc_label($svc_x, @_); };
71 carp 'while resolving history record for svcdb/svcnum ' .
72 $part_svc->svcdb . '/' . $self->svcnum . ': ' . $@ if $DEBUG;
73 return $part_svc->svc, 'n/a', $part_svc->svcdb;
80 =item h_svc_x END_TIMESTAMP [ START_TIMESTAMP ]
82 Returns the FS::h_svc_XXX object for this service as of END_TIMESTAMP (i.e. an
83 FS::h_svc_acct object or FS::h_svc_domain object, etc.) and (optionally) not
84 cancelled before START_TIMESTAMP.
88 #false laziness w/cust_pkg::h_cust_svc
91 my $svcdb = $self->part_svc->svcdb;
93 warn "requiring FS/h_$svcdb.pm" if $DEBUG;
94 require "FS/h_$svcdb.pm";
97 { 'svcnum' => $self->svcnum, },
98 "FS::h_$svcdb"->sql_h_searchs(@_),
99 ) || $self->SUPER::svc_x;
102 carp "Using $svcdb in place of missing h_${svcdb} record."
103 if ($svc_x->isa('FS::' . $svcdb) and $DEBUG);
113 # Used by FS::Upgrade to migrate to a new database.
117 use FS::UID qw( driver_name dbh );
119 sub _upgrade_data { # class method
120 my ($class, %opts) = @_;
122 warn "[FS::h_cust_svc] upgrading $class\n" if $DEBUG;
124 return if driver_name =~ /^mysql/; #You can't specify target table 'h_cust_svc' for update in FROM clause
127 DELETE FROM h_cust_svc
128 WHERE history_action = 'delete'
129 AND historynum != ( SELECT min(historynum) FROM h_cust_svc AS main
130 WHERE main.history_date = h_cust_svc.history_date
131 AND main.history_user = h_cust_svc.history_user
132 AND main.svcnum = h_cust_svc.svcnum
133 AND main.svcpart = h_cust_svc.svcpart
134 AND ( main.pkgnum = h_cust_svc.pkgnum
135 OR ( main.pkgnum IS NULL AND h_cust_svc.pkgnum IS NULL )
137 AND ( main.overlimit = h_cust_svc.overlimit
138 OR ( main.overlimit IS NULL AND h_cust_svc.overlimit IS NULL )
144 my $sth = dbh->prepare($sql) or die dbh->errstr;
145 $sth->execute or die $sth->errstr;
155 L<FS::h_Common>, L<FS::cust_svc>, L<FS::Record>, schema.html from the base