summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorkhoff <khoff>2005-03-31 00:53:45 +0000
committerkhoff <khoff>2005-03-31 00:53:45 +0000
commit4c1c6a0dcce4f2082faf33ae8c56c4858af1bb45 (patch)
treeaee82ae50dd3c362ce3198661a9d492667d28e04 /bin
parentf2b7c7f426a07fea78b7faadeeba69eedcc1b84c (diff)
(Apparently) working version. Updates svc_*, cust_svc, and domain_record history tables.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/add-history-records.pl67
1 files changed, 43 insertions, 24 deletions
diff --git a/bin/add-history-records.pl b/bin/add-history-records.pl
index 16f91a18f..18c473d46 100755
--- a/bin/add-history-records.pl
+++ b/bin/add-history-records.pl
@@ -4,42 +4,61 @@
use strict;
use FS::UID qw(adminsuidsetup);
use FS::Record qw(qsearchs qsearch);
-use FS::svc_domain;
-use FS::h_svc_domain;
-use FS::domain_record;
-use FS::h_domain_record;
use Data::Dumper;
-adminsuidsetup(shift);
+my @tables = qw(svc_acct svc_broadband svc_domain svc_external svc_forward svc_www cust_svc domain_record);
+my $user = shift or die &usage;
+my $dbh = adminsuidsetup($user);
-my $svcnum = shift;
+my $dbdef = FS::Record::dbdef;
-my $svc_domain = qsearchs('svc_domain', { svcnum => $svcnum }) or die "no svcnum '$svcnum'";
+foreach my $table (@tables) {
-my $h_svc_domain = qsearchs(
- 'h_svc_domain',
- { 'svcnum' => $svc_domain->svcnum },
- FS::h_svc_domain->sql_h_searchs(time),
-);
+ my $h_table = 'h_' . $table;
+ my $cnt = 0;
+ my $t_cnt = 0;
-unless ($h_svc_domain) {
- print $svc_domain->_h_statement('insert', 1) . "\n";
-}
+ eval "use FS::${table}";
+ die $@ if $@;
+ eval "use FS::${h_table}";
+ die $@ if $@;
+
+ print "Adding history records for ${table}...\n";
+
+ my $dbdef_table = $dbdef->table($table);
+ my $pkey = $dbdef_table->primary_key;
+
+ foreach my $rec (qsearch($table, {})) {
+
+ my $h_rec = qsearchs(
+ $h_table,
+ { $pkey => $rec->getfield($pkey) },
+ eval "FS::${h_table}->sql_h_searchs(time)",
+ );
-foreach my $rec ($svc_domain->domain_record) {
- my $h_rec = qsearchs(
- 'h_domain_record',
- { 'svcnum' => $svc_domain->svcnum },
- FS::h_domain_record->sql_h_searchs(time),
- );
+ unless ($h_rec) {
+ my $h_insert_rec = $rec->_h_statement('insert', 1);
+ #print $h_insert_rec . "\n";
+ $dbh->do($h_insert_rec);
+ die $dbh->errstr if $dbh->err;
+ $cnt++;
+ }
- #print Dumper($h_rec);
- unless ($h_rec) {
- print $rec->_h_statement('insert', 1) . "\n";
+ $t_cnt++;
+
}
+ print "History records inserted into $h_table: $cnt\n";
+ print " Total records in $table: $t_cnt\n";
+
+ print "\n";
+
+}
+
+sub usage {
+ die "Usage:\n add-history-records.pl user\n";
}