Bug 21957: Add a flag to ModBiblio to avoid linking auths if called from linker
[koha-equinox.git] / misc / link_bibs_to_authorities.pl
index 37596c5..1fd75a5 100755 (executable)
@@ -11,6 +11,7 @@ BEGIN {
     eval { require "$FindBin::Bin/kohalib.pl" };
 }
 
+use Koha::Script;
 use C4::Context;
 use C4::Biblio;
 use Getopt::Long;
@@ -187,7 +188,7 @@ sub process_bib {
     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";
@@ -195,9 +196,10 @@ sub process_bib {
         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};
     }
@@ -211,11 +213,16 @@ sub process_bib {
     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++;
         }
     }