|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
# Small script that rebuilds the non-MARC Holdings DB |
| 3 |
|
| 4 |
use strict; |
| 5 |
use warnings; |
| 6 |
|
| 7 |
BEGIN { |
| 8 |
# find Koha's Perl modules |
| 9 |
# test carefully before changing this |
| 10 |
use FindBin; |
| 11 |
eval { require "$FindBin::Bin/kohalib.pl" }; |
| 12 |
} |
| 13 |
|
| 14 |
# Koha modules used |
| 15 |
use Koha::Holdings; |
| 16 |
|
| 17 |
use Getopt::Long; |
| 18 |
|
| 19 |
my ($input_marc_file, $number) = ('', 0); |
| 20 |
my ($help, $confirm); |
| 21 |
GetOptions( |
| 22 |
'c' => \$confirm, |
| 23 |
'h' => \$help, |
| 24 |
); |
| 25 |
|
| 26 |
if ($help || !$confirm) { |
| 27 |
print <<EOF |
| 28 |
This script rebuilds the non-MARC Holdings DB from the MARC values. |
| 29 |
You can/must use it when you change the mappings. |
| 30 |
|
| 31 |
Example: you decide to map holdings.callnumber to 852\$k\$l\$m (it was previously mapped to 852\$k). |
| 32 |
|
| 33 |
Syntax: |
| 34 |
\t./batchRebuildHoldingsTables.pl -h (or without arguments => shows this screen) |
| 35 |
\t./batchRebuildHoldingsTables.pl -c (c like confirm => rebuild non-MARC DB (may take long) |
| 36 |
EOF |
| 37 |
; |
| 38 |
exit; |
| 39 |
} |
| 40 |
|
| 41 |
my $starttime = time(); |
| 42 |
|
| 43 |
$| = 1; # flushes output |
| 44 |
|
| 45 |
my $count = 0; |
| 46 |
my $page = 0; |
| 47 |
my $rows = 1000; |
| 48 |
while (1) { |
| 49 |
++$page; |
| 50 |
my $holdings = Koha::Holdings->search({}, {page => $page, rows => $rows}); |
| 51 |
my $i = 0; |
| 52 |
while (my $holding = $holdings->next()) { |
| 53 |
my $metadata = $holding->metadata(); |
| 54 |
next unless $metadata; |
| 55 |
$holding->set_marc({ record => $metadata->record() }); |
| 56 |
$holding->store(); |
| 57 |
++$i; |
| 58 |
} |
| 59 |
last unless $i; |
| 60 |
$count += $i; |
| 61 |
my $timeneeded = time() - $starttime; |
| 62 |
print "$count records processed in $timeneeded seconds\n"; |
| 63 |
} |
| 64 |
my $timeneeded = time() - $starttime; |
| 65 |
print "Completed with $count records processed in $timeneeded seconds\n"; |