Bug 6520: Display items for staged record
authorJonathan Druart <jonathan.druart@biblibre.com>
Fri, 27 Mar 2015 12:36:05 +0000 (13:36 +0100)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Thu, 16 Apr 2015 16:40:46 +0000 (13:40 -0300)
When records are imported into Koha, the items is stored into the
import_items table.
This marcxml in this table is never retrieved to display items.

Test plan:
1/ Import a records with items
2/ Before importing the batch into the catalog, you can see the marc
of the records, in the table below.
3/ Verify that the items is correctly displayed.

QA note: This patch does not provide test for new subroutines but the
module (C4::ImportBatch) is not tested at all and it will be time
consuming to provide them.

Signed-off-by: Nicole Engard <nengard@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
C4/ImportBatch.pm
catalogue/showmarc.pl

index fe31c45..5f7d8dd 100644 (file)
@@ -169,12 +169,42 @@ sub GetImportRecordMarc {
     my ($import_record_id) = @_;
 
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("SELECT marc, encoding FROM import_records WHERE import_record_id = ?");
-    $sth->execute($import_record_id);
-    my ($marc, $encoding) = $sth->fetchrow();
-    $sth->finish();
+    my ( $marc, $encoding ) = $dbh->selectrow_array(q|
+        SELECT marc, encoding
+        FROM import_records
+        WHERE import_record_id = ?
+    |, undef, $import_record_id );
+
     return $marc, $encoding;
+}
+
+sub GetRecordFromImportBiblio {
+    my ( $import_record_id, $embed_items ) = @_;
+
+    my ($marc) = GetImportRecordMarc($import_record_id);
+    my $record = MARC::Record->new_from_usmarc($marc);
 
+    EmbedItemsInImportBiblio( $record, $import_record_id ) if $embed_items;
+
+    return $record;
+}
+
+sub EmbedItemsInImportBiblio {
+    my ( $record, $import_record_id ) = @_;
+    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber", '');
+    my $dbh = C4::Context->dbh;
+    my $import_items = $dbh->selectall_arrayref(q|
+        SELECT import_items.marcxml
+        FROM import_items
+        WHERE import_record_id = ?
+    |, { Slice => {} }, $import_record_id );
+    my @item_fields;
+    for my $import_item ( @$import_items ) {
+        my $item_marc = MARC::Record::new_from_xml($import_item->{marcxml});
+        push @item_fields, $item_marc->field($itemtag);
+    }
+    $record->append_fields(@item_fields);
+    return $record;
 }
 
 =head2 GetImportRecordMarcXML
index de7fb22..a48a852 100755 (executable)
@@ -43,8 +43,7 @@ my $view= $input->param('viewas')||'';
 
 my $record;
 if ($importid) {
-    my ($marc) = GetImportRecordMarc($importid);
-    $record = MARC::Record->new_from_usmarc($marc);
+    $record = C4::ImportBatch::GetRecordFromImportBiblio( $importid, 'embed_items' );
 }
 else {
     $record =GetMarcBiblio($biblionumber);