Koha/misc/batchCompareMARCvsFrameworks.pl
Jonathan Druart 238fabc4ab Bug 28617: Remove kohalib.pl and rely on PERL5LIB
The purpose of this script was to load the relevant Koha lib for the
different scripts (installation, cronjob, CLI, etc.)
However it is not used consistently and we prefer to rely on PERL5LIB.

From bug 28617 comment 6 from Galen:
"""
Time marches on, and one of the motivations for having kohalib.pl - making
it possible to install Koha without setting a single environment variable -
has been obviated by the vast improvements in the ease of installing Koha.

Consequently, I think kohalib.pl can go away.
"""

Test plan:
confirm that the changes make sense and that kohalib.pl can be removed
safely.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
2021-12-07 12:16:28 -10:00

100 lines
3.1 KiB
Perl
Executable file

#!/usr/bin/perl
# small script that dumps an iso2709 file.
use strict;
#use warnings; FIXME - Bug 2505
# Koha modules used
use Koha::Script;
use C4::Context;
use MARC::File::USMARC;
use MARC::Batch;
use Getopt::Long qw( GetOptions );
use IO::File;
my ( $input_marc_file,$number,$nowarning,$frameworkcode) = ('',0);
my $version;
GetOptions(
'file:s' => \$input_marc_file,
'n:s' => \$number,
'v' => \$version,
'w' => \$nowarning,
'c' => \$frameworkcode,
);
$frameworkcode="" unless $frameworkcode;
if ($version || ($input_marc_file eq '')) {
print <<EOF
This script compares an iso2709 file and Koha's MARC frameworks
It will show the marc fields/subfields used in Koha, and that
are not in the iso2709 file and which fields/subfields that are
used in the iso2709 file and not in Koha.
parameters :
\tv : this version/help screen
\tfile /path/to/file/to/dump : the file to dump
\tw : warning and strict off. If your dump fails, try -w option. It it works, then, the file is iso2709, but a buggy one !
\tc : the frameworkcode. If omitted, set to ""
SAMPLE : ./compare_iso_and_marc_parameters.pl -file /home/paul/koha.dev/local/npl -n 1
EOF
;
die;
}#/
my $fh = IO::File->new($input_marc_file); # don't let MARC::Batch open the file, as it applies the ':utf8' IO layer
my $batch = MARC::Batch->new( 'USMARC', $fh );
$batch->warnings_off() unless $nowarning;
$batch->strict_off() unless $nowarning;
my $dbh=C4::Context->dbh;
my $sth = $dbh->prepare("select tagfield,tagsubfield,tab from marc_subfield_structure where frameworkcode=?");
$sth->execute($frameworkcode);
my %hash_unused;
my %hash_used;
while (my ($tagfield,$tagsubfield,$tab) = $sth->fetchrow) {
$hash_unused{"$tagfield$tagsubfield"} = 1 if ($tab eq -1);
$hash_used{"$tagfield$tagsubfield"} = 1 if ($tab ne -1);
}
my $i=0;
while ( my $record = $batch->next() ) {
$i++;
foreach my $MARCfield ($record->fields()) {
next if $MARCfield->is_control_field(); # tag num < 10
if ($MARCfield) {
foreach my $fields ($MARCfield->subfields()) {
if ($fields) {
if ($hash_unused{$MARCfield->tag().@$fields[0]}>=1) {
$hash_unused{$MARCfield->tag().@$fields[0]}++;
}
if ($hash_used{$MARCfield->tag().@$fields[0]}>=1) {
$hash_used{$MARCfield->tag().@$fields[0]}++;
}
}
# foreach my $field (@$fields) {
# warn "==>".$MARCfield->tag().@$fields[0];
# }
}
}
}
}
print "Undeclared tag/subfields that exists in the file\n";
print "================================================\n";
foreach my $key (sort keys %hash_unused) {
print "$key => ".($hash_unused{$key}-1)."\n" unless ($hash_unused{$key}==1);
}
print "Declared tag/subfields unused in the iso2709 file\n";
print "=================================================\n";
foreach my $key (sort keys %hash_used) {
print "$key => ".($hash_used{$key}-1)."\n" if ($hash_used{$key}==1);
}
# foreach my $x (sort keys %resB) {
# print "$x => ".$resB{$x}."\n";
# }
print "\n==================\n$i record parsed\n";