From d4d6af42884e66208f70f6a8cb5caed8ed092a0d Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Mon, 25 Jul 2022 22:46:58 +0200 Subject: [PATCH 2/2] Bug 19693: update of an authority record creates inconsistency when the heading tag is changed In those rare cases when authorities are updated by an external agency (or even internally, by reviewing and correcting an exported authority file) when the heading tag will be changed (seems odd but happens: 111 Congress ==> 110 Corporate body.Congress ; 100 Person ==> 110 Corporate body (a company named with person's name ; 151 City--object ==> 150 Object (city) etc.) and then the authority record in Koha database will be updated with bulkmarcimport or by calling directly ModAuthority from a custom script, the merge function "doesn't know" that the change to the authority type has been made and, consequently, doesn't adequately change the tag in related fields in biblio records (as it would if two different records with different authtypecode were merged with Koha interface). This is because at the moment when merge function is being called by ModAuthority: Koha::Authority::Types->find($autfrom->authtypecode) Koha::Authority::Types->find($authto->authtypecode) both have the same value (because $mergefrom == $mergeto). Therefore in case when $mergefrom == $mergeto and the heading tag changes, $authtypefrom and $authfrom calculated in merge in the ordinar way are misleading and should not be taken unto consideration. Test plan: ========== 1. run t/db_dependent/Authority/Merge.t 2. you should see problems in "Test update A with modified heading tag (changing authtype)" 3. apply the patch 4. run t/db_dependent/Authority/Merge.t again 5. the test should pass Alternatively: 1. have an authority record used in biblio; export it to file; change 1XX heading tag to a different (but reasonable) value and possibly change also the content of the heading (one can delete also 942 but it doesn't matter); make bulkmarcimport.pl -a -update -file and see that the tag in biblio record has not been changed (whereas the type of authority record did change); 2. make orders in database (so that the authority type and the tag of the field in biblio record correspond); apply the patch; 3. repeat the test from 1. --- C4/AuthoritiesMarc.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index e211af2b94..107001150a 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -1419,6 +1419,13 @@ sub merge { my $authfrom = Koha::Authorities->find($mergefrom); my $authto = Koha::Authorities->find($mergeto); my $authtypefrom = $authfrom ? Koha::Authority::Types->find($authfrom->authtypecode) : undef; + # If it is a mod ($authfrom == $authto) and there was a change of a heading tag $authtypefrom read from the database is of the current version of the auth rec., which is misleading, so we ignore it + if ($mergeto && $mergefrom == $mergeto && $MARCfrom && $MARCto && + $MARCfrom->field('1..', '2..') && $MARCto->field('1..', '2..') && ($MARCfrom->field('1..', '2..'))[0]->tag ne ($MARCto->field('1..', '2..'))[0]->tag) { + undef $authtypefrom; + undef $authfrom; + } + my $authtypeto = $authto ? Koha::Authority::Types->find($authto->authtypecode) : undef; my $auth_tag_to_report_from = $authtypefrom ? $authtypefrom->auth_tag_to_report : ''; my $auth_tag_to_report_to = $authtypeto ? $authtypeto->auth_tag_to_report : ''; -- 2.30.2