LP#1660059: Protect against null value in group field
authorMike Rylander <mrylander@gmail.com>
Tue, 31 Jan 2017 17:35:05 +0000 (12:35 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Tue, 31 Jan 2017 20:44:31 +0000 (15:44 -0500)
If a nullable event grouping field is configured, and a null value is indeed
encountered when pulling together events, the Action/Trigger code will exit
unceremoniously.  To prevent this, we will now collect events with either
a null grouping object or grouping field, and use a new batch invalidation
API call to get rid of them as quickly as possible after group sorting is
complete.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Event.pm

index 920175b..3336dcb 100644 (file)
@@ -757,6 +757,7 @@ sub grouped_events {
         $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
     }
 
+    my @invalid; # sync for events with a null grouping field
     for my  $e (@fleshed_events) {
         if (my $group = $e->event->event_def->group_field) {
 
@@ -771,12 +772,19 @@ sub grouped_events {
             };
 
             unless($node) { # should not get here, but to be safe..
-                $e->update_state('invalid');
+                push @invalid, $e;
                 next;
             }
 
             # get the grouping value for the grouping object on this event
             my $ident_value = $node->$group_field();
+
+            # could by false-y, so check definedness
+            if (!defined($ident_value)) {
+                push @invalid, $e;
+                next;
+            }
+
             if(ref $ident_value) {
                 my $ident_field = $ident_value->Identity; 
                 $ident_value = $ident_value->$ident_field()
@@ -791,6 +799,7 @@ sub grouped_events {
         }
     }
 
+    OpenILS::Application::Trigger::Event->invalidate(@invalid) if @invalid;
 
     return \%groups;
 }
index 91c7994..bd85e38 100644 (file)
@@ -10,6 +10,27 @@ use Safe;
 
 my $log = 'OpenSRF::Utils::Logger';
 
+sub invalidate {
+    my $class = shift;
+    my @events = @_;
+
+    # if called as an instance method
+    unshift(@events,$class) if ref($class);
+
+    my $e = new_editor();
+    $e->xact_begin;
+
+    map {
+        $_->editor($e);
+        $_->standalone(0);
+        $_->update_state('invalid');
+    } @events;
+
+    $e->commit;
+
+    return @events;
+}
+
 sub new {
     my $class = shift;
     my $id = shift;