From a0dd6d70f58a532ce78da16aebaa9c141f3a93ed Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Wed, 20 Feb 2019 16:27:01 +0200 Subject: [PATCH] Bug 20447: Add a batch rebuild script for holdings table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This script can be used to update the columns in the holdings table from the MARC record using the rules in the framework. In practice this will only be required if the koha link field is changed in the framework. Rebased-by: Joonas Kylmälä Signed-off-by: Michal Denar Signed-off-by: Michal Denar --- misc/batchRebuildHoldingsTables.pl | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 misc/batchRebuildHoldingsTables.pl diff --git a/misc/batchRebuildHoldingsTables.pl b/misc/batchRebuildHoldingsTables.pl new file mode 100755 index 0000000000..3483ebf841 --- /dev/null +++ b/misc/batchRebuildHoldingsTables.pl @@ -0,0 +1,65 @@ +#!/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 Koha::Holdings; + +use Getopt::Long; + +my ($input_marc_file, $number) = ('', 0); +my ($help, $confirm); +GetOptions( + 'c' => \$confirm, + 'h' => \$help, +); + +if ($help || !$confirm) { + print < shows this screen) +\t./batchRebuildHoldingsTables.pl -c (c like confirm => rebuild non-MARC DB (may take long) +EOF +; + exit; +} + +my $starttime = time(); + +$| = 1; # flushes output + +my $count = 0; +my $page = 0; +my $rows = 1000; +while (1) { + ++$page; + my $holdings = Koha::Holdings->search({}, {page => $page, rows => $rows}); + my $i = 0; + while (my $holding = $holdings->next()) { + my $metadata = $holding->metadata(); + next unless $metadata; + $holding->set_marc({ record => $metadata->record() }); + $holding->store(); + ++$i; + } + last unless $i; + $count += $i; + my $timeneeded = time() - $starttime; + print "$count records processed in $timeneeded seconds\n"; +} +my $timeneeded = time() - $starttime; +print "Completed with $count records processed in $timeneeded seconds\n"; -- 2.25.1