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 ModBiblio($bib, $biblionumber, GetFrameworkCode($biblionumber));
94 sub print_progress_and_commit {
97 print "... processed $recs records\n";
102 $0: link headings in bib records to authorities.
104 This batch job checks each bib record in the Koha
105 database and attempts to link each of its headings
106 to the matching authority record.
109 --verbose print the number of headings changed
111 --test only test the authority linking
112 and report the results; do not
113 change the bib records.
114 --comment <comment> optional comment to describe
115 the record batch; if the comment
116 has spaces in it, surround the
117 comment with quotation marks.
118 --help or -h show this message.