MT 1926 : Adding Internal notes to serials list display
[koha.git] / C4 / ImportBatch.pm
index f978d04..f67cdfe 100644 (file)
@@ -43,6 +43,7 @@ BEGIN {
     BatchFindBibDuplicates
     BatchCommitBibRecords
     BatchRevertBibRecords
+    CleanBatch
 
     GetAllImportBatches
     GetImportBatchRangeDesc
@@ -654,6 +655,8 @@ sub BatchRevertBibRecords {
             $num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'});
             SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted');
         }
+        my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = NULL WHERE import_record_id = ?");
+        $sth2->execute($rowref->{'import_record_id'});
     }
 
     $sth->finish();
@@ -696,6 +699,29 @@ sub BatchRevertItems {
     return $num_items_deleted;
 }
 
+=head2 CleanBatch
+
+=over 4
+
+CleanBatch($batch_id)
+
+=back
+
+Deletes all staged records from the import batch
+and sets the status of the batch to 'cleaned'.  Note
+that deleting a stage record does *not* affect
+any record that has been committed to the database.
+
+=cut
+
+sub CleanBatch {
+    my $batch_id = shift;
+    return unless defined $batch_id;
+
+    C4::Context->dbh->do('DELETE FROM import_records WHERE import_batch_id = ?', {}, $batch_id);
+    SetImportBatchStatus($batch_id, 'cleaned');
+}
+
 =head2 GetAllImportBatches
 
 =over 4
@@ -813,7 +839,7 @@ sub GetImportBibliosRange {
 
     my $dbh = C4::Context->dbh;
     my $sth = $dbh->prepare_cached("SELECT title, author, isbn, issn, import_record_id, record_sequence,
-                                           status, overlay_status
+                                           matched_biblionumber, status, overlay_status
                                     FROM   import_records
                                     JOIN   import_biblios USING (import_record_id)
                                     WHERE  import_batch_id = ?
@@ -869,15 +895,14 @@ sub GetImportBatchStatus {
     my ($batch_id) = @_;
 
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("SELECT import_status FROM import_batches WHERE batch_id = ?");
+    my $sth = $dbh->prepare("SELECT import_status FROM import_batches WHERE import_batch_id = ?");
     $sth->execute($batch_id);
     my ($status) = $sth->fetchrow_array();
     $sth->finish();
-    return;
+    return $status;
 
 }
 
-
 =head2 SetImportBatchStatus
 
 =over 4