From 925c1eedd89ca72d77d4ef78824d02cfe542995e Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 1 Apr 2021 11:04:35 +0200 Subject: [PATCH] Bug 24564: Use the same tab as the other subfields within a field For each subfield added, we check if other subfields exists in the same field. If that's the case we use the same tab as the first subfield found. Test plan: 1. Find a biblio subfield in misc/migration_tools/ifla/data/biblio/default.yml that doesn't exist in your default biblio MARC framework (or delete one). The field should exist and have other subfields with a tab set. 2. Change the tab of all subfields within that field it's different from what's in the .yml file 3. Run misc/migration_tools/ifla/update.pl 4. Verify that the subfield has been added and have the same tab as others subfields 5. Do the same for authorities (files are in misc/migration_tools/ifla/data/auth/) --- misc/migration_tools/ifla/update.pl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/misc/migration_tools/ifla/update.pl b/misc/migration_tools/ifla/update.pl index 3d4be0a624..dda33c2f51 100755 --- a/misc/migration_tools/ifla/update.pl +++ b/misc/migration_tools/ifla/update.pl @@ -222,6 +222,14 @@ for my $tag (@tags) { $marc_tag_structure_rs->create($tag); } +my @mss = $marc_subfield_structure_rs->search({ frameworkcode => '' }); +my %tab_for_field; +foreach my $mss (@mss) { + next if $mss->tab < 0; + next if exists $tab_for_field{$mss->tagfield}; + $tab_for_field{$mss->tagfield} = $mss->tab; +} + my $subfield_defaults = $defaults->{subfield}; for my $subfield (@subfields) { foreach my $key (keys %$subfield_defaults) { @@ -231,6 +239,11 @@ for my $subfield (@subfields) { } $subfield->{liblibrarian} = t($subfield->{liblibrarian}); + # If other subfields exist in this field, use the same tab + if (exists $tab_for_field{$subfield->{tagfield}}) { + $subfield->{tab} = $tab_for_field{$subfield->{tagfield}}; + } + my $mss = $marc_subfield_structure_rs->find('', $subfield->{tagfield}, $subfield->{tagsubfield}); if ($mss) { say sprintf('Subfield already exists: %s$%s', $subfield->{tagfield}, $subfield->{tagsubfield}); @@ -290,6 +303,14 @@ for my $authtag (@authtags) { $auth_tag_structure_rs->create($authtag); } +my @ass = $auth_subfield_structure_rs->search({ frameworkcode => '' }); +my %tab_for_authfield; +foreach my $ass (@ass) { + next if $ass->tab < 0; + next if exists $tab_for_authfield{$ass->tagfield}; + $tab_for_authfield{$ass->tagfield} = $ass->tab; +} + my $authsubfield_defaults = $defaults->{authsubfield}; for my $authsubfield (@authsubfields) { foreach my $key (keys %$authsubfield_defaults) { @@ -299,6 +320,11 @@ for my $authsubfield (@authsubfields) { } $authsubfield->{liblibrarian} = t($authsubfield->{liblibrarian}); + # If other subfields exist in this field, use the same tab + if (exists $tab_for_authfield{$authsubfield->{tagfield}}) { + $authsubfield->{tab} = $tab_for_authfield{$authsubfield->{tagfield}}; + } + my $ass = $auth_subfield_structure_rs->find($authsubfield->{authtypecode}, $authsubfield->{tagfield}, $authsubfield->{tagsubfield}); if ($ass) { say sprintf('Auth subfield already exists: %s$%s (%s)', $authsubfield->{tagfield}, $authsubfield->{tagsubfield}, $authsubfield->{authtypecode}); -- 2.20.1