Bug 15380: Move Koha::Authority to Koha::MetadataRecord::Authority
[srvgit] / tools / batch_record_modification.pl
index beb2b4c..51095c3 100755 (executable)
@@ -29,7 +29,7 @@ use C4::AuthoritiesMarc qw( BuildSummary GetAuthTypeCode ModAuthority );
 use C4::BackgroundJob;
 use C4::Biblio qw( GetMarcBiblio ModBiblio );
 use C4::MarcModificationTemplates qw( GetModificationTemplateActions GetModificationTemplates ModifyRecordWithTemplate );
-use Koha::Authority;
+use Koha::MetadataRecord::Authority;
 
 my $input = new CGI;
 our $dbh = C4::Context->dbh;
@@ -62,6 +62,7 @@ if ( $completedJobID ) {
         view => 'report',
     );
     output_html_with_http_headers $input, $cookie, $template->output;
+    $job->clear();
     exit;
 }
 
@@ -127,7 +128,7 @@ if ( $op eq 'form' ) {
             push @records, $biblio;
         } else {
             # Retrieve authority information
-            my $authority = Koha::Authority->get_from_authid( $record_id );
+            my $authority = Koha::MetadataRecord::Authority->get_from_authid( $record_id );
             unless ( $authority ) {
                 push @messages, {
                     type => 'warning',
@@ -155,7 +156,7 @@ if ( $op eq 'form' ) {
     my ( $job );
     if ( $runinbackground ) {
         my $job_size = scalar( @record_ids );
-        $job = C4::BackgroundJob->new( $sessionID, "FIXME", $ENV{SCRIPT_NAME}, $job_size );
+        $job = C4::BackgroundJob->new( $sessionID, "FIXME", '/cgi-bin/koha/tools/batch_record_modification.pl', $job_size );
         my $job_id = $job->id;
         if (my $pid = fork) {
             $dbh->{InactiveDestroy}  = 1;
@@ -166,9 +167,8 @@ if ( $op eq 'form' ) {
             exit 0;
         } elsif (defined $pid) {
             close STDOUT;
-            close STDERR;
         } else {
-            warn "fork failed while attempting to run $ENV{'SCRIPT_NAME'} as a background job";
+            warn "fork failed while attempting to run tools/batch_record_modification.pl as a background job";
             exit 0;
         }
     }
@@ -191,7 +191,8 @@ if ( $op eq 'form' ) {
             my $error = eval {
                 my $record = GetMarcBiblio( $biblionumber );
                 ModifyRecordWithTemplate( $mmtid, $record );
-                ModBiblio( $record, $biblionumber );
+                my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber );
+                ModBiblio( $record, $biblionumber, $frameworkcode );
             };
             if ( $error and $error != 1 or $@ ) { # ModBiblio returns 1 if everything as gone well
                 push @messages, {
@@ -212,7 +213,7 @@ if ( $op eq 'form' ) {
             # Authorities
             my $authid = $record_id;
             my $error = eval {
-                my $authority = Koha::Authority->get_from_authid( $authid );
+                my $authority = Koha::MetadataRecord::Authority->get_from_authid( $authid );
                 my $record = $authority->record;
                 ModifyRecordWithTemplate( $mmtid, $record );
                 ModAuthority( $authid, $record, GetAuthTypeCode( $authid ) );