[freeside-commits] branch master updated. 8864bd26231dc8c6ec436c62af553bdb3d77be9a

Mark Wells mark at 420.am
Wed Aug 29 15:24:34 PDT 2012


The branch, master has been updated
       via  8864bd26231dc8c6ec436c62af553bdb3d77be9a (commit)
       via  dc6eb0609882ec1443a79a309577108e92011dc9 (commit)
      from  c19fc5ead7b7eb700ced64658378ac934b1bc98d (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 8864bd26231dc8c6ec436c62af553bdb3d77be9a
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Aug 29 15:24:21 2012 -0700

    after_event condition, #18687

diff --git a/FS/FS/part_event/Condition/after_event.pm b/FS/FS/part_event/Condition/after_event.pm
new file mode 100644
index 0000000..c59d847
--- /dev/null
+++ b/FS/FS/part_event/Condition/after_event.pm
@@ -0,0 +1,78 @@
+package FS::part_event::Condition::after_event;
+
+use strict;
+use FS::Record qw( qsearchs );
+use FS::part_event;
+use FS::cust_event;
+
+use base qw( FS::part_event::Condition );
+
+sub description { "After running another event" }
+
+# Runs the event at least X days after the most recent time another event
+# ran on the same object.
+
+sub option_fields {
+  (
+    'eventpart' => { label=>'Event', type=>'select-part_event', },
+    'run_delay' => { label=>'Delay', type=>'freq', value=>'1',  },
+  );
+}
+
+# Specification:
+# Given an event B that has this condition, where the "eventpart"
+# option is set to event A, and the "run_delay" option is set to 
+# X days.
+# This condition is TRUE if:
+# - Event A last ran X or more days in the past,
+# AND
+# - Event B has not run since the most recent occurrence of event A.
+
+sub condition {
+  # similar to "once_every", but with a different eventpart
+  my($self, $object, %opt) = @_;
+
+  my $obj_pkey = $object->primary_key;
+  my $tablenum = $object->$obj_pkey();
+
+  my $before = $self->option_age_from('run_delay',$opt{'time'});
+  my $eventpart = $self->option('eventpart');
+
+  my %hash = (
+    'eventpart' => $eventpart,
+    'tablenum'  => $tablenum,
+    'status'    => { op => '!=', value => 'failed' },
+  );
+
+  my $most_recent_other = qsearchs( {
+    'table'     => 'cust_event',
+    'hashref'   => \%hash,
+    'order_by'  => " ORDER BY _date DESC LIMIT 1",
+  } )
+    or return 0; # if it hasn't run at all, return false
+  
+  return 0 if $most_recent_other->_date > $before; # we're still in the delay
+
+  # now see if there's been an instance of this event since the one we're
+  # following...
+  $hash{'eventpart'} = $self->eventpart;
+  if ( $opt{'cust_event'} and $opt{'cust_event'}->eventnum =~ /^(\d+)$/ ) {
+    $hash{'eventnum'} = { op => '!=', value => $1 };
+  }
+
+  my $most_recent_self = qsearchs( {
+    'table'     => 'cust_event',
+    'hashref'   => \%hash,
+    'order_by'  => " ORDER BY _date DESC LIMIT 1",
+  } );
+
+  return 0 if defined($most_recent_self) 
+          and $most_recent_self->_date >= $most_recent_other->_date;
+  # the follower has already run
+  
+  1;
+}
+
+# condition_sql, maybe someday
+
+1;

commit dc6eb0609882ec1443a79a309577108e92011dc9
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Aug 29 15:24:02 2012 -0700

    fix "time" parameter when querying events

diff --git a/FS/FS/part_event.pm b/FS/FS/part_event.pm
index 62f16fa..b7371c9 100644
--- a/FS/FS/part_event.pm
+++ b/FS/FS/part_event.pm
@@ -306,8 +306,8 @@ sub targets {
   });
   my @tested_objects;
   foreach my $object ( @objects ) {
-    my $cust_event = $self->new_cust_event($object);
-    next unless $cust_event->test_conditions('time' => $time);
+    my $cust_event = $self->new_cust_event($object, 'time' => $time);
+    next unless $cust_event->test_conditions;
 
     $object->set('cust_event', $cust_event);
     push @tested_objects, $object;

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

Summary of changes:
 FS/FS/part_event.pm                       |    4 +-
 FS/FS/part_event/Condition/after_event.pm |   78 +++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 2 deletions(-)
 create mode 100644 FS/FS/part_event/Condition/after_event.pm




More information about the freeside-commits mailing list