Allow compressed_end() to handle compressed input
authorDan Wells <dbw2@calvin.edu>
Tue, 2 Jul 2013 16:01:46 +0000 (12:01 -0400)
committerDan Wells <dbw2@calvin.edu>
Tue, 2 Jul 2013 16:01:46 +0000 (12:01 -0400)
The code was assuming the $end_holding param would be uncompressed,
but this was not stated anywhere, nor enforced.  Let's allow the
method to take both compressed and uncompressed holdings as the "end"
(and handle it appropriately).

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/Holding.pm

index 33781dd..37f985a 100644 (file)
@@ -640,12 +640,18 @@ sub compressed_to_last {
 #
 # Creates or replaces an end of a compressed holding
 #
+# If $end_holding does not share caption data with $self, results
+# will be unpredicable
+#
 sub compressed_end {
     my $self = shift;
     my $end_holding = shift;
 
     my %changes;
-    if ($end_holding) {
+    if ($end_holding and !$end_holding->is_open_ended) {
+        if ($end_holding->is_compressed) {
+            $end_holding = $end_holding->clone->compressed_to_last;
+        }
         foreach my $key (keys %{$self->fields}) {
             my @values = @{$self->field_values($key)};
             my @end_values = @{$end_holding->field_values($key)};
@@ -653,7 +659,7 @@ sub compressed_end {
             $self->fields->{$key}{HOLDINGS} = \@values;
             $changes{$key} = join('-', @values);
         }
-    } elsif (!$self->is_open_ended) { # make open-ended if no $end_holding
+    } elsif (!$self->is_open_ended) { # make open-ended if no $end_holding (or $end_holding was open ended)
         foreach my $key (keys %{$self->fields}) {
             my @values = @{$self->field_values($key)};
             $self->fields->{$key}{HOLDINGS} = [$values[0]];