From: Dan Wells Date: Wed, 10 Apr 2013 22:42:11 +0000 (-0400) Subject: Add method for regenerating serial summaries X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=891df1333449cfeacc742bd6088a46feb86a00cc;p=working%2FEvergreen.git Add method for regenerating serial summaries Right now, serial summaries only update when receiving or resetting items. They need to update more often, so lets start by adding a method just for doing that. Signed-off-by: Dan Wells --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm index 377069dcf4..b00cc69fd3 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm @@ -1547,6 +1547,76 @@ sub _prepare_summaries { return $e->die_event unless $e->$method($summary); } + +__PACKAGE__->register_method( + method => 'regenerate_summaries', + api_name => 'open-ils.serial.regenerate_summaries', + api_level => 1, + argc => 1, + signature => { + 'desc' => 'Regenerate all the generated_coverage fields for given distributions', + 'params' => [ { + name => 'sdist_ids', + desc => 'IDs of the distribution whose coverage you want to regenerate', + type => 'array' + } + ], + 'return' => { + desc => 'Returns undef if successful, event if failed', + type => 'mixed' + } +#TODO: best practices for return values + } +); + +sub regenerate_summaries { + my ($self, $conn, $auth, $sdist_ids) = @_; + + my $e = new_editor("authtoken" => $auth, "xact" => 1); + return $e->die_event unless $e->checkauth; +#TODO: need to check for MFHD editing OR serial receiving + #return $editor->die_event unless $editor->allowed("RECEIVE_SERIAL"); + + foreach my $sdist_id (@$sdist_ids) { + # get distribution + my $sdist = $e->retrieve_serial_distribution($sdist_id) + or return $e->die_event; + + foreach my $type (@MFHD_NAMES) { + # get issuances + my $issuances = $e->search_serial_issuance([ + { + "+sdist" => {"id"=> $sdist_id}, + "+sitem" => {"status" => "Received"}, + "+scap" => {"type" => $type} + }, + { + "join" => { + "sitem" => {}, + "scap" => {}, + "ssub" => { + "join" => {"sdist" =>{}} + } + }, + "order_by" => { + "siss" => "date_published" + } + } + ]) or return $e->die_event; + + my $evt = _prepare_summaries($e, $issuances, $sdist, $type, 1); #XXX $do_combined) + if ($U->event_code($evt)) { + $e->rollback; + return $evt; + } + } + } + + $e->commit; + + return undef; +} + sub _unit_by_iss_and_str { my ($e, $issuance, $stream) = @_;