View | Details | Raw Unified | Return to bug 20447
Collapse All | Expand All

(-)a/C4/Holdings.pm (+1 lines)
Lines 32-37 use MARC::File::USMARC; Link Here
32
use MARC::File::XML;
32
use MARC::File::XML;
33
use POSIX qw(strftime);
33
use POSIX qw(strftime);
34
34
35
use C4::Biblio;
35
use C4::Koha;
36
use C4::Koha;
36
use C4::Log;    # logaction
37
use C4::Log;    # logaction
37
use C4::ClassSource;
38
use C4::ClassSource;
(-)a/misc/batchRebuildHoldingsTables.pl (-1 / +71 lines)
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 MARC::Record;
16
use C4::Context;
17
use C4::Holdings;
18
19
use Getopt::Long;
20
21
my ($input_marc_file, $number) = ('', 0);
22
my ($help, $confirm, $test_parameter);
23
GetOptions(
24
    'c' => \$confirm,
25
    'h' => \$help,
26
    't' => \$test_parameter,
27
);
28
29
if ($help || !$confirm) {
30
    print <<EOF
31
This script rebuilds the non-MARC Holdings DB from the MARC values.
32
You can/must use it when you change the mappings.
33
34
Example: you decide to map holdings.callnumber to 852\$ltoo (it was previously mapped to 852\$k).
35
36
Syntax:
37
\t./batchRebuildHoldingsTables.pl -h (or without arguments => shows this screen)
38
\t./batchRebuildHoldingsTables.pl -c (c like confirm => rebuild non-MARC DB (may takes long)
39
\t-t => test only, change nothing in DB
40
EOF
41
;
42
    exit;
43
}
44
45
my $dbh = C4::Context->dbh;
46
my $i = 0;
47
my $starttime = time();
48
49
$| = 1; # flushes output
50
$starttime = time();
51
52
my $sth = $dbh->prepare("SELECT holding_id FROM holdings");
53
$sth->execute();
54
my @errors;
55
while (my ($holding_id) = $sth->fetchrow()) {
56
    my $record = C4::Holdings::GetMarcHolding($holding_id);
57
    if (not defined $record) {
58
        push @errors, $holding_id;
59
        next;
60
    }
61
    my $rowData = C4::Holdings::TransformMarcHoldingToKoha($record);
62
    my $frameworkcode = C4::Holdings::GetHoldingFrameworkCode($holding_id);
63
    C4::Holdings::_koha_modify_holding($dbh, $holding_id, $rowData, $frameworkcode) unless $test_parameter;
64
    ++$i;
65
}
66
$sth->finish();
67
my $timeneeded = time() - $starttime;
68
print "$i MARC records done in $timeneeded seconds\n";
69
if (scalar(@errors) > 0) {
70
    print 'Records that could not be processed: ', join(' ', @errors);
71
}

Return to bug 20447