From 4b1d18116425eed9573b17b053bec071b85ae165 Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 6 Dec 2007 01:29:18 +0000 Subject: [PATCH] script to find and list orphaned output, report and template directories for removal git-svn-id: svn://svn.open-ils.org/ILS/trunk@8157 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/reporter/find_orphaned_reports.pl | 71 ++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 Open-ILS/src/reporter/find_orphaned_reports.pl diff --git a/Open-ILS/src/reporter/find_orphaned_reports.pl b/Open-ILS/src/reporter/find_orphaned_reports.pl new file mode 100755 index 0000000000..ec9a89f0b9 --- /dev/null +++ b/Open-ILS/src/reporter/find_orphaned_reports.pl @@ -0,0 +1,71 @@ +#!/usr/bin/perl -w + +use DBI; +use Getopt::Long; +use OpenSRF::EX qw/:try/; +use OpenSRF::Utils qw/:daemon/; +use OpenSRF::System; +use OpenSRF::AppSession; +use OpenSRF::Utils::SettingsClient; +use OpenILS::Reporter::SQLBuilder; +use File::Find; + +my ($config, $du, $live, %seen) = ('/openils/conf/bootstrap.conf', 0, 0); + +GetOptions( + "boostrap=s" => \$config, + "du" => \$du, + "live" => \$live, +); + +OpenSRF::System->bootstrap_client( config_file => $config ); + +my $sc = OpenSRF::Utils::SettingsClient->new; +my $db_driver = $sc->config_value( reporter => setup => database => 'driver' ); +my $db_host = $sc->config_value( reporter => setup => database => 'host' ); +my $db_port = $sc->config_value( reporter => setup => database => 'port' ); +my $db_name = $sc->config_value( reporter => setup => database => 'name' ); +my $db_user = $sc->config_value( reporter => setup => database => 'user' ); +my $db_pw = $sc->config_value( reporter => setup => database => 'password' ); + +my $output_base = $sc->config_value( reporter => setup => files => 'output_base' ); + +my $dsn = "dbi:" . $db_driver . ":dbname=" . $db_name .';host=' . $db_host . ';port=' . $db_port; + +my $dbh = DBI->connect($dsn,$db_user,$db_pw, {pg_enable_utf8 => 1, RaiseError => 1}); + +find(\&wanted, $output_base); + +$dbh->disconnect; + + +sub wanted { + my $dir = $File::Find::dir; + $dir =~ s/^$output_base//; + $dir =~ s#^/+##; + $dir =~ s#/+$##; + my @list = split '/', $dir; + return unless @list == 3; + return if $seen{$list[2]}; + $seen{$list[2]} = 1; + + if ($dbh->selectrow_array("SELECT id FROM reporter.schedule WHERE id = $list[2];")) { + print STDERR "$output_base/" . join('/', @list) . ( $du ? "\0" : "\n" ) if ($live); + } else { + print "$output_base/" . join('/', @list) . ( $du ? "\0" : "\n" ); + } + + if ($dbh->selectrow_array("SELECT id FROM reporter.report WHERE id = $list[1];")) { + print STDERR "$output_base/" . join('/', @list[0,1]) . ( $du ? "\0" : "\n" ) if ($live); + } else { + print "$output_base/" . join('/', @list[0,1]) . ( $du ? "\0" : "\n" ); + } + + if ($dbh->selectrow_array("SELECT id FROM reporter.template WHERE id = $list[0];")) { + print STDERR "$output_base/" . $list[0] . ( $du ? "\0" : "\n" ) if ($live); + } else { + print "$output_base/" . $list[0] . ( $du ? "\0" : "\n" ); + } +} + + -- 2.11.0