Bug 19693: (QA follow-up) Replace changed tag test
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Fri, 7 Oct 2022 08:41:20 +0000 (08:41 +0000)
committerArthur Suzuki <arthur.suzuki@biblibre.com>
Fri, 16 Dec 2022 15:52:03 +0000 (16:52 +0100)
The test
  $MARCfrom->field('1..', '2..'))[0]->tag ne ($MARCto->field('1..', '2..'))[0]->tag
is not completely consistent with following code in sub merge.
I decided to get the authtype code from the old record that comes
from Koha and should include the type.
Remaining changes refer to indentation/comments.

Test plan:
Run t/db_dependent/Authority/Merge.t
Note: The test actually could be extended a bit for mocking MARC
flavor, but needs some additional framework support to work.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit d7d33744ba34ef95aa3845ca4160abdece4d0f7a)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 90e4cdb752601d273aa1807a88330da29034305c)
Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com>
C4/AuthoritiesMarc.pm

index 0a67448..1dbcb62 100644 (file)
@@ -1385,15 +1385,18 @@ sub merge {
     # Search authtypes and reporting tags
     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 $authtypefrom;
     my $authtypeto   = $authto ? Koha::Authority::Types->find($authto->authtypecode) : undef;
+    if( $mergeto && $mergefrom == $mergeto && $MARCfrom ) {
+        # bulkmarcimport may have changed the authtype; see BZ 19693
+        my $old_type = $MARCfrom->subfield( get_auth_type_location() ); # going via default
+        if( $old_type && $authto && $old_type ne $authto->authtypecode ) {
+            # Type change: handled by simulating a postponed merge where the auth record has been deleted already
+            # This triggers a walk through all auth controlled tags
+            undef $authfrom;
+        }
+    }
+    $authtypefrom = Koha::Authority::Types->find($authfrom->authtypecode) if $authfrom;
     my $auth_tag_to_report_from = $authtypefrom ? $authtypefrom->auth_tag_to_report : '';
     my $auth_tag_to_report_to   = $authtypeto ? $authtypeto->auth_tag_to_report : '';