Bugzilla – Attachment 180222 Details for
Bug 38142
UNIMARC: Choose heading to use from the authority record in the bibliographic record by language
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38142: Choose language to report from authority to bibliographic record.
Bug-38142-Choose-language-to-report-from-authority.patch (text/plain), 12.85 KB, created by
Martin Renvoize (ashimema)
on 2025-04-01 16:24:19 UTC
(
hide
)
Description:
Bug 38142: Choose language to report from authority to bibliographic record.
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-04-01 16:24:19 UTC
Size:
12.85 KB
patch
obsolete
>From 1498bd8a639199cfd4d5545d0d803238557221f9 Mon Sep 17 00:00:00 2001 >From: Matthias Meusburger <matthias.meusburger@biblibre.com> >Date: Wed, 14 Aug 2024 09:54:40 +0000 >Subject: [PATCH] Bug 38142: Choose language to report from authority to > bibliographic record. >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Currently, when reporting authority field to the bibliographic records, >the merge function uses the first matching authority field. > >However, authorities can provide multiple versions of the same field, with >different languages, identified by a code in the $7 field. > >French reference for languages codes for example, but any code system could be >used: >https://documentation.abes.fr/sudoc/formats/unmb/DonneesCodees/CodesZone104.htm#$d > >This patch introduces the LanguageToReportOnMerge system preference, which >allows to specify a language code. > >When set, if there is an authority field with the given language code, it will >be used to report to the bibliographic record. > >If the system preference is not set, or there is no matching field, the default >behavior will apply: the first field will be used. > >The $7 in the authority field can be in a short or long form: > > - the short form is 2 characters long. Example: ba > - the long form is 8 characters long, with the short form in position 5 and 6 > (starting from 1). Example: ba0yba0y > >Test plan: >---------- > >1) Edit the 'Personal Name' authority type framework to make the 100 field >repeatable > >2) Add an authority with several languages, like this (the order is important): > >100 _7ba0yda0y > _a伿±è±é >100 _7ba0yba0y > _aItÅ > >3) Add a bibliographic record linked to that authority. >(Click on the "tag editor" icon next to the 100$a field in the bibliographic record to > search for the authority, then Search main heading ($a only): contains ItÅ) > >Note that you can choose which version you want when searching for the >authority, under the "Get it!" column > >For this example, choose the latin version: ItÅ > >You should now have this in your bibliographic record: >100 _aItÅ > _92646 > >4) Edit the authority, you don't have to change anything, just edit and save. >Note that your bibliographic record now looks like this: > >100 _7ba0yda0y > _a伿±è±é > _92646 > >The first 100 field of the authority has been reported back to the bibliographic >record, regardless of what you chose when selecting the authority. > >5) Apply the patch, set the LanguageToReportOnMerge system preference to: 'ba' > >6) Edit the authority again, and check that your bibliographic record now looks >like this, according to the system preference: > >100 _7ba0yba0y > _aItÅ > _92646 > >7) Edit the authority again, but set the $7 of the latin field to its short >form: > >100 _7ba0yda0y > _a伿±è±é >100 _7ba > _aItÅ > >8) Check that the bibliographic record still has the latin field reported: > >100 _7ba > _aItÅ > _92646 > >9) prove koha/t/db_dependent/Authority/Merge.t > >10) Sign-off :) > >Sponsored-by: ENSA > >Works smoothly, both with UNIMARC/MARC21 >Signed-off-by: Frédéric Demians <f.demians@tamil.fr> >Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> >--- > C4/AuthoritiesMarc.pm | 21 +++++- > installer/data/mysql/atomicupdate/Bug38142.pl | 18 +++++ > installer/data/mysql/mandatory/sysprefs.sql | 1 + > .../admin/preferences/authorities.pref | 4 +- > t/db_dependent/Authority/Merge.t | 75 ++++++++++++++++++- > 5 files changed, 114 insertions(+), 5 deletions(-) > create mode 100755 installer/data/mysql/atomicupdate/Bug38142.pl > >diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm >index 8d0c994ad61..8b3ccf1923e 100644 >--- a/C4/AuthoritiesMarc.pm >+++ b/C4/AuthoritiesMarc.pm >@@ -1619,8 +1619,25 @@ sub merge { > my $auth_tag_to_report_to = $authtypeto ? $authtypeto->auth_tag_to_report : ''; > > my @record_to; >- @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() >- if $auth_tag_to_report_to && $MARCto && $MARCto->field($auth_tag_to_report_to); >+ >+ my $short_langcode = C4::Context->preference('LanguageToReportOnMerge'); >+ if ( $auth_tag_to_report_to && $MARCto && $MARCto->field($auth_tag_to_report_to) ) { >+ my $chosen_field = $MARCto->field($auth_tag_to_report_to); >+ if ($short_langcode) { >+ foreach my $field ( $MARCto->field($auth_tag_to_report_to) ) { >+ my $subfield = $field->subfield('7'); >+ if ( >+ defined $subfield >+ && ( ( length($subfield) == 2 && $subfield eq $short_langcode ) >+ || ( length($subfield) == 8 && substr( $subfield, 4, 2 ) eq $short_langcode ) ) >+ ) >+ { >+ $chosen_field = $field; >+ } >+ } >+ } >+ @record_to = $chosen_field->subfields(); >+ } > > # Exceptional: If MARCto and authtypeto exist but $auth_tag_to_report_to > # is empty, make sure that $9 and $a remain (instead of clearing the >diff --git a/installer/data/mysql/atomicupdate/Bug38142.pl b/installer/data/mysql/atomicupdate/Bug38142.pl >new file mode 100755 >index 00000000000..f94ba2012b6 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/Bug38142.pl >@@ -0,0 +1,18 @@ >+use Modern::Perl; >+ >+return { >+ bug_number => "38142", >+ description => "LanguageToReportOnMerge", >+ up => sub { >+ my ($args) = @_; >+ my ( $dbh, $out ) = @$args{qw(dbh out)}; >+ $dbh->do( >+ q{ >+ INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES >+ ('LanguageToReportOnMerge','','','If set, the authority field having the given language code in its $7 subfield will be reported to the bibliographic record if it exists, rather than the first field. The code can be in a short, 2 characters long form (example: ba for latin) or in a long, 8 characters long form, with the short form in position 5 and 6 starting from 1 (example: ba0yba0y for latin). A list of available codes can be found here: https://documentation.abes.fr/sudoc/formats/unmb/DonneesCodees/CodesZone104.htm#$d','Free'); >+ } >+ ); >+ >+ say $out "Added new syspref 'LanguageToReportOnMerge'"; >+ } >+}; >diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql >index 2bf9d0b6486..3410f79825c 100644 >--- a/installer/data/mysql/mandatory/sysprefs.sql >+++ b/installer/data/mysql/mandatory/sysprefs.sql >@@ -370,6 +370,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('KohaManualBaseURL','https://koha-community.org/manual/','','Where is the Koha manual/documentation located?','Free'), > ('KohaManualLanguage','en','en|ar|cs|de|es|fr|it|pt_BR|tr|zh_TW','What is the language of the online manual you want to use?','Choice'), > ('LabelMARCView','standard','standard|economical','Define how a MARC record will display','Choice'), >+('LanguageToReportOnMerge','',NULL,'If set, the authority field having the given language code in its $7 subfield will be reported to the bibliographic record if it exists, rather than the first field. The code can be in a short, 2 characters long form (example: ba for latin) or in a long, 8 characters long form, with the short form in position 5 and 6 starting from 1 (example: ba0yba0y for latin). A list of available codes can be found here: https://documentation.abes.fr/sudoc/formats/unmb/DonneesCodees/CodesZone104.htm#$d','Free'), > ('LibraryName','','','Define the library name as displayed on the OPAC',''), > ('LibraryThingForLibrariesEnabled','0','','Enable or Disable Library Thing for Libraries Features','YesNo'), > ('LibraryThingForLibrariesID','','','See:http://librarything.com/forlibraries/','free'), >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref >index 1ab804518c5..b824bb9b1ca 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref >@@ -103,7 +103,9 @@ Authorities: > 0: "Don't" > - consider the intended use of MARC21 authority records (008/14-16) during cataloging and linking. > - "<br/>NOTE: If you enable this preference, 'No attempt to code' in 008/14-16 is excluded from search results too." >- >+ - >+ - "If set, the authority field having the given language code in its $7 subfield will be reported to the bibliographic record if it exists, rather than the first field. The code can be in a short, 2 characters long form (example: ba for latin) or in a long, 8 characters long form, with the short form in position 5 and 6 starting from 1 (example: ba0yba0y for latin). A list of available codes can be found here: https://documentation.abes.fr/sudoc/formats/unmb/DonneesCodees/CodesZone104.htm#$d" >+ - pref: LanguageToReportOnMerge > Linker: > - > - Use the >diff --git a/t/db_dependent/Authority/Merge.t b/t/db_dependent/Authority/Merge.t >index e7f50694ce9..bf1a5fc6ff7 100755 >--- a/t/db_dependent/Authority/Merge.t >+++ b/t/db_dependent/Authority/Merge.t >@@ -3,9 +3,8 @@ > # Tests for C4::AuthoritiesMarc::merge > > use Modern::Perl; >- > use Test::NoWarnings; >-use Test::More tests => 13; >+use Test::More tests => 14; > > use Getopt::Long; > use MARC::Record; >@@ -211,6 +210,78 @@ subtest 'Test merge A1 to modified A1, test strict mode' => sub { > # Note: the +1 comes from the added subfield $9 in the biblio > }; > >+subtest 'Test merge A1 to B1 (choosing language)' => sub { >+ plan tests => 4; >+ >+ t::lib::Mocks::mock_preference( 'LanguageToReportOnMerge', '' ); >+ >+ my $auth1 = MARC::Record->new; >+ $auth1->append_fields( >+ MARC::Field->new( '109', '0', '0', 'a' => 'language da', '7' => 'da' ), >+ MARC::Field->new( '109', '0', '0', 'a' => 'language ba', '7' => 'ba' ), >+ ); >+ my $authid1 = AddAuthority( $auth1, undef, $authtype1 ); >+ >+ my $marc = MARC::Record->new; >+ $marc->append_fields( >+ MARC::Field->new( '003', 'some_003' ), >+ MARC::Field->new( '245', '', '', a => 'My title' ), >+ MARC::Field->new( '609', '', '', a => 'language ba', '7' => 'ba', 9 => $authid1 ), >+ ); >+ my ($biblionumber) = C4::Biblio::AddBiblio( $marc, '' ); >+ >+ @linkedrecords = ($biblionumber); >+ C4::AuthoritiesMarc::merge( { mergefrom => $authid1, MARCfrom => $auth1, mergeto => $authid1, MARCto => $auth1 } ); >+ my $biblio = Koha::Biblios->find($biblionumber)->metadata->record; >+ >+ is( >+ $biblio->subfield( '609', 'a' ), 'language da', >+ 'When LanguageToReportOnMerge is not set, the first authority field is used' >+ ); >+ >+ t::lib::Mocks::mock_preference( 'LanguageToReportOnMerge', 'ba' ); >+ C4::AuthoritiesMarc::merge( { mergefrom => $authid1, MARCfrom => $auth1, mergeto => $authid1, MARCto => $auth1 } ); >+ $biblio = Koha::Biblios->find($biblionumber)->metadata->record; >+ is( >+ $biblio->subfield( '609', 'a' ), 'language ba', >+ 'When LanguageToReportOnMerge is set, the field with the matching language is reported' >+ ); >+ >+ t::lib::Mocks::mock_preference( 'LanguageToReportOnMerge', 'xx' ); >+ C4::AuthoritiesMarc::merge( { mergefrom => $authid1, MARCfrom => $auth1, mergeto => $authid1, MARCto => $auth1 } ); >+ $biblio = Koha::Biblios->find($biblionumber)->metadata->record; >+ is( >+ $biblio->subfield( '609', 'a' ), 'language da', >+ 'When LanguageToReportOnMerge is set to a value that does not exist in the authority, the first authority field is used' >+ ); >+ >+ # Long form of lang code >+ t::lib::Mocks::mock_preference( 'LanguageToReportOnMerge', 'ba' ); >+ my $auth2 = MARC::Record->new; >+ $auth2->append_fields( >+ MARC::Field->new( '109', '0', '0', 'a' => 'language da (long form)', '7' => 'ba0yda0y' ), >+ MARC::Field->new( '109', '0', '0', 'a' => 'language ba (long form)', '7' => 'ba0yba0y' ), >+ ); >+ my $authid2 = AddAuthority( $auth2, undef, $authtype1 ); >+ >+ $marc = MARC::Record->new; >+ $marc->append_fields( >+ MARC::Field->new( '003', 'some_003' ), >+ MARC::Field->new( '245', '', '', a => 'My title' ), >+ MARC::Field->new( '609', '', '', a => 'language ba', '7' => 'ba', 9 => $authid2 ), >+ ); >+ my ($biblionumber2) = C4::Biblio::AddBiblio( $marc, '' ); >+ >+ @linkedrecords = ($biblionumber2); >+ C4::AuthoritiesMarc::merge( { mergefrom => $authid2, MARCfrom => $auth2, mergeto => $authid2, MARCto => $auth2 } ); >+ my $biblio2 = Koha::Biblios->find($biblionumber2)->metadata->record; >+ is( >+ $biblio2->subfield( '609', 'a' ), 'language ba (long form)', >+ 'When LanguageToReportOnMerge is set, the field with the matching language in its long form is reported' >+ ); >+ >+}; >+ > subtest 'Test merge A1 to B1 (changing authtype)' => sub { > > # Tests were aimed for bug 9988, moved to 17909 in adjusted form >-- >2.49.0
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 38142
:
172684
|
172802
|
172923
|
177508
|
180178
| 180222 |
182652
|
182671