Bug 12252: OAI-PMH result includes item data

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@prosentient.com.au>

Works as described. Simple yet useful patch.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>

Signed-off-by: Frederic Demians <f.demians@tamil.fr>

952/995 item fields are back in response to GetRecord OAI verb.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>

Signed-off-by: Signed-off-by: Gaetan Boisson <gaetan.boisson@biblibre.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
This commit is contained in:
Robin Sheat 2014-05-14 14:39:03 +12:00 committed by Tomas Cohen Arazi
parent 7349777f14
commit 80aa17d266
2 changed files with 44 additions and 33 deletions

View file

@ -57,13 +57,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
@ -77,7 +78,6 @@ BEGIN {
&GetMarcISBN
&GetMarcISSN
&GetMarcSubjects
&GetMarcBiblio
&GetMarcAuthors
&GetMarcSeries
&GetMarcHosts

View file

@ -288,7 +288,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");
@ -299,31 +301,39 @@ sub new {
my $self = HTTP::OAI::GetRecord->new(%args);
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("
SELECT timestamp
FROM biblioitems
WHERE biblionumber=? " );
my $prefix = $repository->{koha_identifier} . ':';
my ($biblionumber) = $args{identifier} =~ /^$prefix(.*)/;
my ($marcxml, $timestamp);
my $deleted = 0;
unless ( ($marcxml, $timestamp) = $dbh->selectrow_array(q/
SELECT marcxml, timestamp
FROM biblioitems
WHERE biblionumber=? /, undef, $biblionumber)) {
unless ( ($marcxml, $timestamp) = $dbh->selectrow_array(q/
SELECT biblionumber, timestamp
FROM deletedbiblio
WHERE biblionumber=? /, undef, $biblionumber )) {
return HTTP::OAI::Response->new(
requestURL => $repository->self_url(),
errors => [ new HTTP::OAI::Error(
$sth->execute( $biblionumber );
my ($timestamp);
unless ( ($timestamp) = $sth->fetchrow ) {
unless ( ($timestamp) = $dbh->selectrow_array(q/
SELECT timestamp
FROM deletedbiblio
WHERE biblionumber=? /, undef, $biblionumber ))
{
return HTTP::OAI::Response->new(
requestURL => $repository->self_url(),
errors => [ new HTTP::OAI::Error(
code => 'idDoesNotExist',
message => "There is no biblio record with this identifier",
) ] ,
);
} else {
$deleted = 1;
}
) ],
);
}
else {
$deleted = 1;
}
}
# We fetch it using this method, rather than the database directly,
# so it'll include the item data
my $marcxml;
unless ($deleted) {
my $record = GetMarcBiblio($biblionumber, 1);
$marcxml = $record->as_xml();
}
my $oai_sets = GetOAISetsBiblio($biblionumber);
my @setSpecs;
@ -332,10 +342,11 @@ sub new {
}
#$self->header( HTTP::OAI::Header->new( identifier => $args{identifier} ) );
($deleted == 1) ? $self->record( C4::OAI::DeletedRecord->new(
$timestamp, \@setSpecs, %args ) )
: $self->record( C4::OAI::Record->new(
$repository, $marcxml, $timestamp, \@setSpecs, %args ) );
$self->record(
$deleted
? C4::OAI::DeletedRecord->new($timestamp, \@setSpecs, %args)
: C4::OAI::Record->new($repository, $marcxml, $timestamp, \@setSpecs, %args);
);
return $self;
}