Bug 8015: (follow-up) update stage_file.pl
[koha.git] / tools / stage-marc-import.pl
index b113332..8d6ab1a 100755 (executable)
@@ -41,6 +41,7 @@ use C4::ImportBatch;
 use C4::Matcher;
 use C4::UploadedFile;
 use C4::BackgroundJob;
+use C4::MarcModificationTemplates;
 
 my $input = new CGI;
 my $dbh = C4::Context->dbh;
@@ -55,7 +56,10 @@ my $nomatch_action = $input->param('nomatch_action');
 my $parse_items = $input->param('parse_items');
 my $item_action = $input->param('item_action');
 my $comments = $input->param('comments');
-my $syntax = $input->param('syntax');
+my $record_type = $input->param('record_type');
+my $encoding = $input->param('encoding');
+my $marc_modification_template = $input->param('marc_modification_template_id');
+
 my ($template, $loggedinuser, $cookie)
        = get_template_and_user({template_name => "tools/stage-marc-import.tmpl",
                                        query => $input,
@@ -108,14 +112,14 @@ if ($completedJobID) {
 
             my $reply = CGI->new("");
             print $reply->header(-type => 'text/html');
-            print "{ jobID: '$jobID' }";
+            print '{"jobID":"' . $jobID . '"}';
             exit 0;
         } elsif (defined $pid) {
             # child
             # close STDOUT to signal to Apache that
             # we're now running in the background
             close STDOUT;
-            close STDERR;
+            # close STDERR; # there is no good reason to close STDERR
         } else {
             # fork failed, so exit immediately
             warn "fork failed while attempting to run $ENV{'SCRIPT_NAME'} as a background job";
@@ -130,10 +134,10 @@ if ($completedJobID) {
     }
 
     # FIXME branch code
-    my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($syntax, $marcrecord, $filename, 
-                                                                                   $comments, '', $parse_items, 0,
-                                                                                   50, staging_progress_callback($job, $dbh));
+    my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($record_type, $encoding, $marcrecord, $filename, $marc_modification_template, $comments, '', $parse_items, 0, 50, staging_progress_callback($job, $dbh));
+
     $dbh->commit();
+
     my $num_with_matches = 0;
     my $checked_matches = 0;
     my $matcher_failed = 0;
@@ -143,7 +147,7 @@ if ($completedJobID) {
         if (defined $matcher) {
             $checked_matches = 1;
             $matcher_code = $matcher->code();
-            $num_with_matches = BatchFindBibDuplicates($batch_id, $matcher, 
+            $num_with_matches = BatchFindDuplicates($batch_id, $matcher,
                                                        10, 50, matching_progress_callback($job, $dbh));
             SetImportBatchMatcher($batch_id, $matcher_id);
             SetImportBatchOverlayAction($batch_id, $overlay_action);
@@ -179,6 +183,8 @@ if ($completedJobID) {
                          matcher_code => $matcher_code,
                          import_batch_id => $batch_id
                         );
+
+
     }
 
 } else {
@@ -188,6 +194,10 @@ if ($completedJobID) {
     }
     my @matchers = C4::Matcher::GetMatcherList();
     $template->param(available_matchers => \@matchers);
+
+    my @templates = GetModificationTemplates();
+    $template->param( MarcModificationTemplatesLoop => \@templates );
+
 }
 
 output_html_with_http_headers $input, $cookie, $template->output;