2 # small script that rebuilds the non-MARC DB
7 # use MARC::File::USMARC;
12 use Time::HiRes qw(gettimeofday);
15 my ( $input_marc_file, $number) = ('',0);
16 my ($version, $confirm,$test_parameter);
20 't' => \$test_parameter,
23 if ($version || (!$confirm)) {
25 This script rebuilds the non-MARC DB from the MARC values.
26 You can/must use it when you change your mapping.
27 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
30 \t./rebuildnonmarc.pl -h (or without arguments => shows this screen)
31 \t./rebuildnonmarc.pl -c (c like confirm => rebuild non marc DB (may be long)
32 \t-t => test only, change nothing in DB
38 my $dbh = C4::Context->dbh;
40 my $starttime = gettimeofday;
41 #1st of all, find item MARC tag.
42 my ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,"items.itemnumber");
43 # $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");
44 my $sth = $dbh->prepare("select bibid from marc_biblio");
46 # my ($bibidmax) = $sth->fetchrow;
47 # warn "$bibidmax <<==";
48 while (my ($bibid)= $sth->fetchrow) {
49 #now, parse the record, extract the item fields, and store them in somewhere else.
50 my $record = MARCgetbiblio($dbh,$bibid);
51 my @fields = $record->field($tagfield);
55 foreach my $field (@fields) {
56 my $item = MARC::Record->new();
57 $item->append_fields($field);
59 $record->delete_field($field);
63 # now, create biblio and items with NEWnewXX call.
64 NEWmodbiblio($dbh,$record,$bibid) unless $test_parameter;
65 # print "biblio done\n";
66 for (my $i=0;$i<=$#items;$i++) {
67 my $tmp = MARCmarc2koha($dbh,$items[$i]) unless $test_parameter; # finds the itemnumber
68 # warn "==> ".$items[$i]->as_formatted;
69 NEWmoditem($dbh,$items[$i],$bibid,$tmp->{itemnumber}) unless $test_parameter;
70 # print "1 item done\n";
73 # $dbh->do("unlock tables");
74 my $timeneeded = gettimeofday - $starttime;
75 print "$i MARC record done in $timeneeded seconds\n";