From 18db64ee5b80c5ac15bd6142ac304b65ad3deafd Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Wed, 17 Dec 2014 17:15:34 +0100
Subject: [PATCH] Bug 13475: OAI should return items

Since bug 5579, items are not stored in DB.
The oai script does not have been changed.

Test plan:
go on
1/ Enable the pref OAI-PMH
2/ Set OAI-PMH:archiveID = KOHA-OAI-TEST (or what you want)
3/ Go on
oai.pl?verb=GetRecord&metadataPrefix=marcxml&identifier=KOHA-OAI-TEST:[BIBLIONUMBER]
with [BIBLIONUMBER] a record's biblionumber containing items.
The marcxml should be returned with items.
---
 opac/oai.pl | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/opac/oai.pl b/opac/oai.pl
index b453408..e965134 100755
--- a/opac/oai.pl
+++ b/opac/oai.pl
@@ -259,14 +259,14 @@ sub new {
 
     my $dbh = C4::Context->dbh;
     my $sth = $dbh->prepare("
-        SELECT marcxml, timestamp
+        SELECT timestamp
         FROM   biblioitems
         WHERE  biblionumber=? " );
     my $prefix = $repository->{koha_identifier} . ':';
     my ($biblionumber) = $args{identifier} =~ /^$prefix(.*)/;
     $sth->execute( $biblionumber );
     my ($marcxml, $timestamp);
-    unless ( ($marcxml, $timestamp) = $sth->fetchrow ) {
+    unless ( ($timestamp) = $sth->fetchrow ) {
         return HTTP::OAI::Response->new(
             requestURL  => $repository->self_url(),
             errors      => [ new HTTP::OAI::Error(
@@ -275,6 +275,8 @@ sub new {
                 ) ] ,
         );
     }
+    my $record = C4::Biblio::GetMarcBiblio( $biblionumber, 1);
+    $marcxml = C4::Record::marc2marcxml( $record );
 
     my $oai_sets = GetOAISetsBiblio($biblionumber);
     my @setSpecs;
@@ -452,6 +454,7 @@ use strict;
 use warnings;
 use HTTP::OAI;
 use C4::OAI::Sets;
+use C4::Record;
 
 use base ("HTTP::OAI::ListRecords");
 
@@ -468,7 +471,7 @@ sub new {
         $set = GetOAISetBySpec($token->{'set'});
     }
     my $sql = "
-        SELECT biblioitems.biblionumber, biblioitems.marcxml, biblioitems.timestamp
+        SELECT biblioitems.biblionumber, biblioitems.timestamp
         FROM biblioitems
     ";
     $sql .= " JOIN oai_sets_biblios ON biblioitems.biblionumber = oai_sets_biblios.biblionumber " if defined $set;
@@ -485,12 +488,14 @@ sub new {
     $sth->execute( @bind_params );
 
     my $pos = $token->{offset};
-    while ( my ($biblionumber, $marcxml, $timestamp) = $sth->fetchrow ) {
+    while ( my ($biblionumber, $timestamp) = $sth->fetchrow ) {
         my $oai_sets = GetOAISetsBiblio($biblionumber);
         my @setSpecs;
         foreach (@$oai_sets) {
             push @setSpecs, $_->{spec};
         }
+        my $record = C4::Biblio::GetMarcBiblio( $biblionumber, 1 );
+        $marcxml = C4::Record::marc2marcxml( $record );
         $self->record( C4::OAI::Record->new(
             $repository, $marcxml, $timestamp, \@setSpecs,
             identifier      => $repository->{ koha_identifier } . ':' . $biblionumber,
-- 
2.1.0