[open-ils-commits] [GIT] Evergreen ILS branch rel_2_7 updated. 0bd632658a23b8e544da1982beb75a4acb7f1bef

Evergreen Git git at git.evergreen-ils.org
Tue Feb 3 16:06:50 EST 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, rel_2_7 has been updated
       via  0bd632658a23b8e544da1982beb75a4acb7f1bef (commit)
       via  ad97a1bc053da67fbaae62fb208180c510b46e82 (commit)
       via  ae58b646675a6f0829aa42dba72928cde8a1f559 (commit)
      from  38e4319391fc830db73b40b1bce27fbd09e2bc9d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0bd632658a23b8e544da1982beb75a4acb7f1bef
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Tue Apr 8 16:22:33 2014 -0400

    LP#1078593 Regenerate summaries when deleting issuances
    
    Both interfaces currently allow you to delete issuances even if they
    have items attached and have the delete cascade.  While this might be
    a dangerous allowance, we should still make sure to keep our summaries
    updated when this happens.
    
    This commit adds automatic summary regeneration when deleting issuances
    in either serials interface.
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>
    Signed-off-by: Ben Shum <bshum at biblio.org>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm
index c2caf50..07cd43a 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm
@@ -392,6 +392,7 @@ sub fleshed_issuance_alter {
     my $override = $self->api_name =~ /override/;
 
     my %found_ssub_ids;
+    my %regen_ssub_ids;
     for my $issuance (@$issuances) {
         my $ssub_id = ref $issuance->subscription ? $issuance->subscription->id : $issuance->subscription;
         if (!exists($found_ssub_ids{$ssub_id})) {
@@ -413,6 +414,7 @@ sub fleshed_issuance_alter {
 
         if( $issuance->isdeleted ) {
             $evt = _delete_siss( $editor, $override, $issuance);
+            $regen_ssub_ids{$ssub_id} = 1;
         } elsif( $issuance->isnew ) {
             _cleanse_dates($issuance, ['date_published']);
             $evt = _create_siss( $editor, $issuance );
@@ -424,11 +426,19 @@ sub fleshed_issuance_alter {
         last if $evt;
     }
 
-    if( $evt ) {
+    if (!$evt) {
+        # if we deleted any issuances, update the summaries
+        # for all dists in those ssubs
+        my @ssub_ids = keys %regen_ssub_ids;
+        $evt = _regenerate_summaries($editor, {'ssub_ids' => \@ssub_ids}) if @ssub_ids;
+    }
+
+    if ( $evt ) {
         $logger->info("fleshed issuance-alter failed with event: ".OpenSRF::Utils::JSON->perl2JSON($evt));
         $editor->rollback;
         return $evt;
     }
+
     $logger->debug("issuance-alter: done updating issuance batch");
     $editor->commit;
     $logger->info("fleshed issuance-alter successfully updated ".scalar(@$issuances)." issuances");
diff --git a/Open-ILS/src/templates/serial/subscription/issuance.tt2 b/Open-ILS/src/templates/serial/subscription/issuance.tt2
index a90e5b0..42042c4 100644
--- a/Open-ILS/src/templates/serial/subscription/issuance.tt2
+++ b/Open-ILS/src/templates/serial/subscription/issuance.tt2
@@ -7,7 +7,7 @@
         <span dojoType="dijit.form.Button"
             onclick="iss_grid.showCreatePane();">[% l('New Issuance') %]</span>
         <span dojoType="dijit.form.Button"
-            onclick="iss_grid.deleteSelected();">[% l('Delete Selected') %]</span>
+            onclick="iss_grid.deleteSelected(); regenerate_summaries();">[% l('Delete Selected') %]</span>
     </div>
 </div>
 [%- IF CGI.param('context') != 'scv' -%]
diff --git a/Open-ILS/web/js/ui/default/serial/subscription/issuance.js b/Open-ILS/web/js/ui/default/serial/subscription/issuance.js
index 3f4dfcf..047ea77 100644
--- a/Open-ILS/web/js/ui/default/serial/subscription/issuance.js
+++ b/Open-ILS/web/js/ui/default/serial/subscription/issuance.js
@@ -98,3 +98,20 @@ function generate_predictions(fields) {
         progess_dialog.hide();
     }
 }
+
+function regenerate_summaries() {
+    var args = {"ssub_ids": [sub.id()]};
+    try {
+        fieldmapper.standardRequest(
+            ["open-ils.serial", "open-ils.serial.regenerate_summaries"], {
+                "params": [openils.User.authtoken, args],
+                "async": true,
+                "onresponse": function(r) {
+                    openils.Util.readResponse(r); /* tests for events */
+                }
+            }
+        );
+    } catch (E) {
+        alert(E);
+    }
+}

commit ad97a1bc053da67fbaae62fb208180c510b46e82
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Wed Apr 10 18:42:11 2013 -0400

    LP#1078593 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 <dbw2 at calvin.edu>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>
    Signed-off-by: Ben Shum <bshum at biblio.org>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm
index 623f39b..c2caf50 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm
@@ -1590,6 +1590,148 @@ sub _prepare_summaries {
     return $e->die_event unless $e->$method($summary);
 }
 
+
+__PACKAGE__->register_method(
+    method    => 'regen_summaries',
+    api_name  => 'open-ils.serial.regenerate_summaries',
+    api_level => 1,
+    argc      => 1,
+    signature => {
+        'desc'   => 'Regenerate all the generated_coverage fields for given distributions or subscriptions (depending on params given). Params are expected to be hash members.',
+        'params' => [ {
+                 name => 'sdist_ids',
+                 desc => 'IDs of the distribution whose coverage you want to regenerate',
+                 type => 'array'
+            },
+            {
+                 name => 'ssub_ids',
+                 desc => 'IDs of the subscriptions 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 regen_summaries {
+    my ($self, $conn, $auth, $opts) = @_;
+
+    my $e = new_editor("authtoken" => $auth, "xact" => 1);
+    return $e->die_event unless $e->checkauth;
+    # Perm checks not necessary since generated_coverage is akin to
+    # caching of data, not actual editing.  XXX This might need more
+    # consideration.
+    #return $editor->die_event unless $editor->allowed("RECEIVE_SERIAL");
+
+    my $evt = _regenerate_summaries($e, $opts);
+    if ($U->event_code($evt)) {
+        $e->rollback;
+        return $evt;
+    }
+
+    $e->commit;
+
+    return undef;
+}
+
+sub _regenerate_summaries {
+    my ($e, $opts) = @_;
+
+    $logger->debug('_regenerate_summaries with opts: ' . OpenSRF::Utils::JSON->perl2JSON($opts));
+    my @sdist_ids;
+    if ($opts->{'ssub_ids'}) {
+        foreach my $ssub_id (@{$opts->{'ssub_ids'}}) {
+            my $sdist_ids_temp = $e->search_serial_distribution(
+                { 'subscription' => $ssub_id },
+                { 'idlist' => 1 }
+            );
+            push(@sdist_ids, @$sdist_ids_temp);
+        }
+    } elsif ($opts->{'sdist_ids'}) {
+        @sdist_ids = @$opts->{'sdist_ids'};
+    }
+
+    foreach my $sdist_id (@sdist_ids) {
+        # get distribution
+        my $sdist = $e->retrieve_serial_distribution($sdist_id)
+            or return $e->die_event;
+
+# See large comment below
+#        my $has_merged_mfhd;
+        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;
+
+# This level of nuance doesn't appear to be necessary.
+# At the moment, we pass down an empty issuance list,
+# and the inner methods will "do the right thing" and
+# pull in the MFHD if called for, but in some cases not
+# ultimately generate any coverage.  The code below is
+# broken in cases where we delete the last issuance, since
+# the now empty summary never gets updated.
+#
+# Leaving this code for now (2014/04) in case pushing
+# the logic down ends up being too slow or complicates
+# the inner methods beyond their scope.
+#
+#            if (!@$issuances and !$has_merged_mfhd) {
+#                if (!defined($has_merged_mfhd)) {
+#                    # even without issuances, we can generate a summary
+#                    # from a merged MFHD record, so look for one
+#                    my $mfhd_ids = $e->search_serial_record_entry(
+#                        {
+#                            '+sdist' => {
+#                                'id' => $sdist_id,
+#                                'summary_method' => 'merge_with_sre'
+#                            }
+#                        },
+#                        {
+#                            'join' => { 'sdist' => {} },
+#                            'idlist' => 1
+#                        }
+#                    );
+#                    if ($mfhd_ids and @$mfhd_ids) {
+#                        $has_merged_mfhd = 1;
+#                    } else {
+#                        next;
+#                    }
+#                } else {
+#                    next; # abort to prevent empty summary creation (i.e. '[]')
+#                }
+#            }
+            my $evt = _prepare_summaries($e, $issuances, $sdist, $type);
+            if ($U->event_code($evt)) {
+                $e->rollback;
+                return $evt;
+            }
+        }
+    }
+
+    return undef;
+}
+
 sub _unit_by_iss_and_str {
     my ($e, $issuance, $stream) = @_;
 

commit ae58b646675a6f0829aa42dba72928cde8a1f559
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Tue Apr 8 16:11:31 2014 -0400

    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 <dbw2 at calvin.edu>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>
    Signed-off-by: Ben Shum <bshum at biblio.org>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm
index 60b7383..623f39b 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;

-----------------------------------------------------------------------

Summary of changes:
 .../src/perlmods/lib/OpenILS/Application/Serial.pm |  171 +++++++++++++++++++-
 .../src/templates/serial/subscription/issuance.tt2 |    2 +-
 .../js/ui/default/serial/subscription/issuance.js  |   17 ++
 3 files changed, 184 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list