2 # Small script that rebuilds the non-MARC DB
3 # Formerly named rebuildnonmarc.pl
6 #use warnings; FIXME - Bug 2505
9 # find Koha's Perl modules
10 # test carefully before changing this
12 eval { require "$FindBin::Bin/kohalib.pl" };
19 use Time
::HiRes
qw(gettimeofday);
22 my ( $input_marc_file, $number) = ('', 0);
23 my ($version, $confirm, $test_parameter);
27 't' => \
$test_parameter,
30 if ($version || (!$confirm)) {
32 This script rebuilds the non-MARC DB from the MARC values.
33 You can/must use it when you change your mapping.
35 Example: you decide to map biblio.title to 200\$a (it was previously mapped to 610\$a).
36 Run this script or you will have strange results in OPAC !
39 \t./batchRebuildBiblioTables.pl -h (or without arguments => shows this screen)
40 \t./batchRebuildBiblioTables.pl -c (c like confirm => rebuild non marc DB (may be long)
41 \t-t => test only, change nothing in DB
47 my $dbh = C4
::Context
->dbh;
49 my $starttime = time();
51 $|=1; # flushes output
52 $starttime = gettimeofday
;
54 #1st of all, find item MARC tag.
55 my ($tagfield,$tagsubfield) = &GetMarcFromKohaField
("items.itemnumber",'');
56 # $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");
57 my $sth = $dbh->prepare("SELECT biblionumber FROM biblio");
59 # my ($biblionumbermax) = $sth->fetchrow;
60 # warn "$biblionumbermax <<==";
61 while (my ($biblionumber)= $sth->fetchrow) {
62 #now, parse the record, extract the item fields, and store them in somewhere else.
63 my $record = GetMarcBiblio
($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";
86 # modified NEWmodbiblio to jump the MARC part of the biblio modif
88 sub localNEWmodbiblio
{
89 my ($dbh,$record,$biblionumber,$frameworkcode) =@_;
90 $frameworkcode="" unless $frameworkcode;
91 my $oldbiblio = TransformMarcToKoha
($dbh,$record,$frameworkcode);
92 C4
::Biblio
::_koha_modify_biblio
( $dbh, $oldbiblio, $frameworkcode );
93 C4
::Biblio
::_koha_modify_biblioitem_nonmarc
( $dbh, $oldbiblio );