freeside/bin add-history-records.pl,1.1,1.2
Kristian Hoffmann
khoff at pouncequick.420.am
Wed Mar 30 16:53:48 PST 2005
Update of /home/cvs/cvsroot/freeside/bin
In directory pouncequick:/tmp/cvs-serv4261
Modified Files:
add-history-records.pl
Log Message:
(Apparently) working version. Updates svc_*, cust_svc, and domain_record history tables.
Index: add-history-records.pl
===================================================================
RCS file: /home/cvs/cvsroot/freeside/bin/add-history-records.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- add-history-records.pl 30 Mar 2005 20:55:16 -0000 1.1
+++ add-history-records.pl 31 Mar 2005 00:53:45 -0000 1.2
@@ -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 $@;
-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),
- );
+ print "Adding history records for ${table}...\n";
- #print Dumper($h_rec);
+ 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)",
+ );
+
+ 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++;
+ }
+
+
+ $t_cnt++;
- unless ($h_rec) {
- print $rec->_h_statement('insert', 1) . "\n";
}
+ 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";
}
More information about the freeside-commits
mailing list