Bugzilla – Attachment 158063 Details for
Bug 19097
Koha to MARC mappings (Part 3): Correct remaining GetMarcFromKohaField calls
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19097: GetMarcSubfieldStructureFromKohaField - remove wantarray
Bug-19097-GetMarcSubfieldStructureFromKohaField---.patch (text/plain), 5.15 KB, created by
Marcel de Rooy
on 2023-10-30 13:34:01 UTC
(
hide
)
Description:
Bug 19097: GetMarcSubfieldStructureFromKohaField - remove wantarray
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2023-10-30 13:34:01 UTC
Size:
5.15 KB
patch
obsolete
>From 1f90f09d5f531348f7c7da6bdb8b108785768800 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Mon, 30 Oct 2023 13:20:14 +0000 >Subject: [PATCH] Bug 19097: GetMarcSubfieldStructureFromKohaField - remove > wantarray >Content-Type: text/plain; charset=utf-8 > >Replacing wantarray by a list parameter. >Adding comment to calls where simply one return is assumed. > >Test plan: >Look at results of git grep GetMarcSubfieldStructureFromKohaField >Run t/db_dependent/Biblio.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > C4/Biblio.pm | 12 +++++++----- > reports/acquisitions_stats.pl | 2 +- > reports/catalogue_stats.pl | 2 +- > t/db_dependent/Biblio.t | 15 +++++++++------ > 4 files changed, 18 insertions(+), 13 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index eea56d7e4c..a3e9498961 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -1191,18 +1191,20 @@ sub GetMarcFromKohaField { > > =head2 GetMarcSubfieldStructureFromKohaField > >- my $str = GetMarcSubfieldStructureFromKohaField( $kohafield ); >+ my $str = GetMarcSubfieldStructureFromKohaField( $kohafield, { list => 0|1 } ); > > Returns marc subfield structure information for $kohafield. > The Default framework is used, since it is authoritative for kohafield > mappings. >- In list context returns a list of all hashrefs, since there may be >- multiple mappings. In scalar context the first hashref is returned. >+ Normally returns first subfield structure hash found. >+ With list parameter, returns an arrayref of hashes. (NOTE: replace >+ previous wantarray construct. Parameter is currently not yet used as >+ of 10/2023.) > > =cut > > sub GetMarcSubfieldStructureFromKohaField { >- my ( $kohafield ) = @_; >+ my ( $kohafield, $params ) = @_; > > return unless $kohafield; > >@@ -1210,7 +1212,7 @@ sub GetMarcSubfieldStructureFromKohaField { > # for all Koha to MARC mappings. > my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework > return unless $mss->{$kohafield}; >- return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0]; >+ return $params && $params->{list} ? $mss->{$kohafield} : $mss->{$kohafield}->[0]; > } > > =head2 GetXmlBiblio >diff --git a/reports/acquisitions_stats.pl b/reports/acquisitions_stats.pl >index 2c90fe32cc..1ecc8c67f6 100755 >--- a/reports/acquisitions_stats.pl >+++ b/reports/acquisitions_stats.pl >@@ -173,7 +173,7 @@ else { > > my $libraries = Koha::Libraries->search({}, { order_by => 'branchname' }); > >- my $ccode_subfield_structure = GetMarcSubfieldStructureFromKohaField('items.ccode'); >+ my $ccode_subfield_structure = GetMarcSubfieldStructureFromKohaField('items.ccode'); # assuming one result.. > my $ccode_label; > my $ccode_avlist; > if($ccode_subfield_structure) { >diff --git a/reports/catalogue_stats.pl b/reports/catalogue_stats.pl >index b4d72a384b..a0291fe789 100755 >--- a/reports/catalogue_stats.pl >+++ b/reports/catalogue_stats.pl >@@ -118,7 +118,7 @@ if ($do_it) { > my @locations = map { { code => $_->{authorised_value}, description => $_->{lib} } } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ); > > foreach my $kohafield (qw(items.notforloan items.materials)) { >- my $subfield_structure = GetMarcSubfieldStructureFromKohaField($kohafield); >+ my $subfield_structure = GetMarcSubfieldStructureFromKohaField($kohafield); # assuming one result.. > if($subfield_structure) { > my $avlist; > my $avcategory = $subfield_structure->{authorised_value}; >diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t >index 4f096f7fe1..0b768fd04f 100755 >--- a/t/db_dependent/Biblio.t >+++ b/t/db_dependent/Biblio.t >@@ -102,7 +102,7 @@ subtest 'AddBiblio' => sub { > }; > > subtest 'GetMarcSubfieldStructureFromKohaField' => sub { >- plan tests => 25; >+ plan tests => 26; > > my @columns = qw( > tagfield tagsubfield liblibrarian libopac repeatable mandatory kohafield tab >@@ -121,11 +121,14 @@ subtest 'GetMarcSubfieldStructureFromKohaField' => sub { > is($marc_subfield_structure->{kohafield}, 'biblio.biblionumber', "Result is the good result"); > like($marc_subfield_structure->{tagfield}, qr/^\d{3}$/, "tagfield is a valid tagfield"); > >- # Add a test for list context (BZ 10306) >- my @results = GetMarcSubfieldStructureFromKohaField('biblio.biblionumber'); >- is( @results, 1, 'We expect only one mapping' ); >- is_deeply( $results[0], $marc_subfield_structure, >- 'The first entry should be the same hashref as we had before' ); >+ # Add a test for list parameter >+ my $results = GetMarcSubfieldStructureFromKohaField( 'biblio.biblionumber', { list => 1 } ); >+ is( ref $results, "ARRAY", "Result is an arrayref when using list => 1" ); >+ is( @$results, 1, 'We expect only one mapping' ); >+ is_deeply( >+ $results->[0], $marc_subfield_structure, >+ 'The first entry should be the same hashref as we had before' >+ ); > > # foo.bar does not exist so this should return undef > $marc_subfield_structure = GetMarcSubfieldStructureFromKohaField('foo.bar'); >-- >2.30.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 19097
:
158063
|
158231
|
158232
|
158233
|
158246
|
158247
|
158248
|
158249
|
165103
|
165104
|
165105
|
165106