From 60cf5d44167851a3a7b6ac1493f8d473471bc41d Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Thu, 21 Apr 2022 02:39:22 +0000 Subject: [PATCH] Bug 30326: (follow-up) Add output parameter and handle bad biblionumbers When the script is run without the --html parameter, the output will be simply text. When the script is run with the --html parameter, the output will display in an HTML table. Additional test plan: 5. Test running script with and without --html parameter and confirm output is correct. 6. Test running script with a --bibnum that does not exist and confirm the output acknowledges this. --- misc/cronjobs/check_marc_errors.pl | 40 ++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/misc/cronjobs/check_marc_errors.pl b/misc/cronjobs/check_marc_errors.pl index 24b8b350ac..ccd0080795 100755 --- a/misc/cronjobs/check_marc_errors.pl +++ b/misc/cronjobs/check_marc_errors.pl @@ -45,6 +45,10 @@ Check a specified biblio for MARC errors. Can be repeated to use with multiple b URL for Koha staff client. Required for the results to print a handy link to the record with the warning. Must include a trailing slash and a complete URL. +=item B<--html> + +Flag to output results in HTML format + =back =cut @@ -58,22 +62,24 @@ use Koha::Biblios; my @bibnum; my $intranet; +my $html; GetOptions( '+bibnum=i' => \@bibnum, 'intranet=s' => \$intranet, + 'html' => \$html, ); my $count = 0; -print "\n\n
\n"; +print "\n\n
\n
" if $html; # checking MARC errors for specific records only if ( @bibnum ) { foreach my $id ( @bibnum ) { my $record = GetMarcBiblio({ biblionumber => $id }); - my $warning = lint_record( $record ); + my $warning = $record ? lint_record( $record ) : "Record does not exist."; my $detail_uri = "cgi-bin/koha/catalogue/detail.pl?biblionumber="; report( $id, $warning, $detail_uri ); } @@ -86,13 +92,13 @@ if ( @bibnum ) { while ( my ( $biblionumber ) = $sth->fetchrow ) { my $record = GetMarcBiblio({ biblionumber => $biblionumber }); - my $warning = lint_record( $record ); + my $warning = $record ? lint_record( $record ) : "Record does not exist."; my $detail_uri = "cgi-bin/koha/catalogue/detail.pl?biblionumber="; report( $biblionumber, $warning, $detail_uri ); } } -print "
\n
\n\n"; +print "\n\n\n" if $html; sub lint_record { my $record = shift; @@ -105,19 +111,23 @@ sub lint_record { sub report { my ( $id, $warning, $detail_uri ) = @_; if ( $warning ) { - my $string = "\n"; $count++; - $string .= "" . $count . "\n"; - if ( $intranet ) { - $string .= "$id\n"; + if ( $html ) { + my $string = "\n"; + $string .= "" . $count . ".\n"; + if ( $intranet ) { + $string .= "$id\n"; + } else { + $string .= "" . $id . "\n"; + } + $string .= "" . $warning . "\n\n"; + print $string; } else { - $string .= "" . $id . "\n"; + print "$count.\t$id\t$warning\n"; } - $string .= "" . $warning . "\n\n"; - print $string; } } -- 2.11.0