Bugzilla – Attachment 132053 Details for
Bug 30326
Cronjob that checks biblios for MARC errors
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30326: check_marc_errors.pl script which prints MARC errors
Bug-30326-checkmarcerrorspl-script-which-prints-MA.patch (text/plain), 6.22 KB, created by
Owen Leonard
on 2022-03-23 12:49:41 UTC
(
hide
)
Description:
Bug 30326: check_marc_errors.pl script which prints MARC errors
Filename:
MIME Type:
Creator:
Owen Leonard
Created:
2022-03-23 12:49:41 UTC
Size:
6.22 KB
patch
obsolete
>From fe71760acff0e73fedf953bbf76c192415f92d7d Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleishaamohia@hotmail.com> >Date: Tue, 22 Mar 2022 02:55:51 +0000 >Subject: [PATCH] Bug 30326: check_marc_errors.pl script which prints MARC > errors > >This new check_marc_errors.pl script uses the MARC::Lint package to >check bibliographic records for MARC errors, and print any errors >found. The script can check all biblios, or specified biblios. > >To test: > >1. Run the script from your commandline. This should not be run from > within your koha shell. Replace the --intranet parameter with your > staff client URL. > > sudo koha-shell kohadev -c "misc/cronjobs/check_marc_errors.pl --intranet http://localhost:8081/" > /tmp/marc_errors.html > >2. The above command will run the script for all biblios in your > database and print the output to a file /tmp/marc_errors.html. View > the file and confirm it has been populated as expected, with errors! > > cat /tmp/marc_errors.html > >3. Run the script again, this time specify one or more biblionumbers. > > sudo koha-shell kohadev -c "misc/cronjobs/check_marc_errors.pl --bibnum 1 --bibnum 2 --bibnum 3 --intranet http://localhost:8081/" > /tmp/marc_errors.html > >4. Confirm the file is populated as expected > > cat /tmp/marc_errors.html > >Sponsored-by: Catalyst IT > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> >--- > cpanfile | 1 + > debian/control | 2 + > misc/cronjobs/check_marc_errors.pl | 123 +++++++++++++++++++++++++++++ > 3 files changed, 126 insertions(+) > create mode 100755 misc/cronjobs/check_marc_errors.pl > >diff --git a/cpanfile b/cpanfile >index 58d812ea74..b938823579 100644 >--- a/cpanfile >+++ b/cpanfile >@@ -145,6 +145,7 @@ recommends 'HTTPD::Bench::ApacheBench', '0.73'; > recommends 'LWP::Protocol::https', '5.836'; > recommends 'Lingua::Ispell', '0.07'; > recommends 'Locale::XGettext::TT2', '0.6'; >+recommends 'MARC::Lint', '1.50'; > recommends 'Module::Bundled::Files', '0.03'; > recommends 'Module::Load::Conditional', '0.38'; > recommends 'Module::Pluggable', '3.9'; >diff --git a/debian/control b/debian/control >index a4384d2d1a..1dcbb858ea 100644 >--- a/debian/control >+++ b/debian/control >@@ -83,6 +83,7 @@ Build-Depends: libalgorithm-checkdigits-perl, > liblwp-protocol-https-perl | libwww-perl (<<6.02), libio-socket-ssl-perl, > libmarc-charset-perl, > libmarc-file-mij-perl, >+ libmarc-lint-perl, > libmarc-record-perl, > libmarc-xml-perl, > libmime-lite-perl, >@@ -319,6 +320,7 @@ Depends: libalgorithm-checkdigits-perl, > liblwp-protocol-https-perl | libwww-perl (<<6.02), libio-socket-ssl-perl, > libmarc-charset-perl, > libmarc-file-mij-perl, >+ libmarc-lint-perl, > libmarc-record-perl, > libmarc-xml-perl, > libmime-lite-perl, >diff --git a/misc/cronjobs/check_marc_errors.pl b/misc/cronjobs/check_marc_errors.pl >new file mode 100755 >index 0000000000..24b8b350ac >--- /dev/null >+++ b/misc/cronjobs/check_marc_errors.pl >@@ -0,0 +1,123 @@ >+#! /usr/bin/perl >+# >+# Copyright 2022 Aleisha Amohia <aleisha@catalyst.net.nz> >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+=head1 NAME >+ >+check_marc_errors.pl - Check for MARC encoding errors in bibliographic records and print results >+ >+=head1 USAGE >+ >+=over >+ >+=item check_marc_errors.pl [ --bibnum X ][ --intranet https://koha-intranet-url.com/ ] >+ >+=back >+ >+=cut >+ >+=head1 OPTIONS >+ >+=over >+ >+=item B<--bibnum X> >+ >+Check a specified biblio for MARC errors. Can be repeated to use with multiple biblios. >+ >+ --bibnum 1 --bibnum 2 --bibnum 3 >+ >+=item B<--intranet https://koha-intranet-url.com/> >+ >+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. >+ >+=back >+ >+=cut >+ >+use C4::Context; >+use C4::Biblio qw( GetMarcBiblio ); >+use Getopt::Long qw( GetOptions ); >+use Modern::Perl; >+use MARC::Lint; >+use Koha::Biblios; >+ >+my @bibnum; >+my $intranet; >+ >+GetOptions( >+ '+bibnum=i' => \@bibnum, >+ 'intranet=s' => \$intranet, >+); >+ >+my $count = 0; >+ >+print "<html>\n<body>\n<div id=\"marc_errors\">\n<table>"; >+ >+# checking MARC errors for specific records only >+if ( @bibnum ) { >+ foreach my $id ( @bibnum ) { >+ my $record = GetMarcBiblio({ biblionumber => $id }); >+ >+ my $warning = lint_record( $record ); >+ my $detail_uri = "cgi-bin/koha/catalogue/detail.pl?biblionumber="; >+ report( $id, $warning, $detail_uri ); >+ } >+} else { >+ # checking MARC errors for all records >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare("SELECT biblionumber FROM biblio"); >+ $sth->execute(); >+ my $warnings; >+ while ( my ( $biblionumber ) = $sth->fetchrow ) { >+ my $record = GetMarcBiblio({ biblionumber => $biblionumber }); >+ >+ my $warning = lint_record( $record ); >+ my $detail_uri = "cgi-bin/koha/catalogue/detail.pl?biblionumber="; >+ report( $biblionumber, $warning, $detail_uri ); >+ } >+} >+ >+print "</table>\n</div>\n</body>\n</html>"; >+ >+sub lint_record { >+ my $record = shift; >+ my $linter = MARC::Lint->new; >+ $linter->check_record( $record ); >+ my $warnings = join( "\n", $linter->warnings ); >+ return $warnings; >+} >+ >+sub report { >+ my ( $id, $warning, $detail_uri ) = @_; >+ if ( $warning ) { >+ my $string = "<tr>\n"; >+ $count++; >+ $string .= "<td>" . $count . "</td>\n"; >+ if ( $intranet ) { >+ $string .= "<td><a href=\"" >+ . $intranet >+ . $detail_uri >+ . $id >+ . "\">$id</a></td>\n"; >+ } else { >+ $string .= "<td>" . $id . "</td>\n"; >+ } >+ $string .= "<td>" . $warning . "</td>\n</tr>\n"; >+ print $string; >+ } >+} >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30326
:
131994
|
132038
| 132053 |
133511
|
133674
|
134345
|
134447