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/)

Signed-off-by: Koha team <koha@univ-lyon.fr>

Signed-off-by: sonia <sonia.bouis@univ-lyon3.fr>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Julian Maurice 2021-04-01 11:04:35 +02:00 committed by Jonathan Druart
parent 2f522d8ad4
commit c74f6848ed

View file

@ -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,18 @@ for my $authtag (@authtags) {
$auth_tag_structure_rs->create($authtag);
}
my @ass = $auth_subfield_structure_rs->search();
my %tab_for_authfield;
foreach my $ass (@ass) {
my $authtypecode = $ass->get_column('authtypecode');
$tab_for_authfield{$authtypecode} //= {};
next if $ass->tab < 0;
next if exists $tab_for_authfield{$authtypecode}->{$ass->tagfield};
$tab_for_authfield{$authtypecode}->{$ass->tagfield} = $ass->tab;
}
my $authsubfield_defaults = $defaults->{authsubfield};
for my $authsubfield (@authsubfields) {
foreach my $key (keys %$authsubfield_defaults) {
@ -299,6 +324,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->{authtypecode}}->{$authsubfield->{tagfield}}) {
$authsubfield->{tab} = $tab_for_authfield{$authsubfield->{authtypecode}}->{$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});