my %statement_blob;
for my $type ( keys %type_blob ) {
my ($mfhd,$list) = _summarize_contents(new_editor(), $type_blob{$type});
+
+ return {} if $U->event_code($mfhd); # _summarize_contents() failed, bad data?
+
$statement_blob{$type} = $list;
}
}
my ($mfhd, $formatted_parts) = _summarize_contents($e, $issuances);
+ return $mfhd if $U->event_code($mfhd);
# special case for single formatted_part (may have summarized version)
if (@$formatted_parts == 1) {
my ($e, $issuances, $sdist, $type) = @_;
my ($mfhd, $formatted_parts) = _summarize_contents($e, $issuances, $sdist);
+ return $mfhd if $U->event_code($mfhd);
my $search_method = "search_serial_${type}_summary";
my $summary = $e->$search_method([{"distribution" => $sdist->id}]);
return $unit;
}
-
sub _summarize_contents {
my $editor = shift;
my $issuances = shift;
my @formatted_parts;
my @scap_fields_ordered = $mfhd->field('85[345]');
+
foreach my $scap_field (@scap_fields_ordered) { #TODO: use generic MFHD "summarize" method, once available
- my @updated_holdings = $mfhd->get_compressed_holdings($scap_field);
- foreach my $holding (@updated_holdings) {
- push(@formatted_parts, $holding->format);
- }
+ my @updated_holdings;
+ eval {
+ @updated_holdings = $mfhd->get_compressed_holdings($scap_field);
+ };
+ if ($@) {
+ my $msg = "get_compressed_holdings(): $@ ; using sdist ID #" .
+ ($sdist ? $sdist->id : "<NONE>") . " and " .
+ scalar(@$issuances) . " issuances, of which one has ID #" .
+ $issuances->[0]->id;
+
+ $msg =~ s/\n//gm;
+ $logger->error($msg);
+ return new OpenILS::Event("BAD_PARAMS", note => $msg);
+ }
+
+ push @formatted_parts, map { $_->format } @updated_holdings;
}
return ($mfhd, \@formatted_parts);
last;
} else {
push(@comp_holdings, $curr_holding);
+
+ my $loop_count = 0;
+ (my $runner_dump = $runner->as_formatted) =~ s/\n\s+/*/gm; # logging
+
while ($runner le $holding) {
- # Here is where we used to get stuck in an infinite loop
- # until the "Don't know how to deal with frequency" was
- # elevated from a carp to a croak.
+ # Infinite loops used to happen here. As written today,
+ # ->increment() cannot be guaranteed to eventually falsify
+ # the condition ($runner le $holding) in certain cases.
+
$runner->increment;
+
+ if (++$loop_count >= 10000) {
+ (my $holding_dump = $holding->as_formatted) =~ s/\n\s+/*/gm;
+
+ croak "\$runner<$runner_dump> didn't catch up with " .
+ "\$holding<$holding_dump> after 10000 increments";
+ }
}
$curr_holding = $holding->clone;
$seqno++;