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;
22 my ( $input_marc_file,$number,$nowarning,$frameworkcode) = ('',0);
25 'file:s' => \$input_marc_file,
29 'c' => \$frameworkcode,
32 $frameworkcode="" unless $frameworkcode;
34 if ($version || ($input_marc_file eq '')) {
36 This script compares an iso2709 file and Koha's MARC frameworks
37 It will show the marc fields/subfields used in Koha, and that
38 are not in the iso2709 file and which fields/subfields that are
39 used in the iso2709 file and not in Koha.
42 \tv : this version/help screen
43 \tfile /path/to/file/to/dump : the file to dump
44 \tw : warning and strict off. If your dump fails, try -w option. It it works, then, the file is iso2709, but a buggy one !
45 \tc : the frameworkcode. If omitted, set to ""
47 SAMPLE : ./compare_iso_and_marc_parameters.pl -file /home/paul/koha.dev/local/npl -n 1
54 my $fh = IO::File->new($input_marc_file); # don't let MARC::Batch open the file, as it applies the ':utf8' IO layer
55 my $batch = MARC::Batch->new( 'USMARC', $fh );
56 $batch->warnings_off() unless $nowarning;
57 $batch->strict_off() unless $nowarning;
58 my $dbh=C4::Context->dbh;
59 my $sth = $dbh->prepare("select tagfield,tagsubfield,tab from marc_subfield_structure where frameworkcode=?");
60 $sth->execute($frameworkcode);
64 while (my ($tagfield,$tagsubfield,$tab) = $sth->fetchrow) {
65 $hash_unused{"$tagfield$tagsubfield"} = 1 if ($tab eq -1);
66 $hash_used{"$tagfield$tagsubfield"} = 1 if ($tab ne -1);
69 while ( my $record = $batch->next() ) {
71 foreach my $MARCfield ($record->fields()) {
72 next if $MARCfield->is_control_field(); # tag num < 10
74 foreach my $fields ($MARCfield->subfields()) {
76 if ($hash_unused{$MARCfield->tag().@$fields[0]}>=1) {
77 $hash_unused{$MARCfield->tag().@$fields[0]}++;
79 if ($hash_used{$MARCfield->tag().@$fields[0]}>=1) {
80 $hash_used{$MARCfield->tag().@$fields[0]}++;
83 # foreach my $field (@$fields) {
84 # warn "==>".$MARCfield->tag().@$fields[0];
90 print "Undeclared tag/subfields that exists in the file\n";
91 print "================================================\n";
92 foreach my $key (sort keys %hash_unused) {
93 print "$key => ".($hash_unused{$key}-1)."\n" unless ($hash_unused{$key}==1);
96 print "Declared tag/subfields unused in the iso2709 file\n";
97 print "=================================================\n";
98 foreach my $key (sort keys %hash_used) {
99 print "$key => ".($hash_used{$key}-1)."\n" if ($hash_used{$key}==1);
102 # foreach my $x (sort keys %resB) {
103 # print "$x => ".$resB{$x}."\n";
105 print "\n==================\n$i record parsed\n";