LP#1261486 Action/trigger aggregator script repairs user/csharp/lp1366964-libdbi-error-handling-signoff
authorBill Erickson <berick@esilibrary.com>
Wed, 11 Dec 2013 17:58:49 +0000 (12:58 -0500)
committerGalen Charlton <gmc@esilibrary.com>
Wed, 15 Oct 2014 20:45:00 +0000 (13:45 -0700)
* If both date filters are selected, apply both instead of replacing the
  first with the second

* Select distinct event output to prevent dupes

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/support-scripts/action_trigger_aggregator.pl

index aebf235..4a53454 100755 (executable)
@@ -143,14 +143,28 @@ print "Processing event-defs @event_defs\n" if $verbose;
 
 my %date_filter;
 $date_filter{run_time} = {'>=' => $start_date} if $start_date;
-$date_filter{run_time} = {'<' => $end_date} if $end_date;
+
+if ($end_date) {
+    if ($date_filter{run_time}) {
+        # both filters requested, -and them together
+        $date_filter{'-and'} = [
+            {run_time => delete $date_filter{run_time}},
+            {run_time => {'<' => $end_date}}
+        ];
+    } else {
+        $date_filter{run_time} = {'<' => $end_date};
+    }
+}
+                
 
 # collect the event tempate output data
 # use a real session here so we can stream results directly to the output file
 my $ses = OpenSRF::AppSession->create('open-ils.cstore');
 my $req = $ses->request(
     'open-ils.cstore.json_query', {
-        select => {ateo => ['data']},
+        select => {ateo => [
+            # ateo's may be linked to multiple atev's; select distinct.
+            {column => 'id', transform => 'distinct'}, 'data']},
         from => {ateo => { atev => {
             filter => {state => 'complete', %date_filter},
             join => {atevdef => {filter => {