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" };
13 # use MARC::File::USMARC;
18 use Time::HiRes qw(gettimeofday);
21 my ( $input_marc_file, $number) = ('',0);
22 my ($version, $confirm,$test_parameter);
26 't' => \$test_parameter,
29 if ($version || (!$confirm)) {
31 This script rebuilds the non-MARC DB from the MARC values.
32 You can/must use it when you change your mapping.
33 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
36 \t./rebuildnonmarc.pl -h (or without arguments => shows this screen)
37 \t./rebuildnonmarc.pl -c (c like confirm => rebuild non marc DB (may be long)
38 \t-t => test only, change nothing in DB
44 my $dbh = C4::Context->dbh;
46 my $starttime = time();
48 $|=1; # flushes output
49 my $starttime = gettimeofday;
51 #1st of all, find item MARC tag.
52 my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.itemnumber",'');
53 # $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");
54 my $sth = $dbh->prepare("SELECT biblionumber FROM biblio");
56 # my ($biblionumbermax) = $sth->fetchrow;
57 # warn "$biblionumbermax <<==";
58 while (my ($biblionumber)= $sth->fetchrow) {
59 #now, parse the record, extract the item fields, and store them in somewhere else.
60 my $record = GetMarcBiblio($biblionumber);
61 my @fields = $record->field($tagfield);
65 my $timeneeded = gettimeofday - $starttime;
66 print "$i in $timeneeded s\n" unless ($i % 50);
68 foreach my $field (@fields) {
69 my $item = MARC::Record->new();
70 $item->append_fields($field);
72 $record->delete_field($field);
75 # print "$biblionumber\n";
76 my $frameworkcode = GetFrameworkCode($biblionumber);
77 localNEWmodbiblio($dbh,$record,$biblionumber,$frameworkcode) unless $test_parameter;
79 # $dbh->do("unlock tables");
80 my $timeneeded = time() - $starttime;
81 print "$i MARC record done in $timeneeded seconds\n";
83 # modified NEWmodbiblio to jump the MARC part of the biblio modif
85 sub localNEWmodbiblio {
86 my ($dbh,$record,$biblionumber,$frameworkcode) =@_;
87 $frameworkcode="" unless $frameworkcode;
88 my $oldbiblio = TransformMarcToKoha($dbh,$record,$frameworkcode);
89 C4::Biblio::_koha_modify_biblio( $dbh, $oldbiblio );
90 C4::Biblio::_koha_modify_biblioitem_nonmarc( $dbh, $oldbiblio );