5 # find Koha's Perl modules
6 # test carefully before changing this
8 eval { require "$FindBin::Bin/kohalib.pl" };
17 # command-line parameters
22 my $result = GetOptions
(
23 'verbose' => \
$verbose,
24 'test' => \
$test_only,
25 'h|help' => \
$want_help
28 if (not $result or $want_help) {
33 my $num_bibs_processed = 0;
34 my $num_bibs_modified = 0;
36 my $dbh = C4
::Context
->dbh;
37 $dbh->{AutoCommit
} = 0;
44 my $sql = "SELECT biblionumber FROM biblio ORDER BY biblionumber ASC";
45 my $sth = $dbh->prepare($sql);
47 while (my ($biblionumber) = $sth->fetchrow_array()) {
48 $num_bibs_processed++;
49 process_bib
($biblionumber);
51 if (not $test_only and ($num_bibs_processed % 100) == 0) {
52 print_progress_and_commit
($num_bibs_processed);
62 Bib authority heading linking report
63 ------------------------------------
64 Number of bibs checked
: $num_bibs_processed
65 Number of bibs modified
: $num_bibs_modified
66 Number of bibs with errors
: $num_bad_bibs
71 my $biblionumber = shift;
73 my $bib = GetMarcBiblio
($biblionumber);
74 unless (defined $bib) {
75 print "\nCould not retrieve bib $biblionumber from the database - record is corrupt.\n";
80 my $headings_changed = LinkBibHeadingsToAuthorities
($bib);
82 if ($headings_changed) {
84 my $title = substr($bib->title, 0, 20);
85 print "Bib $biblionumber ($title): $headings_changed headings changed\n";
88 # delete any item tags
89 my ($itemtag, $itemsubfield) = GetMarcFromKohaField
("items.itemnumber", '');
90 foreach my $field ($bib->field($itemtag)) {
91 $bib->delete_field($field);
93 ModBiblio
($bib, $biblionumber, GetFrameworkCode
($biblionumber));
99 sub print_progress_and_commit
{
102 print "... processed $recs records\n";
107 $0: link headings
in bib records to authorities
.
109 This batch job checks
each bib record
in the Koha
110 database
and attempts to
link each of its headings
111 to the matching authority record
.
114 --verbose
print the number of headings changed
116 --test only test the authority linking
117 and report the results
; do not
118 change the bib records
.
119 --help
or -h show this message
.