Bug 25006: Make Koha::Item->as_marc_field skip undefined subfields

This patch makes as_marc_field skip subfields that don't have a value or
contains an empty string (replicating C4::Items:1021 logic).

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Item.t
=> FAIL: Tests fail because the generated MARC::Field contains undef
subfields.
3. Apply this patch
4. Repeat 2.
=> SUCCESS: Tests pass! Undefined and empty subfields are skipped!
5. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Joy Nelson <joy@bywatersolutions.com>
This commit is contained in:
Tomas Cohen Arazi 2020-03-27 16:38:15 -03:00 committed by Joy Nelson
parent 2fd3ac8b52
commit b5062aaf6b
1 changed files with 2 additions and 1 deletions

View File

@ -412,7 +412,8 @@ sub as_marc_field {
next if !$tagfield; # TODO: Should we raise an exception instead?
# Feels like safe fallback is better
push @subfields, $tagsubfield => $self->$item_field;
push @subfields, $tagsubfield => $self->$item_field
if defined $self->$item_field and $item_field ne '';
}
my $unlinked_item_subfields = C4::Items::_parse_unlinked_item_subfields_from_xml($self->more_subfields_xml);