]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/reporter/find_orphaned_reports.pl
Add the ability to generate live-db-setup.pl to eg_db_config.pl
[Evergreen.git] / Open-ILS / src / reporter / find_orphaned_reports.pl
1 #!/usr/bin/perl -w
2
3 use DBI;
4 use Getopt::Long;
5 use OpenSRF::EX qw/:try/;
6 use OpenSRF::Utils qw/:daemon/;
7 use OpenSRF::System;
8 use OpenSRF::AppSession;
9 use OpenSRF::Utils::SettingsClient;
10 use OpenILS::Reporter::SQLBuilder;
11 use File::Find;
12
13 my ($config, $du, $live, %seen) = ('SYSCONFDIR/bootstrap.conf', 0, 0);
14
15 GetOptions(
16         "boostrap=s"    => \$config,
17         "du"    => \$du,
18         "live"  => \$live,
19 );
20
21 OpenSRF::System->bootstrap_client( config_file => $config );
22
23 my $sc = OpenSRF::Utils::SettingsClient->new;
24 my $db_driver = $sc->config_value( reporter => setup => database => 'driver' );
25 my $db_host = $sc->config_value( reporter => setup => database => 'host' );
26 my $db_port = $sc->config_value( reporter => setup => database => 'port' );
27 my $db_name = $sc->config_value( reporter => setup => database => 'name' );
28 my $db_user = $sc->config_value( reporter => setup => database => 'user' );
29 my $db_pw = $sc->config_value( reporter => setup => database => 'password' );
30
31 my $output_base = $sc->config_value( reporter => setup => files => 'output_base' );
32
33 my $dsn = "dbi:" . $db_driver . ":dbname=" . $db_name .';host=' . $db_host . ';port=' . $db_port;
34
35 my $dbh = DBI->connect($dsn,$db_user,$db_pw, {pg_enable_utf8 => 1, RaiseError => 1});
36
37 find(\&wanted, $output_base);
38
39 $dbh->disconnect;
40
41
42 sub wanted {
43         my $dir = $File::Find::dir;
44         $dir =~ s/^$output_base//;
45         $dir =~ s#^/+##;
46         $dir =~ s#/+$##;
47         my @list = split '/', $dir;
48         return unless @list == 3;
49         return if $seen{$list[2]};
50         $seen{$list[2]} = 1;
51
52         if ($dbh->selectrow_array("SELECT id FROM reporter.schedule WHERE id = $list[2];")) {
53                 print STDERR "$output_base/" . join('/', @list) . ( $du ? "\0" : "\n" ) if ($live);
54         } else {
55                 print "$output_base/" . join('/', @list) . ( $du ? "\0" : "\n" );
56         }
57
58         if ($dbh->selectrow_array("SELECT id FROM reporter.report WHERE id = $list[1];")) {
59                 print STDERR "$output_base/" . join('/', @list[0,1]) . ( $du ? "\0" : "\n" ) if ($live);
60         } else {
61                 print "$output_base/" . join('/', @list[0,1]) . ( $du ? "\0" : "\n" );
62         }
63
64         if ($dbh->selectrow_array("SELECT id FROM reporter.template WHERE id = $list[0];")) {
65                 print STDERR "$output_base/" . $list[0] . ( $du ? "\0" : "\n" ) if ($live);
66         } else {
67                 print "$output_base/" . $list[0] . ( $du ? "\0" : "\n" );
68         }
69 }
70
71