blob: 14d72316f7a6a71cabbb9c1065bb0eee72506f4c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/usr/bin/perl
use strict;
use FS::UID qw(adminsuidsetup);
use FS::Record qw(qsearchs qsearch);
use Data::Dumper;
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 $dbdef = FS::Record::dbdef;
foreach my $table (@tables) {
my $h_table = 'h_' . $table;
my $cnt = 0;
my $t_cnt = 0;
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)",
);
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;
$dbh->commit or die $dbh->errstr;
$cnt++;
}
$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";
}
|