Bugzilla – Attachment 144563 Details for
Bug 32463
Embed analytical items into bibliographic records export
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32463: Embed analytical items into bibliographic records export
Bug-32463-Embed-analytical-items-into-bibliographi.patch (text/plain), 5.17 KB, created by
Fridolin Somers
on 2022-12-14 06:12:31 UTC
(
hide
)
Description:
Bug 32463: Embed analytical items into bibliographic records export
Filename:
MIME Type:
Creator:
Fridolin Somers
Created:
2022-12-14 06:12:31 UTC
Size:
5.17 KB
patch
obsolete
>From 7d4454cf519801b4c24bb0cb3225d2e6f8b15a29 Mon Sep 17 00:00:00 2001 >From: Fridolin Somers <fridolin.somers@biblibre.com> >Date: Tue, 13 Dec 2022 10:23:15 -1000 >Subject: [PATCH] Bug 32463: Embed analytical items into bibliographic records > export > >--- > Koha/Exporter/Record.pm | 8 +++ > Koha/Filter/MARC/EmbedAnalyticalItems.pm | 74 ++++++++++++++++++++++++ > misc/export_records.pl | 8 +++ > 3 files changed, 90 insertions(+) > create mode 100644 Koha/Filter/MARC/EmbedAnalyticalItems.pm > >diff --git a/Koha/Exporter/Record.pm b/Koha/Exporter/Record.pm >index e678c36ee1..0362f3d12f 100644 >--- a/Koha/Exporter/Record.pm >+++ b/Koha/Exporter/Record.pm >@@ -10,6 +10,7 @@ use C4::Record; > use Koha::Biblios; > use Koha::CsvProfiles; > use Koha::Logger; >+use Koha::RecordProcessor; > use List::Util qw( all any ); > > sub _get_record_for_export { >@@ -120,6 +121,7 @@ sub _get_biblio_for_export { > my $itemnumbers = $params->{itemnumbers}; > my $export_items = $params->{export_items} // 1; > my $only_export_items_for_branches = $params->{only_export_items_for_branches}; >+ my $embed_analytical_items = $params->{embed_analytical_items}; > > my $biblio = Koha::Biblios->find($biblionumber); > my $record = eval { $biblio->metadata->record }; >@@ -147,6 +149,12 @@ sub _get_biblio_for_export { > } > } > } >+ >+ if ( $embed_analytical_items && C4::Context->preference('EasyAnalyticalRecords') ) { >+ my $eai_record_processor = Koha::RecordProcessor->new( { filters => 'EmbedAnalyticalItems' } ); >+ $eai_record_processor->process($record); >+ } >+ > return $record; > } > >diff --git a/Koha/Filter/MARC/EmbedAnalyticalItems.pm b/Koha/Filter/MARC/EmbedAnalyticalItems.pm >new file mode 100644 >index 0000000000..2719a1f83a >--- /dev/null >+++ b/Koha/Filter/MARC/EmbedAnalyticalItems.pm >@@ -0,0 +1,74 @@ >+package Koha::Filter::MARC::EmbedAnalyticalItems; >+ >+# Copyright 2022 Biblibre >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+=head1 NAME >+ >+Koha::Filter::MARC::EmbedAnalyticalItems - Appends analytical items information on MARC::Record objects. >+ >+=head1 DESCRIPTION >+ >+Filter to embed analytical items information into MARC::Record objects. >+ >+Does nothing if system preference EasyAnalyticalRecords is disabled. >+ >+=cut >+ >+use Modern::Perl; >+ >+use Koha::Item; >+ >+use base qw(Koha::RecordProcessor::Base); >+our $NAME = 'EmbedAnalyticalItems'; >+ >+=head2 filter >+ >+Embed analytical items into the MARC::Record object. >+ >+=cut >+ >+sub filter { >+ my $self = shift; >+ my $record = shift; >+ >+ return unless defined $record and ref($record) eq 'MARC::Record'; >+ >+ return $record unless C4::Context->preference('EasyAnalyticalRecords'); >+ >+ my @item_fields; >+ my $marcflavour = C4::Context->preference('marcflavour'); >+ my $analyticfield = '773'; >+ if ( $marcflavour eq 'MARC21' ) { >+ $analyticfield = '773'; >+ } >+ elsif ( $marcflavour eq 'UNIMARC' ) { >+ $analyticfield = '461'; >+ } >+ foreach my $field ( $record->field($analyticfield) ) { >+ my $item = Koha::Item->find($field->subfield('9')); >+ next unless defined $item; >+ my $item_field = $item->as_marc_field; >+ # TODO barcode >+ push @item_fields, $item_field; >+ } >+ $record->append_fields(@item_fields); >+ >+ return $record; >+} >+ >+1; >diff --git a/misc/export_records.pl b/misc/export_records.pl >index 32658cb8c8..60361f0fde 100755 >--- a/misc/export_records.pl >+++ b/misc/export_records.pl >@@ -54,6 +54,7 @@ my ( > $start_accession, > $end_accession, > $marc_conditions, >+ $embed_analytical_items, > $help > ); > >@@ -78,6 +79,7 @@ GetOptions( > 'start_accession=s' => \$start_accession, > 'end_accession=s' => \$end_accession, > 'marc_conditions=s' => \$marc_conditions, >+ 'embed_analytical_items' => \$embed_analytical_items, > 'h|help|?' => \$help > ) || pod2usage(1); > >@@ -256,6 +258,7 @@ else { > csv_profile_id => $csv_profile_id, > export_items => (not $dont_export_items), > clean => $clean || 0, >+ embed_analytical_items => $embed_analytical_items || 0, > } > ); > } >@@ -385,6 +388,11 @@ Print a brief help message. > "exists(<marc_target>)" will include marc records where > no <marc_target> exists. > >+=item B<--embed_analytical_items> >+ >+ --embed_analytical_items Embed analytical items in bibliographic record. >+ Only valid with system preference EasyAnalyticalRecords enabled. >+ > =back > > =head1 AUTHOR >-- >2.35.5
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 32463
: 144563