Bug 16011: $VERSION - remove use vars $VERSION
[koha_ffzg] / C4 / ImportBatch.pm
index 5f7d8dd..8a69a94 100644 (file)
@@ -4,18 +4,18 @@ package C4::ImportBatch;
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use strict;
 use warnings;
@@ -27,8 +27,10 @@ use C4::Items;
 use C4::Charset;
 use C4::AuthoritiesMarc;
 use C4::MarcModificationTemplates;
+use Koha::Plugins::Handler;
+use Koha::Logger;
 
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
+use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 BEGIN {
        # set the version for version checking
@@ -81,6 +83,8 @@ BEGIN {
        );
 }
 
+our $logger = Koha::Logger->get( { category => 'C4.ImportBatch' } );
+
 =head1 NAME
 
 C4::ImportBatch - manage batches of imported MARC records
@@ -347,11 +351,15 @@ sub ModAuthInBatch {
 
 =head2 BatchStageMarcRecords
 
-  ($batch_id, $num_records, $num_items, @invalid_records) = 
-    BatchStageMarcRecords($encoding, $marc_records, $file_name, $marc_modification_template,
-                          $comments, $branch_code, $parse_items,
-                          $leave_as_staging, 
-                          $progress_interval, $progress_callback);
+( $batch_id, $num_records, $num_items, @invalid_records ) =
+  BatchStageMarcRecords(
+    $encoding,                   $marc_records,
+    $file_name,                  $to_marc_plugin,
+    $marc_modification_template, $comments,
+    $branch_code,                $parse_items,
+    $leave_as_staging,           $progress_interval,
+    $progress_callback
+  );
 
 =cut
 
@@ -360,6 +368,7 @@ sub BatchStageMarcRecords {
     my $encoding = shift;
     my $marc_records = shift;
     my $file_name = shift;
+    my $to_marc_plugin = shift;
     my $marc_modification_template = shift;
     my $comments = shift;
     my $branch_code = shift;
@@ -391,6 +400,14 @@ sub BatchStageMarcRecords {
         SetImportBatchItemAction($batch_id, 'ignore');
     }
 
+    $marc_records = Koha::Plugins::Handler->run(
+        {
+            class  => $to_marc_plugin,
+            method => 'to_marc',
+            params => { data => $marc_records }
+        }
+    ) if $to_marc_plugin;
+
     my $marc_type = C4::Context->preference('marcflavour');
     $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
     my @invalid_records = ();
@@ -798,6 +815,8 @@ sub BatchCommitItems {
 sub BatchRevertRecords {
     my $batch_id = shift;
 
+    $logger->trace("C4::ImportBatch::BatchRevertRecords( $batch_id )");
+
     my $record_type;
     my $num_deleted = 0;
     my $num_errors = 0;
@@ -853,6 +872,10 @@ sub BatchRevertRecords {
             if ($record_type eq 'biblio') {
                 my $biblionumber = $rowref->{'matched_biblionumber'};
                 my $oldbiblio = GetBiblio($biblionumber);
+
+                $logger->info("C4::ImportBatch::BatchRevertRecords: Biblio record $biblionumber does not exist, restoration of this record was skipped") unless $oldbiblio;
+                next unless $oldbiblio; # Record has since been deleted. Deleted records should stay deleted.
+
                 $num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'});
                 ModBiblio($old_record, $biblionumber, $oldbiblio->{'frameworkcode'});
             } else {