Bugzilla – Attachment 67198 Details for
Bug 19331
When filtering by library, the analyticals are not recovered
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19331 - When filtering by library, the analyticals are not recovered
Bug-19331---When-filtering-by-library-the-analytic.patch (text/plain), 9.72 KB, created by
leire
on 2017-09-19 07:54:45 UTC
(
hide
)
Description:
Bug 19331 - When filtering by library, the analyticals are not recovered
Filename:
MIME Type:
Creator:
leire
Created:
2017-09-19 07:54:45 UTC
Size:
9.72 KB
patch
obsolete
>From bb7c8202cc6c5632cdb5510c834e6540ae8ad5d0 Mon Sep 17 00:00:00 2001 >From: Leire Diez <leire@scanbit.net> >Date: Tue, 19 Sep 2017 09:42:04 +0200 >Subject: [PATCH] Bug 19331 - When filtering by library, the analyticals are > not recovered > >When the zebra indexes are rebuild, whe put in the analyticals, the copies of the source document > >Test plan: >1) Apply patch >2) Look for a analytical >3) Filter by a library with items in its source document >4) Check if the analytical is found > >Sponsored-by: Scanbit >--- > C4/Biblio.pm | 22 ++++++++++++++++++---- > C4/Items.pm | 32 +++++++++++++++++++++++++++++++- > C4/Search.pm | 28 ---------------------------- > C4/XSLT.pm | 10 ++++++++++ > misc/migration_tools/rebuild_zebra.pl | 18 +++++++++++++++++- > 5 files changed, 76 insertions(+), 34 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index a82dbed..cffdc8a 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -1139,7 +1139,8 @@ sub GetMarcSubfieldStructureFromKohaField { > my $record = GetMarcBiblio({ > biblionumber => $biblionumber, > embed_items => $embeditems, >- opac => $opac }); >+ opac => $opac, >+ hostItemsInfo => $hostItemsInfo }); > > Returns MARC::Record representing a biblio record, or C<undef> if the > biblionumber doesn't exist. >@@ -1178,6 +1179,7 @@ sub GetMarcBiblio { > my $biblionumber = $params->{biblionumber}; > my $embeditems = $params->{embed_items} || 0; > my $opac = $params->{opac} || 0; >+ my $hostItemsInfo = $params->{hostItemsInfo} || 0; > > if (not defined $biblionumber) { > carp 'GetMarcBiblio called with undefined biblionumber'; >@@ -1205,7 +1207,7 @@ sub GetMarcBiblio { > > C4::Biblio::_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber, > $biblioitemnumber ); >- C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, $opac ) >+ C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, $opac, $hostItemsInfo) > if ($embeditems); > > return $record; >@@ -2923,7 +2925,7 @@ sub ModZebra { > > =head2 EmbedItemsInMarcBiblio > >- EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers, $opac); >+ EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers, $opac, $hostItemsInfo); > > Given a MARC::Record object containing a bib record, > modify it to include the items attached to it as 9XX >@@ -2935,11 +2937,12 @@ If $opac is true, then opac-relevant suppressions are included. > =cut > > sub EmbedItemsInMarcBiblio { >- my ($marc, $biblionumber, $itemnumbers, $opac) = @_; >+ my ($marc, $biblionumber, $itemnumbers, $opac, $hostItemsInfo) = @_; > if ( !$marc ) { > carp 'EmbedItemsInMarcBiblio: No MARC record passed'; > return; > } >+ > > $itemnumbers = [] unless defined $itemnumbers; > >@@ -2961,6 +2964,17 @@ sub EmbedItemsInMarcBiblio { > my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef; > push @items, { itemnumber => $itemnumber, item => $i }; > } >+ >+ if ($hostItemsInfo){ >+ my $record = GetMarcBiblio({ biblionumber => $biblionumber }); >+ my @hostitems = C4::Items::GetHostItem($record); >+ my $itemnumber = 0; >+ foreach my $item (@hostitems){ >+ $itemnumber = $item->{itemnumber} if ($item);; >+ push @items, { itemnumber => $itemnumber, item => $item }; >+ } >+ } >+ > my @hiddenitems = > $opachiddenitems > ? C4::Items::GetHiddenItemnumbers( map { $_->{item} } @items ) >diff --git a/C4/Items.pm b/C4/Items.pm >index 0b6a77e..4759c80 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -73,6 +73,7 @@ BEGIN { > GetItemsInfo > GetItemsLocationInfo > GetHostItemsInfo >+ GetHostItem > GetItemnumbersForBiblio > get_hostitemnumbers_of > GetItemnumberFromBarcode >@@ -1235,6 +1236,35 @@ sub GetHostItemsInfo { > return @returnitemsInfo; > } > >+=head2 GetHostItem >+ >+ $hostiteminfo = GetHostItem($record); >+ Returns the item for items linked to records via a host field >+ >+=cut >+ >+sub GetHostItem { >+ my ($record) = @_; >+ my @returnitemsInfo; >+ >+ if (C4::Context->preference('marcflavour') eq 'MARC21' || >+ C4::Context->preference('marcflavour') eq 'NORMARC'){ >+ foreach my $hostfield ( $record->field('773') ) { >+ my $hostbiblionumber = $hostfield->subfield("0"); >+ my $linkeditemnumber = $hostfield->subfield("9"); >+ my $hostitem = GetItem($linkeditemnumber); >+ push (@returnitemsInfo,$hostitem); >+ } >+ } elsif ( C4::Context->preference('marcflavour') eq 'UNIMARC'){ >+ foreach my $hostfield ( $record->field('461') ) { >+ my $hostbiblionumber = $hostfield->subfield("0"); >+ my $linkeditemnumber = $hostfield->subfield("9"); >+ my $hostitem = GetItem($linkeditemnumber); >+ push (@returnitemsInfo,$hostitem); >+ } >+ } >+ return @returnitemsInfo; >+} > > =head2 GetLastAcquisitions > >@@ -1321,7 +1351,7 @@ references on array of itemnumbers. > > sub get_hostitemnumbers_of { > my ($biblionumber) = @_; >- my $marcrecord = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); >+ my $marcrecord = C4::Biblio::GetMarcBiblio($biblionumber); > > return unless $marcrecord; > >diff --git a/C4/Search.pm b/C4/Search.pm >index 9278f26..544ed35 100644 >--- a/C4/Search.pm >+++ b/C4/Search.pm >@@ -1997,34 +1997,6 @@ sub searchResults { > # Pull out the items fields > my @fields = $marcrecord->field($itemtag); > my $marcflavor = C4::Context->preference("marcflavour"); >- # adding linked items that belong to host records >- my $analyticsfield = '773'; >- if ($marcflavor eq 'MARC21' || $marcflavor eq 'NORMARC') { >- $analyticsfield = '773'; >- } elsif ($marcflavor eq 'UNIMARC') { >- $analyticsfield = '461'; >- } >- foreach my $hostfield ( $marcrecord->field($analyticsfield)) { >- my $hostbiblionumber = $hostfield->subfield("0"); >- my $linkeditemnumber = $hostfield->subfield("9"); >- if(!$hostbiblionumber eq undef){ >- my $hostbiblio = GetMarcBiblio({ >- biblionumber => $hostbiblionumber, >- embed_items => 1 }); >- my ($itemfield, undef) = GetMarcFromKohaField( 'items.itemnumber', GetFrameworkCode($hostbiblionumber) ); >- if(!$hostbiblio eq undef){ >- my @hostitems = $hostbiblio->field($itemfield); >- foreach my $hostitem (@hostitems){ >- if ($hostitem->subfield("9") eq $linkeditemnumber){ >- my $linkeditem =$hostitem; >- # append linked items if they exist >- if (!$linkeditem eq undef){ >- push (@fields, $linkeditem);} >- } >- } >- } >- } >- } > > # Setting item statuses for display > my @available_items_loop; >diff --git a/C4/XSLT.pm b/C4/XSLT.pm >index bf2647a..48a13ea 100644 >--- a/C4/XSLT.pm >+++ b/C4/XSLT.pm >@@ -273,6 +273,16 @@ sub buildKohaItemsNamespace { > my %hi = map {$_ => 1} @$hidden_items; > @items = grep { !$hi{$_->{itemnumber}} } @items; > } >+ >+ my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); >+ my @hostitems = C4::Items::GetHostItemsInfo($record); >+ if ($hidden_items && @$hidden_items) { >+ my %hi = map {$_ => 1} @$hidden_items; >+ @hostitems = grep { !$hi{$_->{itemnumber}} } @hostitems; >+ push (@items, @hostitems); >+ } else{ >+ push (@items, @hostitems); >+ } > > my $shelflocations = > { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => GetFrameworkCode($biblionumber), kohafield => 'items.location' } ) }; >diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl >index c3f41df..a1e0bab 100755 >--- a/misc/migration_tools/rebuild_zebra.pl >+++ b/misc/migration_tools/rebuild_zebra.pl >@@ -521,6 +521,22 @@ sub export_marc_records_from_sth { > substr($marcxml, 0, length($marcxml)-10) . > substr($itemsxml, index($itemsxml, "</leader>\n", 0) + 10); > } >+ my $record = GetMarcBiblio({ biblionumber => $record_number}); >+ my @hostitems = GetHostItemsInfo($record); >+ if (@hostitems){ >+ my $record = MARC::Record->new; >+ $record->encoding('UTF-8'); >+ my @itemsrecord; >+ foreach my $item (@hostitems){ >+ my $record = Item2Marc($item, $record_number); >+ push @itemsrecord, $record->field($itemtag); >+ } >+ $record->insert_fields_ordered(@itemsrecord); >+ my $itemsxml = $record->as_xml_record(); >+ $marcxml = >+ substr($marcxml, 0, length($marcxml)-10) . >+ substr($itemsxml, index($itemsxml, "</leader>\n", 0) + 10); >+ } > } > # extra test to ensure that result is valid XML; otherwise > # Zebra won't parse it in DOM mode >@@ -675,7 +691,7 @@ sub get_raw_marc_record { > > my $marc; > if ($record_type eq 'biblio') { >- eval { $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $record_number, embed_items => 1 }); }; >+ eval { $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $record_number, embed_items => 1, opac => 0, hostItemsInfo => 1 }); }; > if ($@ || !$marc) { > # here we do warn since catching an exception > # means that the bib was found but failed >-- >2.1.4
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 19331
: 67198 |
67336