[freeside-commits] freeside/FS/FS part_event.pm,1.6,1.7

Mark Wells mark at wavetail.420.am
Tue Feb 14 17:32:11 PST 2012


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv27823/FS/FS

Modified Files:
	part_event.pm 
Log Message:
query billing events to see affected objects, #15142

Index: part_event.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_event.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -d -r1.6 -r1.7
--- part_event.pm	22 Sep 2011 21:41:46 -0000	1.6
+++ part_event.pm	15 Feb 2012 01:32:09 -0000	1.7
@@ -253,31 +253,23 @@
   }
 }
 
-=item initialize PARAMS
-
-Identify all objects eligible for this event and create L<FS::cust_event>
-records for each of them, as of the present time, with status "initial".  When 
-combined with conditions that prevent an event from running more than once
-(at all or within some period), this will exclude any objects that met the 
-conditions before the event was created.
+=item targets
 
-If an L<FS::part_event> object needs to be initialized, it should be created 
-in a disabled state to avoid running the event prematurely for any existing 
-objects.  C<initialize> will enable it once all the cust_event records 
-have been created.
+Returns all objects (of type C<FS::eventtable>, for this object's 
+C<eventtable>) eligible for processing under this event, as of right now.
+The L<FS::cust_event> object used to test event conditions will be 
+included in each object as the 'cust_event' pseudo-field.
 
-This may take some time, so it should be run from the job queue.
+This is not used in normal event processing (which is done on a 
+per-customer basis to control timing of pre- and post-billing events)
+but can be useful when configuring events.
 
 =cut
 
-sub initialize {
+sub targets {
   my $self = shift;
   my $time = time; # $opt{'time'}?
 
-  my $oldAutoCommit = $FS::UID::AutoCommit;
-  local $FS::UID::AutoCommit = 0;
-  my $dbh = dbh;
-
   my $eventpart = $self->eventpart;
   $eventpart =~ /^\d+$/ or die "bad eventpart $eventpart";
   my $eventtable = $self->eventtable;
@@ -286,8 +278,9 @@
   my $linkage = '';
   # this is the 'object' side of the FROM clause
   if ( $eventtable ne 'cust_main' ) {
-    $linkage = ($self->eventtables_cust_join->{$eventtable} || '') . 
-        ' LEFT JOIN cust_main USING (custnum) '
+    $linkage = 
+        ($self->eventtables_cust_join->{$eventtable} || '') .
+        ' LEFT JOIN cust_main USING (custnum) ';
   }
 
   # this is the 'event' side
@@ -300,24 +293,55 @@
 
   $where .= ' AND cust_main.agentnum = '.$self->agentnum
     if $self->agentnum;
-  # don't enforce check_freq since this is a special, out-of-order check,
-  # and don't enforce disabled because we want to do this with the part_event 
-  # disabled.
+  # don't enforce check_freq since this is a special, out-of-order check
+  # and don't enforce disabled because we want to be able to see targets 
+  # for a disabled event
+
   my @objects = qsearch({
       table     => $eventtable,
       hashref   => {},
       addl_from => $join,
       extra_sql => "WHERE $where",
-      debug     => 1,
   });
-  warn "initialize: ".(scalar @objects) ." $eventtable objects found\n" 
-    if $DEBUG;
-  my $error = '';
+  my @tested_objects;
   foreach my $object ( @objects ) {
-    # test conditions
     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;
+  }
+  @tested_objects;
+}
+
+=item initialize PARAMS
+
+Identify all objects eligible for this event and create L<FS::cust_event>
+records for each of them, as of the present time, with status "initial".  When 
+combined with conditions that prevent an event from running more than once
+(at all or within some period), this will exclude any objects that met the 
+conditions before the event was created.
+
+If an L<FS::part_event> object needs to be initialized, it should be created 
+in a disabled state to avoid running the event prematurely for any existing 
+objects.  C<initialize> will enable it once all the cust_event records 
+have been created.
+
+This may take some time, so it should be run from the job queue.
+
+=cut
+
+sub initialize {
+  my $self = shift;
+  my $error;
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my @objects = $self->targets;
+  foreach my $object ( @objects ) {
+    my $cust_event = $object->get('cust_event');
     $cust_event->status('initial');
     $error = $cust_event->insert;
     last if $error;



More information about the freeside-commits mailing list