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