From 856fcc907bce6e1de730a1236d1cd70e12e1a7b8 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 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. https://bugs.koha-community.org/show_bug.cgi?id=22690 --- 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.11.0