2 # small script that rebuilds the non-MARC DB
6 # find Koha's Perl modules
7 # test carefully before changing this
9 eval { require "$FindBin::Bin/kohalib.pl" };
16 use Time::HiRes qw(gettimeofday);
19 my ( $input_marc_file, $number) = ('',0);
20 my ($version, $confirm,$test_parameter);
24 't' => \$test_parameter,
27 if ($version || (!$confirm)) {
29 This script rebuilds the non-MARC DB from the MARC values.
30 You can/must use it when you change your mapping.
31 For example : you decide to map biblio.title to 200$a (it was previously mapped to 610$a) : run this script or you will have strange
34 \t./rebuildnonmarc.pl -h (or without arguments => shows this screen)
35 \t./rebuildnonmarc.pl -c (c like confirm => rebuild non marc DB (may be long)
36 \t-t => test only, change nothing in DB
42 my $dbh = C4::Context->dbh;
44 my $starttime = time();
46 $|=1; # flushes output
47 $starttime = gettimeofday;
49 #1st of all, find item MARC tag.
50 my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.itemnumber",'');
51 # $dbh->do("lock tables biblio write, biblioitems write, items write, marc_biblio write, marc_subfield_table write, marc_blob_subfield write, marc_word write, marc_subfield_structure write, stopwords write");
52 my $sth = $dbh->prepare("SELECT biblionumber FROM biblio");
54 # my ($biblionumbermax) = $sth->fetchrow;
55 # warn "$biblionumbermax <<==";
57 while (my ($biblionumber)= $sth->fetchrow) {
58 #now, parse the record, extract the item fields, and store them in somewhere else.
59 my $record = GetMarcBiblio($biblionumber);
60 if (not defined $record) {
61 push @errors, $biblionumber;
64 my @fields = $record->field($tagfield);
68 my $timeneeded = gettimeofday - $starttime;
69 print "$i in $timeneeded s\n" unless ($i % 50);
71 foreach my $field (@fields) {
72 my $item = MARC::Record->new();
73 $item->append_fields($field);
75 $record->delete_field($field);
78 # print "$biblionumber\n";
79 my $frameworkcode = GetFrameworkCode($biblionumber);
80 localNEWmodbiblio($dbh,$record,$biblionumber,$frameworkcode) unless $test_parameter;
82 # $dbh->do("unlock tables");
83 my $timeneeded = time() - $starttime;
84 print "$i MARC record done in $timeneeded seconds\n";
85 if (scalar(@errors) > 0) {
86 print "Some biblionumber could not be processed though: ", join(" ", @errors);
89 # modified NEWmodbiblio to jump the MARC part of the biblio modif
91 sub localNEWmodbiblio {
92 my ($dbh,$record,$biblionumber,$frameworkcode) =@_;
93 $frameworkcode="" unless $frameworkcode;
94 my $oldbiblio = TransformMarcToKoha($dbh,$record,$frameworkcode);
95 C4::Biblio::_koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode );
96 C4::Biblio::_koha_modify_biblioitem_nonmarc( $dbh, $oldbiblio );