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
55 sub label { shift->_label('svc_label', @_); }
56 sub label_long { shift->_label('svc_label_long', @_); }
62 #carp "FS::h_cust_svc::_label called on $self" if $DEBUG;
63 warn "FS::h_cust_svc::_label called on $self for $method" if $DEBUG;
64 my $svc_x = $self->h_svc_x(@_);
65 return () unless $svc_x;
66 my $part_svc = $self->part_svc;
69 carp "can't find h_". $self->part_svc->svcdb. '.svcnum '. $self->svcnum if $DEBUG;
70 return $part_svc->svc, 'n/a', $part_svc->svcdb;
74 eval { @label = $self->$method($svc_x, @_); };
77 carp 'while resolving history record for svcdb/svcnum ' .
78 $part_svc->svcdb . '/' . $self->svcnum . ': ' . $@ if $DEBUG;
79 return $part_svc->svc, 'n/a', $part_svc->svcdb;
86 =item h_svc_x END_TIMESTAMP [ START_TIMESTAMP ]
88 Returns the FS::h_svc_XXX object for this service as of END_TIMESTAMP (i.e. an
89 FS::h_svc_acct object or FS::h_svc_domain object, etc.) and (optionally) not
90 cancelled before START_TIMESTAMP.
94 #false laziness w/cust_pkg::h_cust_svc
97 my $svcdb = $self->part_svc->svcdb;
99 warn "requiring FS/h_$svcdb.pm" if $DEBUG;
100 require "FS/h_$svcdb.pm";
101 my $svc_x = qsearchs(
103 { 'svcnum' => $self->svcnum, },
104 "FS::h_$svcdb"->sql_h_searchs(@_),
105 ) || $self->SUPER::svc_x;
108 carp "Using $svcdb in place of missing h_${svcdb} record."
109 if ($svc_x->isa('FS::' . $svcdb) and $DEBUG);
119 # Used by FS::Upgrade to migrate to a new database.
121 use FS::UID qw( driver_name dbh );
123 sub _upgrade_data { # class method
124 my ($class, %opts) = @_;
126 warn "[FS::h_cust_svc] upgrading $class\n" if $DEBUG;
128 return if driver_name =~ /^mysql/; #You can't specify target table 'h_cust_svc' for update in FROM clause
131 DELETE FROM h_cust_svc
132 WHERE history_action = 'delete'
133 AND historynum != ( SELECT min(historynum) FROM h_cust_svc AS main
134 WHERE main.history_date = h_cust_svc.history_date
135 AND main.history_user = h_cust_svc.history_user
136 AND main.svcnum = h_cust_svc.svcnum
137 AND main.svcpart = h_cust_svc.svcpart
138 AND ( main.pkgnum = h_cust_svc.pkgnum
139 OR ( main.pkgnum IS NULL AND h_cust_svc.pkgnum IS NULL )
141 AND ( main.overlimit = h_cust_svc.overlimit
142 OR ( main.overlimit IS NULL AND h_cust_svc.overlimit IS NULL )
148 my $sth = dbh->prepare($sql) or die dbh->errstr;
149 $sth->execute or die $sth->errstr;
159 L<FS::h_Common>, L<FS::cust_svc>, L<FS::Record>, schema.html from the base