[Koha-patches] [PATCH] Bug 12252 - OAI-PMH result includes item data

David Cook dcook at prosentient.com.au
Wed May 14 05:42:01 CEST 2014


From: Robin Sheat <robin at catalyst.net.nz>

GetRecord for OAI-PMH was pulling the MARCXML directly from the
database. Now it uses GetMarcBiblio and includes the item data with it,
making it more generally useful.

Test plan:
* Run an OAI-PMH query, for example:
http://koha/cgi-bin/koha/oai.pl?verb=GetRecord&identifier=KOHA-OAI-TEST:52&metadataPrefix=marcxml
  to fetch biblionumber 52
* Note that it doesn't include the 952 data
* Apply the patch
* Do the same thing, but this time see that the 952 data is at the
  bottom of the MARCXML.

Note:
* This patch also includes a small tidy-up in C4::Biblios to group
  things semantically a bit better, so I don't spend ages looking for a
  function that was staring me in the face all along again.

Signed-off-by: David Cook <dcook at prosentient.com.au>

Works as described. Simple yet useful patch.
---
 C4/Biblio.pm |   16 ++++++++--------
 opac/oai.pl  |   12 +++++++++---
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index 0fb453d..b6f98b4 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -54,13 +54,14 @@ BEGIN {
 
     # to get something
     push @EXPORT, qw(
-      &GetBiblio
-      &GetBiblioData
-      &GetBiblioItemData
-      &GetBiblioItemInfosOf
-      &GetBiblioItemByBiblioNumber
-      &GetBiblioFromItemNumber
-      &GetBiblionumberFromItemnumber
+      GetBiblio
+      GetBiblioData
+      GetMarcBiblio
+      GetBiblioItemData
+      GetBiblioItemInfosOf
+      GetBiblioItemByBiblioNumber
+      GetBiblioFromItemNumber
+      GetBiblionumberFromItemnumber
 
       &GetRecordValue
       &GetFieldMapping
@@ -74,7 +75,6 @@ BEGIN {
       &GetMarcISBN
       &GetMarcISSN
       &GetMarcSubjects
-      &GetMarcBiblio
       &GetMarcAuthors
       &GetMarcSeries
       &GetMarcHosts
diff --git a/opac/oai.pl b/opac/oai.pl
index b453408..b580a27 100755
--- a/opac/oai.pl
+++ b/opac/oai.pl
@@ -247,7 +247,9 @@ package C4::OAI::GetRecord;
 use strict;
 use warnings;
 use HTTP::OAI;
+use C4::Biblio;
 use C4::OAI::Sets;
+use MARC::File::XML;
 
 use base ("HTTP::OAI::GetRecord");
 
@@ -259,14 +261,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 ) {
+    my ($timestamp);
+    unless ( ($timestamp) = $sth->fetchrow ) {
         return HTTP::OAI::Response->new(
             requestURL  => $repository->self_url(),
             errors      => [ new HTTP::OAI::Error(
@@ -276,6 +278,10 @@ sub new {
         );
     }
 
+    # We fetch it using this method, rather than the database directly,
+    # so it'll include the item data
+    my $record = GetMarcBiblio($biblionumber, 1);
+    my $marcxml = $record->as_xml();
     my $oai_sets = GetOAISetsBiblio($biblionumber);
     my @setSpecs;
     foreach (@$oai_sets) {
-- 
1.7.7.4




More information about the Koha-patches mailing list