Bug 22789: (follow-up) Fix atomic update, GUI and more than one hold
[koha-ffzg.git] / C4 / ImportBatch.pm
index 7e252da..7d0d7ba 100644 (file)
@@ -83,8 +83,6 @@ BEGIN {
        );
 }
 
-our $logger = Koha::Logger->get( { category => 'C4.ImportBatch' } );
-
 =head1 NAME
 
 C4::ImportBatch - manage batches of imported MARC records
@@ -204,7 +202,7 @@ sub EmbedItemsInImportBiblio {
     |, { Slice => {} }, $import_record_id );
     my @item_fields;
     for my $import_item ( @$import_items ) {
-        my $item_marc = MARC::Record::new_from_xml($import_item->{marcxml});
+        my $item_marc = MARC::Record::new_from_xml($import_item->{marcxml}, 'UTF-8');
         push @item_fields, $item_marc->field($itemtag);
     }
     $record->append_fields(@item_fields);
@@ -800,6 +798,8 @@ sub BatchCommitItems {
 sub BatchRevertRecords {
     my $batch_id = shift;
 
+    my $logger = Koha::Logger->get( { category => 'C4.ImportBatch' } );
+
     $logger->trace("C4::ImportBatch::BatchRevertRecords( $batch_id )");
 
     my $record_type;
@@ -910,8 +910,9 @@ sub BatchRevertItems {
     $sth->bind_param(1, $import_record_id);
     $sth->execute();
     while (my $row = $sth->fetchrow_hashref()) {
-        my $error = DelItemCheck( $biblionumber, $row->{'itemnumber'});
-        if ($error == 1){
+        my $item = Koha::Items->find($row->{itemnumber});
+        my $error = $item->safe_delete;
+        if ($error eq '1'){
             my $updsth = $dbh->prepare("UPDATE import_items SET status = ? WHERE import_items_id = ?");
             $updsth->bind_param(1, 'reverted');
             $updsth->bind_param(2, $row->{'import_items_id'});
@@ -1114,7 +1115,7 @@ sub GetImportRecordsRange {
     my $dbh = C4::Context->dbh;
 
     my $order_by = $parameters->{order_by} || 'import_record_id';
-    ( $order_by ) = grep( /^$order_by$/, qw( import_record_id title status overlay_status ) ) ? $order_by : 'import_record_id';
+    ( $order_by ) = grep( { $_ eq $order_by } qw( import_record_id title status overlay_status ) ) ? $order_by : 'import_record_id';
 
     my $order_by_direction =
       uc( $parameters->{order_by_direction} // 'ASC' ) eq 'DESC' ? 'DESC' : 'ASC';
@@ -1501,10 +1502,10 @@ sub RecordsFromISO2709File {
     my $marc_type = C4::Context->preference('marcflavour');
     $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
 
-    open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n";
+    open my $fh, '<', $input_file or die "$0: cannot open input file $input_file: $!\n";
     my @marc_records;
     $/ = "\035";
-    while (<IN>) {
+    while (<$fh>) {
         s/^\s+//;
         s/\s+$//;
         next unless $_; # skip if record has only whitespace, as might occur
@@ -1516,7 +1517,7 @@ sub RecordsFromISO2709File {
                 "Unexpected charset $charset_guessed, expecting $encoding";
         }
     }
-    close IN;
+    close $fh;
     return ( \@errors, \@marc_records );
 }
 
@@ -1559,15 +1560,15 @@ sub RecordsFromMarcPlugin {
     return \@return if !$input_file || !$plugin_class;
 
     # Read input file
-    open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n";
+    open my $fh, '<', $input_file or die "$0: cannot open input file $input_file: $!\n";
     $/ = "\035";
-    while (<IN>) {
+    while (<$fh>) {
         s/^\s+//;
         s/\s+$//;
         next unless $_;
         $text .= $_;
     }
-    close IN;
+    close $fh;
 
     # Convert to large MARC blob with plugin
     $text = Koha::Plugins::Handler->run({