From 5a96e79b2d75c81f885bb4753af40af4facb07c8 Mon Sep 17 00:00:00 2001 From: mxbeaulieu Date: Mon, 9 Mar 2015 14:57:10 -0400 Subject: [PATCH] check-url's --html option prints directly to a file instead of stdout. This change makes the option behave more like other cronjob's --html or --csv options. It also makes the script silent while printing html, as nothing is printed to stdout unless the verbose option is passed. The script's behaviour is not changed when launched without options. (Prints in stdout) sponsored by: CCSR http://bugs.koha-community.org/show_bug.cgi?id=13811 --- misc/cronjobs/check-url.pl | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/misc/cronjobs/check-url.pl b/misc/cronjobs/check-url.pl index 589a4c5..c39fd09 100755 --- a/misc/cronjobs/check-url.pl +++ b/misc/cronjobs/check-url.pl @@ -155,20 +155,20 @@ my $verbose = 0; my $help = 0; my $host = ''; my $host_pro = ''; -my $html = 0; +my $html = ''; my $uriedit = "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber="; my $agent = ''; my $timeout = 15; GetOptions( 'verbose' => \$verbose, - 'html' => \$html, + 'html:s' => \$html, 'help' => \$help, 'host=s' => \$host, 'host-pro=s' => \$host_pro, 'agent=s' => \$agent, 'timeout=i', => \$timeout, ); - +my $htmlfh; sub usage { pod2usage( -verbose => 2 ); @@ -195,8 +195,8 @@ sub check_all_url { my $sth = $dbh->prepare( "SELECT biblionumber FROM biblioitems WHERE url <> ''" ); $sth->execute; - if ( $html ) { - print < @@ -207,16 +207,17 @@ EOS next unless $result; # No URL foreach my $url ( @$result ) { if ( ! $url->{ is_success } || $verbose ) { - print $html - ? "\n\n\n\n\n\n" - : "$biblionumber\t" . $url->{ url } . "\t" . - $url->{ status } . "\n"; + if($htmlfh){ + my $message = "\n\n\n\n\n\n"; + print $htmlfh $message; + } + print "$biblionumber\t$url->{ url }\t$url->{ status }\n" if (!$htmlfh || $verbose); } } } - print "
" . bibediturl( $biblionumber ) . - "" . $url->{url} . "" . - $url->{status} . "
" . bibediturl( $biblionumber ) . + "" . $url->{url} . "" . + $url->{status} . "
\n\n\n" if $html; + print $htmlfh "\n\n\n" if $htmlfh; } @@ -233,8 +234,11 @@ if ( $html && !$host_pro ) { exit; } } - -check_all_url(); +if($html){ + open($htmlfh, '>', $html) or die $!; +} +check_all_url(); +close $htmlfh if $htmlfh; -- 1.7.9.5