2 # small script that dumps an iso2709 file.
9 use MARC
::File
::USMARC
;
14 my ( $input_marc_file,$number,$nowarning,$frameworkcode) = ('',0);
17 'file:s' => \
$input_marc_file,
21 'c' => \
$frameworkcode,
24 $frameworkcode="" unless $frameworkcode;
26 if ($version || ($input_marc_file eq '')) {
28 This script compare an iso2709 file and the MARC parameters
29 It will show the marc fields/subfields used in Koha, and that are not anywhere in the iso2709 file and which fields/subfields that are used in the iso2709 file and not in Koha.
30 to solve this, just modify Koha parameters (change TAB)
32 \tv : this version/help screen
33 \tfile /path/to/file/to/dump : the file to dump
34 \tw : warning and strict off. If your dump fail, try -w option. It it works, then, the file is iso2709, but a buggy one !
35 \tc : the frameworkcode. If omitted, set to ""
36 SAMPLE : ./compare_iso_and_marc_parameters.pl -file /home/paul/koha.dev/local/npl -n 1
42 my $batch = MARC
::Batch
->new( 'USMARC', $input_marc_file );
43 $batch->warnings_off() unless $nowarning;
44 $batch->strict_off() unless $nowarning;
45 my $dbh=C4
::Context
->dbh;
46 my $sth = $dbh->prepare("select tagfield,tagsubfield,tab from marc_subfield_structure where frameworkcode=?");
47 $sth->execute($frameworkcode);
51 while (my ($tagfield,$tagsubfield,$tab) = $sth->fetchrow) {
52 $hash_unused{"$tagfield$tagsubfield"} = 1 if ($tab eq -1);
53 $hash_used{"$tagfield$tagsubfield"} = 1 if ($tab ne -1);
56 while ( my $record = $batch->next() ) {
58 foreach my $MARCfield ($record->fields()) {
59 next if $MARCfield->tag()<=010;
61 foreach my $fields ($MARCfield->subfields()) {
63 if ($hash_unused{$MARCfield->tag().@
$fields[0]}>=1) {
64 $hash_unused{$MARCfield->tag().@
$fields[0]}++;
66 if ($hash_used{$MARCfield->tag().@
$fields[0]}>=1) {
67 $hash_used{$MARCfield->tag().@
$fields[0]}++;
70 # foreach my $field (@$fields) {
71 # warn "==>".$MARCfield->tag().@$fields[0];
77 print "Undeclared tag/subfields that exists in the file\n";
78 print "================================================\n";
79 foreach my $key (sort keys %hash_unused) {
80 print "$key => ".($hash_unused{$key}-1)."\n" unless ($hash_unused{$key}==1);
83 print "Declared tag/subfields unused in the iso2709 file\n";
84 print "=================================================\n";
85 foreach my $key (sort keys %hash_used) {
86 print "$key => ".($hash_used{$key}-1)."\n" if ($hash_used{$key}==1);
89 # foreach my $x (sort keys %resB) {
90 # print "$x => ".$resB{$x}."\n";
92 print "\n==================\n$i record parsed\n";