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" };
24 use Time::HiRes qw( gettimeofday );
26 use Getopt::Long qw( GetOptions );
28 my ($version, $confirm);
34 if ($version || (!$confirm)) {
36 This script rebuilds the non-MARC fields from the MARC values.
37 You can/must use it when you change your mapping.
39 Example: you decide to map biblio.title to 200\$a (it was previously mapped to 610\$a).
40 Run this script or you will have strange results in the UI!
43 \t./batchRebuildBiblioTables.pl -h (or without arguments => show this screen)
44 \t./batchRebuildBiblioTables.pl -c (c like confirm => rebuild non-MARC fields (may take long)
50 $|=1; # non-buffered output
52 my $dbh = C4::Context->dbh;
54 my $starttime = gettimeofday;
55 my $marcflavour = C4::Context->preference('marcflavour');
56 my $sth = $dbh->prepare('SELECT biblionumber, frameworkcode FROM biblio');
60 while (my ($biblionumber, $frameworkcode) = $sth->fetchrow) {
61 my $marcxml = GetXmlBiblio($biblionumber);
62 if (not defined $marcxml) {
63 push @errors, $biblionumber;
67 $marcxml = C4::Charset::StripNonXmlChars( $marcxml );
69 MARC::Record::new_from_xml($marcxml, 'UTF-8', $marcflavour);
72 push @errors, $biblionumber;
76 my $biblio = TransformMarcToKoha($record);
77 C4::Biblio::_koha_modify_biblio($dbh, $biblio, $frameworkcode);
78 C4::Biblio::_koha_modify_biblioitem_nonmarc($dbh, $biblio);
81 printf("%lu records processed in %.2f seconds\n", $i, gettimeofday() - $starttime) unless ($i % 100);
84 printf("\n%lu records processed in %.2f seconds\n", $i, gettimeofday() - $starttime);
85 if (scalar(@errors) > 0) {
86 print "Some records could not be processed though: ", join(' ', @errors);