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 <<==";
56 while (my ($biblionumber)= $sth->fetchrow) {
57 #now, parse the record, extract the item fields, and store them in somewhere else.
58 my $record = GetMarcBiblio
($biblionumber);
59 my @fields = $record->field($tagfield);
63 my $timeneeded = gettimeofday
- $starttime;
64 print "$i in $timeneeded s\n" unless ($i % 50);
66 foreach my $field (@fields) {
67 my $item = MARC
::Record
->new();
68 $item->append_fields($field);
70 $record->delete_field($field);
73 # print "$biblionumber\n";
74 my $frameworkcode = GetFrameworkCode
($biblionumber);
75 localNEWmodbiblio
($dbh,$record,$biblionumber,$frameworkcode) unless $test_parameter;
77 # $dbh->do("unlock tables");
78 my $timeneeded = time() - $starttime;
79 print "$i MARC record done in $timeneeded seconds\n";
81 # modified NEWmodbiblio to jump the MARC part of the biblio modif
83 sub localNEWmodbiblio
{
84 my ($dbh,$record,$biblionumber,$frameworkcode) =@_;
85 $frameworkcode="" unless $frameworkcode;
86 my $oldbiblio = TransformMarcToKoha
($dbh,$record,$frameworkcode);
87 C4
::Biblio
::_koha_modify_biblio
( $dbh, $oldbiblio );
88 C4
::Biblio
::_koha_modify_biblioitem_nonmarc
( $dbh, $oldbiblio );