Bugzilla – Attachment 28345 Details for
Bug 12252
OAI-PMH GetRecord result doesn't include item data
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12252 - OAI-PMH items respect OpacHiddenItems
Bug-12252---OAI-PMH-items-respect-OpacHiddenItems.patch (text/plain), 5.32 KB, created by
Robin Sheat
on 2014-05-20 05:30:03 UTC
(
hide
)
Description:
Bug 12252 - OAI-PMH items respect OpacHiddenItems
Filename:
MIME Type:
Creator:
Robin Sheat
Created:
2014-05-20 05:30:03 UTC
Size:
5.32 KB
patch
obsolete
>From cdefa14c1cf07c35a850a871bf4e8565cdb3006d Mon Sep 17 00:00:00 2001 >From: Robin Sheat <robin@catalyst.net.nz> >Date: Tue, 20 May 2014 17:15:52 +1200 >Subject: [PATCH] Bug 12252 - OAI-PMH items respect OpacHiddenItems > >This allows the OAI-PMH service to not provide item information when >there is a rule that would supress it in OpacHiddenItems. > >Test plan: >* Find an OAI-PMH URL that shows you some items. >* Add an entry to OpacHiddenItems that would block that. >* Check that it's blocked. >--- > C4/Biblio.pm | 67 ++++++++++++++++++++++++++++++++++++++++++++++-------------- > opac/oai.pl | 2 +- > 2 files changed, 53 insertions(+), 16 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index b6f98b4..8f5d51e 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -1261,18 +1261,34 @@ sub GetMarcSubfieldStructureFromKohaField { > > =head2 GetMarcBiblio > >- my $record = GetMarcBiblio($biblionumber, [$embeditems]); >+ my $record = GetMarcBiblio($biblionumber, [$embeditems], [$opac]); > >-Returns MARC::Record representing bib identified by >-C<$biblionumber>. If no bib exists, returns undef. >-C<$embeditems>. If set to true, items data are included. >-The MARC record contains biblio data, and items data if $embeditems is set to true. >+Returns MARC::Record representing a biblio record, or C<undef> if the >+biblionumber doesn't exist. >+ >+=over 4 >+ >+=item C<$biblionumber> >+ >+the biblionumber >+ >+=item C<$embeditems> >+ >+set to true to include item information. >+ >+=item C<$opac> >+ >+set to true to make the result suited for OPAC view. This causes things like >+OpacHiddenItems to be applied. >+ >+=back > > =cut > > sub GetMarcBiblio { > my $biblionumber = shift; > my $embeditems = shift || 0; >+ my $opac = shift || 0; > my $dbh = C4::Context->dbh; > my $sth = $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? "); > $sth->execute($biblionumber); >@@ -1282,15 +1298,21 @@ sub GetMarcBiblio { > my $record = MARC::Record->new(); > > if ($marcxml) { >- $record = eval { MARC::Record::new_from_xml( $marcxml, "utf8", C4::Context->preference('marcflavour') ) }; >+ $record = eval { >+ MARC::Record::new_from_xml( $marcxml, "utf8", >+ C4::Context->preference('marcflavour') ); >+ }; > if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; } > return unless $record; > >- C4::Biblio::_koha_marc_update_bib_ids($record, '', $biblionumber, $biblionumber); >- C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) if ($embeditems); >+ C4::Biblio::_koha_marc_update_bib_ids( $record, '', $biblionumber, >+ $biblionumber ); >+ C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, $opac ) >+ if ($embeditems); > > return $record; >- } else { >+ } >+ else { > return; > } > } >@@ -2882,17 +2904,19 @@ sub ModZebra { > > =head2 EmbedItemsInMarcBiblio > >- EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers); >+ EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers, $opac); > > Given a MARC::Record object containing a bib record, > modify it to include the items attached to it as 9XX > per the bib's MARC framework. >-if $itemnumbers is defined, only specified itemnumbers are embedded >+if $itemnumbers is defined, only specified itemnumbers are embedded. >+ >+If $opac is true, then opac-relevant suppressions are included. > > =cut > > sub EmbedItemsInMarcBiblio { >- my ($marc, $biblionumber, $itemnumbers) = @_; >+ my ($marc, $biblionumber, $itemnumbers, $opac) = @_; > if ( !$marc ) { > carp 'EmbedItemsInMarcBiblio: No MARC record passed'; > return; >@@ -2909,10 +2933,23 @@ sub EmbedItemsInMarcBiblio { > $sth->execute($biblionumber); > my @item_fields; > my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); >- while (my ($itemnumber) = $sth->fetchrow_array) { >+ my @items; >+ my $opachiddenitems = $opac >+ && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ ); >+ require C4::Items; >+ while ( my ($itemnumber) = $sth->fetchrow_array ) { > next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers; >- require C4::Items; >- my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber); >+ my $i = C4::Items::GetItem($itemnumber) if $opachiddenitems; >+ push @items, { itemnumber => $itemnumber, item => $i }; >+ } >+ my @hiddenitems = >+ C4::Items::GetHiddenItemnumbers( map { $_->{item} } @items ) >+ if $opachiddenitems; >+ # Convert to a hash for quick searching >+ my %hiddenitems = map { $_ => 1 } @hiddenitems; >+ foreach my $itemnumber ( map { $_->{itemnumber} } @items ) { >+ next if $hiddenitems{$itemnumber}; >+ my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); > push @item_fields, $item_marc->field($itemtag); > } > $marc->append_fields(@item_fields); >diff --git a/opac/oai.pl b/opac/oai.pl >index b580a27..ca3ac59 100755 >--- a/opac/oai.pl >+++ b/opac/oai.pl >@@ -280,7 +280,7 @@ 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 $record = GetMarcBiblio($biblionumber, 1, 1); > my $marcxml = $record->as_xml(); > my $oai_sets = GetOAISetsBiblio($biblionumber); > my @setSpecs; >-- >1.8.3.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 12252
:
28228
|
28229
|
28243
|
28344
|
28345
|
29159
|
29160
|
33120
|
33121
|
33122
|
34890
|
35006
|
35007
|
35008
|
35009
|
35010
|
35011
|
41135
|
41136
|
41137
|
41138
|
41139
|
41140
|
41175
|
41176
|
41177
|
41178
|
41179
|
41180
|
42018
|
42019
|
42020
|
42021
|
42022
|
42023
|
42024
|
42314
|
42575
|
42576
|
42577
|
42578
|
42579
|
42580
|
42581