From bbf4fe9aba76779cc2c8225c906d2a46a20deee5 Mon Sep 17 00:00:00 2001 From: Dan Wells Date: Tue, 8 Apr 2014 16:11:31 -0400 Subject: [PATCH] LP#1078593 Assorted small Serial.pm fixes 1) fleshed_issuance_alter() changes - First, if one of the inner updates returns an event, abort early. Otherwise, we might overwrite the event while looping and lose the error. - Second, add authtoken to the created editor. This editor gets passed around, and other functions might look for it there. 2) pass $type down into _summarize_contents() - Right now, we have a bug where supplement/index contents in a merged MFHD record will get added to the basic contents (and vice-(vice-)versa). By passing in $type, we can assure that we only return the type of contents we are looking for. 3) _prepare_summaries() should acknowledge empty summaries - Under normal use, summaries will generally grow, and never shrink to nothing. However, we must still handle cases where we have discarded/deleted our last issuance, and in those cases, make sure we "empty" the generated_coverage field in our summary. Signed-off-by: Dan Wells Signed-off-by: Kathy Lussier Signed-off-by: Ben Shum --- Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm index 60b7383c4c..623f39bb4d 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm @@ -388,7 +388,7 @@ sub fleshed_issuance_alter { return 1 unless ref $issuances; my( $reqr, $evt ) = $U->checkses($auth); return $evt if $evt; - my $editor = new_editor(requestor => $reqr, xact => 1); + my $editor = new_editor(authtoken => $auth, requestor => $reqr, xact => 1); my $override = $self->api_name =~ /override/; my %found_ssub_ids; @@ -420,6 +420,8 @@ sub fleshed_issuance_alter { _cleanse_dates($issuance, ['date_published']); $evt = _update_siss( $editor, $override, $issuance ); } + + last if $evt; } if( $evt ) { @@ -1560,7 +1562,7 @@ sub _prepare_unit { sub _prepare_summaries { my ($e, $issuances, $sdist, $type) = @_; - my ($mfhd, $formatted_parts) = _summarize_contents($e, $issuances, $sdist); + my ($mfhd, $formatted_parts) = _summarize_contents($e, $issuances, $sdist, $type); return $mfhd if $U->event_code($mfhd); my $search_method = "search_serial_${type}_summary"; @@ -1577,7 +1579,13 @@ sub _prepare_summaries { $cu_method = "create"; } - $summary->generated_coverage(OpenSRF::Utils::JSON->perl2JSON($formatted_parts)); + if (@$formatted_parts) { + $summary->generated_coverage(OpenSRF::Utils::JSON->perl2JSON($formatted_parts)); + } else { + # we had no issuances or MFHD data for this type, so clear any + # generated data which may have existed before + $summary->generated_coverage(''); + } my $method = "${cu_method}_serial_${type}_summary"; return $e->die_event unless $e->$method($summary); } @@ -1852,6 +1860,7 @@ sub _summarize_contents { my $editor = shift; my $issuances = shift; my $sdist = shift; + my $type = shift; # create or lookup MFHD record my $mfhd; @@ -1925,7 +1934,7 @@ sub _summarize_contents { } my @formatted_parts; - my @scap_fields_ordered = $mfhd->field('85[345]'); + my @scap_fields_ordered = $mfhd->field($MFHD_TAGS_BY_NAME{$type}); foreach my $scap_field (@scap_fields_ordered) { #TODO: use generic MFHD "summarize" method, once available my @updated_holdings; -- 2.11.0