6 # find Koha's Perl modules
7 # test carefully before changing this
9 eval { require "$FindBin::Bin/kohalib.pl" };
18 # command-line parameters
23 my $result = GetOptions
(
24 'verbose' => \
$verbose,
25 'test' => \
$test_only,
26 'h|help' => \
$want_help
29 if (not $result or $want_help) {
34 my $num_bibs_processed = 0;
35 my $num_bibs_modified = 0;
37 my $dbh = C4
::Context
->dbh;
38 $dbh->{AutoCommit
} = 0;
45 my $sql = "SELECT biblionumber FROM biblio ORDER BY biblionumber ASC";
46 my $sth = $dbh->prepare($sql);
48 while (my ($biblionumber) = $sth->fetchrow_array()) {
49 $num_bibs_processed++;
50 process_bib
($biblionumber);
52 if (not $test_only and ($num_bibs_processed % 100) == 0) {
53 print_progress_and_commit
($num_bibs_processed);
63 Bib authority heading linking report
64 ------------------------------------
65 Number of bibs checked
: $num_bibs_processed
66 Number of bibs modified
: $num_bibs_modified
67 Number of bibs with errors
: $num_bad_bibs
72 my $biblionumber = shift;
74 my $bib = GetMarcBiblio
($biblionumber);
75 unless (defined $bib) {
76 print "\nCould not retrieve bib $biblionumber from the database - record is corrupt.\n";
81 my $headings_changed = LinkBibHeadingsToAuthorities
($bib);
83 if ($headings_changed) {
85 my $title = substr($bib->title, 0, 20);
86 print "Bib $biblionumber ($title): $headings_changed headings changed\n";
89 # delete any item tags
90 my ($itemtag, $itemsubfield) = GetMarcFromKohaField
("items.itemnumber", '');
91 foreach my $field ($bib->field($itemtag)) {
92 $bib->delete_field($field);
94 ModBiblio
($bib, $biblionumber, GetFrameworkCode
($biblionumber));
100 sub print_progress_and_commit
{
103 print "... processed $recs records\n";
108 $0: link headings
in bib records to authorities
.
110 This batch job checks
each bib record
in the Koha
111 database
and attempts to
link each of its headings
112 to the matching authority record
.
115 --verbose
print the number of headings changed
117 --test only test the authority linking
118 and report the results
; do not
119 change the bib records
.
120 --help
or -h show this message
.