@@ -, +, @@ --- C4/Holdings.pm | 1 + misc/batchRebuildHoldingsTables.pl | 71 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 misc/batchRebuildHoldingsTables.pl --- a/C4/Holdings.pm +++ a/C4/Holdings.pm @@ -32,6 +32,7 @@ use MARC::File::USMARC; use MARC::File::XML; use POSIX qw(strftime); +use C4::Biblio; use C4::Koha; use C4::Log; # logaction use C4::ClassSource; --- a/misc/batchRebuildHoldingsTables.pl +++ a/misc/batchRebuildHoldingsTables.pl @@ -0,0 +1,71 @@ +#!/usr/bin/perl +# Small script that rebuilds the non-MARC Holdings DB + +use strict; +use warnings; + +BEGIN { + # find Koha's Perl modules + # test carefully before changing this + use FindBin; + eval { require "$FindBin::Bin/kohalib.pl" }; +} + +# Koha modules used +use MARC::Record; +use C4::Context; +use C4::Holdings; + +use Getopt::Long; + +my ($input_marc_file, $number) = ('', 0); +my ($help, $confirm, $test_parameter); +GetOptions( + 'c' => \$confirm, + 'h' => \$help, + 't' => \$test_parameter, +); + +if ($help || !$confirm) { + print < shows this screen) +\t./batchRebuildHoldingsTables.pl -c (c like confirm => rebuild non-MARC DB (may takes long) +\t-t => test only, change nothing in DB +EOF +; + exit; +} + +my $dbh = C4::Context->dbh; +my $i = 0; +my $starttime = time(); + +$| = 1; # flushes output +$starttime = time(); + +my $sth = $dbh->prepare("SELECT holding_id FROM holdings"); +$sth->execute(); +my @errors; +while (my ($holding_id) = $sth->fetchrow()) { + my $record = C4::Holdings::GetMarcHolding($holding_id); + if (not defined $record) { + push @errors, $holding_id; + next; + } + my $rowData = C4::Holdings::TransformMarcHoldingToKoha($record); + my $frameworkcode = C4::Holdings::GetHoldingFrameworkCode($holding_id); + C4::Holdings::_koha_modify_holding($dbh, $holding_id, $rowData, $frameworkcode) unless $test_parameter; + ++$i; +} +$sth->finish(); +my $timeneeded = time() - $starttime; +print "$i MARC records done in $timeneeded seconds\n"; +if (scalar(@errors) > 0) { + print 'Records that could not be processed: ', join(' ', @errors); +} --