Bugzilla – Attachment 172802 Details for
Bug 38142
Choose language to report from authority to bibliographic record.
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.68 KB, created by
Matthias Meusburger
on 2024-10-16 07:25:45 UTC
(
hide
)
Description:
Bug 38142: Choose language to report from authority to bibliographic record.
Filename:
MIME Type:
Creator:
Matthias Meusburger
Created:
2024-10-16 07:25:45 UTC
Size:
12.68 KB
patch
obsolete
>From db3dd4600cb0c76fb6d27b9e7c98d88b12a06524 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 >--- > C4/AuthoritiesMarc.pm | 21 +++++- > installer/data/mysql/atomicupdate/Bug38142.pl | 18 +++++ > installer/data/mysql/mandatory/sysprefs.sql | 1 + > .../admin/preferences/authorities.pref | 3 + > t/db_dependent/Authority/Merge.t | 74 ++++++++++++++++++- > 5 files changed, 115 insertions(+), 2 deletions(-) > create mode 100755 installer/data/mysql/atomicupdate/Bug38142.pl > >diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm >index 1656a2ba9bc..49c0c06924a 100644 >--- a/C4/AuthoritiesMarc.pm >+++ b/C4/AuthoritiesMarc.pm >@@ -1551,7 +1551,26 @@ 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 > # reference) in order to allow for data recovery. >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 66c7b008f21..e8996175c4c 100644 >--- a/installer/data/mysql/mandatory/sysprefs.sql >+++ b/installer/data/mysql/mandatory/sysprefs.sql >@@ -364,6 +364,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('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'), > ('StaffInterfaceLanguages','en',NULL,'Set the default language in the staff interface.','Languages'), >+('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 484368fffec..8c841adc57a 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 >@@ -95,6 +95,9 @@ Authorities: > - Display the MARC field/subfields > - pref: AdditionalFieldsInZ3950ResultAuthSearch > - " in the 'Additional fields' column of Z39.50 search results (use comma as delimiter e.g.: \"<code>001, 035$a</code>\")" >+ - >+ - "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: > - >diff --git a/t/db_dependent/Authority/Merge.t b/t/db_dependent/Authority/Merge.t >index 2336cf999cf..65ca0f191b7 100755 >--- a/t/db_dependent/Authority/Merge.t >+++ b/t/db_dependent/Authority/Merge.t >@@ -4,7 +4,7 @@ > > use Modern::Perl; > >-use Test::More tests => 12; >+use Test::More tests => 13; > > use Getopt::Long; > use MARC::Record; >@@ -187,6 +187,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 > # Would not encourage this type of merge, but we should test what we offer >-- >2.39.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 38142
:
172684
|
172802
|
172923