2 # small script that dumps an iso2709 file.
7 # find Koha's Perl modules
8 # test carefully before changing this
10 eval { require "$FindBin::Bin/kohalib.pl" };
15 use MARC::File::USMARC;
20 my ( $input_marc_file,$number,$nowarning,$frameworkcode) = ('',0);
23 'file:s' => \$input_marc_file,
27 'c' => \$frameworkcode,
30 $frameworkcode="" unless $frameworkcode;
32 if ($version || ($input_marc_file eq '')) {
34 This script compares an iso2709 file and Koha's MARC frameworks
35 It will show the marc fields/subfields used in Koha, and that
36 are not in the iso2709 file and which fields/subfields that are
37 used in the iso2709 file and not in Koha.
40 \tv : this version/help screen
41 \tfile /path/to/file/to/dump : the file to dump
42 \tw : warning and strict off. If your dump fails, try -w option. It it works, then, the file is iso2709, but a buggy one !
43 \tc : the frameworkcode. If omitted, set to ""
45 SAMPLE : ./compare_iso_and_marc_parameters.pl -file /home/paul/koha.dev/local/npl -n 1
52 my $batch = MARC::Batch->new( 'USMARC', $input_marc_file );
53 $batch->warnings_off() unless $nowarning;
54 $batch->strict_off() unless $nowarning;
55 my $dbh=C4::Context->dbh;
56 my $sth = $dbh->prepare("select tagfield,tagsubfield,tab from marc_subfield_structure where frameworkcode=?");
57 $sth->execute($frameworkcode);
61 while (my ($tagfield,$tagsubfield,$tab) = $sth->fetchrow) {
62 $hash_unused{"$tagfield$tagsubfield"} = 1 if ($tab eq -1);
63 $hash_used{"$tagfield$tagsubfield"} = 1 if ($tab ne -1);
66 while ( my $record = $batch->next() ) {
68 foreach my $MARCfield ($record->fields()) {
69 next if $MARCfield->tag()<=010;
71 foreach my $fields ($MARCfield->subfields()) {
73 if ($hash_unused{$MARCfield->tag().@$fields[0]}>=1) {
74 $hash_unused{$MARCfield->tag().@$fields[0]}++;
76 if ($hash_used{$MARCfield->tag().@$fields[0]}>=1) {
77 $hash_used{$MARCfield->tag().@$fields[0]}++;
80 # foreach my $field (@$fields) {
81 # warn "==>".$MARCfield->tag().@$fields[0];
87 print "Undeclared tag/subfields that exists in the file\n";
88 print "================================================\n";
89 foreach my $key (sort keys %hash_unused) {
90 print "$key => ".($hash_unused{$key}-1)."\n" unless ($hash_unused{$key}==1);
93 print "Declared tag/subfields unused in the iso2709 file\n";
94 print "=================================================\n";
95 foreach my $key (sort keys %hash_used) {
96 print "$key => ".($hash_used{$key}-1)."\n" if ($hash_used{$key}==1);
99 # foreach my $x (sort keys %resB) {
100 # print "$x => ".$resB{$x}."\n";
102 print "\n==================\n$i record parsed\n";