Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
|
6 |
use C4::Context; |
7 |
use C4::AuthoritiesMarc qw(); |
8 |
|
9 |
print "Fetching authority IDs\n"; |
10 |
my $auth_ids = get_used_auth_ids(); |
11 |
print "Found " . scalar @$auth_ids . " authority IDs\n"; |
12 |
foreach my $authid (@$auth_ids){ |
13 |
print "Updating authority $authid\n"; |
14 |
eval { |
15 |
my $record = C4::AuthoritiesMarc::GetAuthority($authid); |
16 |
C4::AuthoritiesMarc::merge({ mergefrom => $authid, MARCfrom => $record, mergeto => $authid, MARCto => $record }); |
17 |
}; |
18 |
if ($@){ |
19 |
warn $@; |
20 |
} |
21 |
} |
22 |
|
23 |
sub get_used_auth_ids { |
24 |
my @auth_ids = (); |
25 |
my %numbers = (); |
26 |
my $conn = C4::Context->Zconn; |
27 |
if ($conn){ |
28 |
$conn->option('number', '100'); |
29 |
$conn->option('position', '1'); |
30 |
$conn->option('stepSize', '0'); |
31 |
my $term = 1; |
32 |
while (1){ |
33 |
my $rs = $conn->scan_pqf('@attr 1=8910 '.$term); |
34 |
my $counter = 0; |
35 |
my $size = $rs->size(); |
36 |
if ($size){ |
37 |
while ( $counter < $size ){ |
38 |
($term) = $rs->term($counter); |
39 |
#warn "FETCHED $term"; |
40 |
if ( ! $numbers{$term} ){ |
41 |
$numbers{$term} = 1; |
42 |
push(@auth_ids,$term); |
43 |
} |
44 |
$counter++; |
45 |
} |
46 |
if ($size == 1){ |
47 |
last; |
48 |
} |
49 |
} |
50 |
} |
51 |
} |
52 |
return \@auth_ids; |
53 |
} |
54 |
|
55 |
=head1 NAME |
56 |
|
57 |
update_bibs_from_authorities.pl |
58 |
|
59 |
=head1 DESCRIPTION |
60 |
|
61 |
This batch job finds every authority ID in the Koha-Auth-Number index, |
62 |
and then it runs a "merge", so that all bibliographic records using |
63 |
that authority will have their headings updated from the authoritative |
64 |
source record. |
65 |
|
66 |
This is a useful job to run after link_bibs_to_authorities.pl. |
67 |
|
68 |
=cut |