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 compare an iso2709 file and the MARC parameters
35 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.
36 to solve this, just modify Koha parameters (change TAB)
38 \tv : this version/help screen
39 \tfile /path/to/file/to/dump : the file to dump
40 \tw : warning and strict off. If your dump fail, try -w option. It it works, then, the file is iso2709, but a buggy one !
41 \tc : the frameworkcode. If omitted, set to ""
42 SAMPLE : ./compare_iso_and_marc_parameters.pl -file /home/paul/koha.dev/local/npl -n 1
48 my $batch = MARC::Batch->new( 'USMARC', $input_marc_file );
49 $batch->warnings_off() unless $nowarning;
50 $batch->strict_off() unless $nowarning;
51 my $dbh=C4::Context->dbh;
52 my $sth = $dbh->prepare("select tagfield,tagsubfield,tab from marc_subfield_structure where frameworkcode=?");
53 $sth->execute($frameworkcode);
57 while (my ($tagfield,$tagsubfield,$tab) = $sth->fetchrow) {
58 $hash_unused{"$tagfield$tagsubfield"} = 1 if ($tab eq -1);
59 $hash_used{"$tagfield$tagsubfield"} = 1 if ($tab ne -1);
62 while ( my $record = $batch->next() ) {
64 foreach my $MARCfield ($record->fields()) {
65 next if $MARCfield->tag()<=010;
67 foreach my $fields ($MARCfield->subfields()) {
69 if ($hash_unused{$MARCfield->tag().@$fields[0]}>=1) {
70 $hash_unused{$MARCfield->tag().@$fields[0]}++;
72 if ($hash_used{$MARCfield->tag().@$fields[0]}>=1) {
73 $hash_used{$MARCfield->tag().@$fields[0]}++;
76 # foreach my $field (@$fields) {
77 # warn "==>".$MARCfield->tag().@$fields[0];
83 print "Undeclared tag/subfields that exists in the file\n";
84 print "================================================\n";
85 foreach my $key (sort keys %hash_unused) {
86 print "$key => ".($hash_unused{$key}-1)."\n" unless ($hash_unused{$key}==1);
89 print "Declared tag/subfields unused in the iso2709 file\n";
90 print "=================================================\n";
91 foreach my $key (sort keys %hash_used) {
92 print "$key => ".($hash_used{$key}-1)."\n" if ($hash_used{$key}==1);
95 # foreach my $x (sort keys %resB) {
96 # print "$x => ".$resB{$x}."\n";
98 print "\n==================\n$i record parsed\n";