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 ] [ LOCALE ]
44 Returns a label for this historical service, if the service was created
45 before END_TIMESTAMP and (optionally) not deleted before START_TIMESTAMP.
46 Otherwise, 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), optionally localized
50 - A meaningful identifier (username, domain, or mail alias)
51 - The table name (i.e. svc_domain) for this historical service
55 sub label { shift->_label('svc_label', @_); }
56 sub label_long { shift->_label('svc_label_long', @_); }
58 # Parameters to _label:
60 # 1: the cust_svc method we should call to produce the label. (svc_label
61 # and svc_label_long are defined in FS::cust_svc, not here, and take a svc_x
62 # object as first argument.)
63 # 2, 3: date range to use to find the h_svc_x, which will be passed to
64 # svc_label(_long) and eventually have ->label called on it.
65 # 4: locale, passed to svc_label(_long) also.
67 # however, if label is called with a locale only, must DTRT (this is a
68 # FS::cust_svc subclass)
73 my ($end, $start, $locale);
75 if ( $_[0] =~ /^\d+$/ ) {
76 ($end, $start, $locale) = @_;
79 $end = $self->history_date;
83 #carp "FS::h_cust_svc::_label called on $self" if $DEBUG;
84 warn "FS::h_cust_svc::_label called on $self for $method" if $DEBUG;
85 my $svc_x = $self->h_svc_x($end, $start);
86 return () unless $svc_x;
87 my $part_svc = $self->part_svc;
90 carp "can't find h_". $self->part_svc->svcdb. '.svcnum '. $self->svcnum if $DEBUG;
91 return $part_svc->svc, 'n/a', $part_svc->svcdb;
95 eval { @label = $self->$method($svc_x, $end, $start, $locale); };
98 carp 'while resolving history record for svcdb/svcnum ' .
99 $part_svc->svcdb . '/' . $self->svcnum . ': ' . $@ if $DEBUG;
100 return $part_svc->svc, 'n/a', $part_svc->svcdb;
107 =item h_svc_x END_TIMESTAMP [ START_TIMESTAMP ]
109 Returns the FS::h_svc_XXX object for this service as of END_TIMESTAMP (i.e.
110 an FS::h_svc_acct object or FS::h_svc_domain object, etc.) and (optionally)
111 not cancelled before START_TIMESTAMP.
115 #false laziness w/cust_pkg::h_cust_svc
118 my $svcdb = $self->part_svc->svcdb;
120 warn "requiring FS/h_$svcdb.pm" if $DEBUG;
121 require "FS/h_$svcdb.pm";
122 local($FS::Record::qsearch_qualify_columns) = 0;
123 my $svc_x = qsearchs(
125 { 'svcnum' => $self->svcnum, },
126 "FS::h_$svcdb"->sql_h_searchs(@_),
127 ) || $self->SUPER::svc_x;
130 carp "Using $svcdb in place of missing h_${svcdb} record."
131 if ($svc_x->isa('FS::' . $svcdb) and $DEBUG);
141 # Used by FS::Upgrade to migrate to a new database.
143 use FS::UID qw( driver_name dbh );
145 sub _upgrade_data { # class method
146 my ($class, %opts) = @_;
148 warn "[FS::h_cust_svc] upgrading $class\n" if $DEBUG;
150 return if driver_name =~ /^mysql/; #You can't specify target table 'h_cust_svc' for update in FROM clause
153 DELETE FROM h_cust_svc
154 WHERE history_action = 'delete'
155 AND historynum != ( SELECT min(historynum) FROM h_cust_svc AS main
156 WHERE main.history_date = h_cust_svc.history_date
157 AND main.history_user = h_cust_svc.history_user
158 AND main.svcnum = h_cust_svc.svcnum
159 AND main.svcpart = h_cust_svc.svcpart
160 AND ( main.pkgnum = h_cust_svc.pkgnum
161 OR ( main.pkgnum IS NULL AND h_cust_svc.pkgnum IS NULL )
163 AND ( main.overlimit = h_cust_svc.overlimit
164 OR ( main.overlimit IS NULL AND h_cust_svc.overlimit IS NULL )
170 my $sth = dbh->prepare($sql) or die dbh->errstr;
171 $sth->execute or die $sth->errstr;
181 L<FS::h_Common>, L<FS::cust_svc>, L<FS::Record>, schema.html from the base