eval { require "$FindBin::Bin/kohalib.pl" };
}
+use Koha::Script;
use C4::Context;
use C4::Biblio;
use Getopt::Long;
use Data::Dumper;
use Time::HiRes qw/time/;
use POSIX qw/strftime ceil/;
+use Module::Load::Conditional qw(can_load);
sub usage {
pod2usage( -verbose => 2 );
my $linker_module =
"C4::Linker::" . ( C4::Context->preference("LinkerModule") || 'Default' );
-eval { eval "require $linker_module"; };
-if ($@) {
+unless ( can_load( modules => { $linker_module => undef } ) ) {
$linker_module = 'C4::Linker::Default';
- eval "require $linker_module";
-}
-if ($@) {
- die "Unable to load linker module. Aborting.";
+ unless ( can_load( modules => { $linker_module => undef } ) ) {
+ die "Unable to load linker module. Aborting.";
+ }
}
my $linker = $linker_module->new(
my $linker = shift;
my $biblionumber = shift;
- my $bib = GetMarcBiblio($biblionumber);
+ my $bib = GetMarcBiblio({ biblionumber => $biblionumber });
unless ( defined $bib ) {
print
"\nCould not retrieve bib $biblionumber from the database - record is corrupt.\n";
return;
}
+ my $frameworkcode = GetFrameworkCode($biblionumber);
+
my ( $headings_changed, $results ) =
- LinkBibHeadingsToAuthorities( $linker, $bib,
- GetFrameworkCode($biblionumber) );
+ LinkBibHeadingsToAuthorities( $linker, $bib, $frameworkcode );
foreach my $key ( keys %{ $results->{'unlinked'} } ) {
$unlinked_headings{$key} += $results->{'unlinked'}->{$key};
}
if ($headings_changed) {
if ($verbose) {
my $title = substr( $bib->title, 0, 20 );
- print
-"Bib $biblionumber ($title): $headings_changed headings changed\n";
+ printf(
+ "Bib %12d (%-20s): %3d headings changed\n",
+ $biblionumber,
+ $title,
+ $headings_changed
+ );
}
if ( not $test_only ) {
- ModBiblio( $bib, $biblionumber, GetFrameworkCode($biblionumber) );
+ ModBiblio( $bib, $biblionumber, $frameworkcode, 1 );
+ #Last param is to note ModBiblio was called from linking script and bib should not be linked again
$num_bibs_modified++;
}
}