batch import rework -- implement stage-commit-undo for batch import
[koha.git] / misc / migration_tools / check_marc_definition.pl
1 #!/usr/bin/perl
2 # script that rebuild thesaurus from biblio table.
3
4 use strict;
5
6 # Koha modules used
7 use MARC::File::USMARC;
8 use MARC::Record;
9 use MARC::Batch;
10 use C4::Context;
11 use C4::Biblio;
12 use C4::AuthoritiesMarc;
13 use Time::HiRes qw(gettimeofday);
14
15 use Getopt::Long;
16 my ( $input_marc_file, $number) = ('',0);
17 my ($version,$confirm);
18 GetOptions(
19     'h' => \$version,
20     'c' => \$confirm,
21 );
22
23 if ($version || ($confirm eq '')) {
24         print <<EOF
25 Script that compare the datas in the DB and the setting of MARC structure 
26 It show all fields/subfields that are in the MARC DB but NOT in any tab (= fields used but not visible) Usually, this means you made an error in your MARC editor. Sometimes, this is something normal.
27
28 Enter $0 -c to run this script (the -c being here only to "confirm"
29 EOF
30 ;#
31 exit;
32 }#/
33
34 my $dbh = C4::Context->dbh;
35 print "Checking\n";
36 my $sth = $dbh->prepare("SELECT count(*), tag, subfieldcode, frameworkcode FROM marc_subfield_table, marc_biblio WHERE marc_biblio.bibid = marc_subfield_table.bibid group by frameworkcode,tag,subfieldcode");
37 $sth->execute;
38 my $sth2 = $dbh->prepare("select tab,liblibrarian,kohafield from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?");
39 while (my ($total,$tag,$subfield,$frameworkcode) = $sth->fetchrow) {
40         $sth2->execute($tag,$subfield,$frameworkcode);
41         my ($tab,$liblibrarian,$kohafield) = $sth2->fetchrow;
42         if ($tab eq -1 && $kohafield ne "biblio.biblionumber" && $kohafield ne "biblioitems.biblioitemnumber" && $kohafield ne "items.itemnumber") {
43                 print "Tab ignore for framework $frameworkcode, $tag\$$subfield - $liblibrarian (used $total times)\n";
44         }
45 }
46
47 print "Done\n";