X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event.pm;h=be894593e5f3b12b5ff12efb2bf5d219637d78e0;hb=103dfde149eec5034696d073253255f508a1be78;hp=9a1144c85dfc16f5927d0de651d9f0b336cb344e;hpb=2b2dd969f3c18751afc583ad1e836ab8e6f73b5d;p=freeside.git diff --git a/FS/FS/part_event.pm b/FS/FS/part_event.pm index 9a1144c85..be894593e 100644 --- a/FS/FS/part_event.pm +++ b/FS/FS/part_event.pm @@ -1,11 +1,12 @@ package FS::part_event; +use base qw( FS::m2name_Common FS::option_Common ); use strict; -use base qw( FS::m2name_Common FS::option_Common ); use vars qw( $DEBUG ); use Carp qw(confess); use FS::Record qw( dbh qsearch qsearchs ); use FS::Conf; +use FS::Cursor; use FS::part_event_option; use FS::part_event_condition; use FS::cust_event; @@ -251,10 +252,28 @@ but can be useful when configuring events. =cut -sub targets { +sub targets { # may want to cursor this also my $self = shift; my %opt = @_; - my $time = $opt{'time'} || time; + my $time = $opt{'time'} ||= time; + + my $query = $self->_target_query(%opt); + my @objects = qsearch($query); + my @tested_objects; + foreach my $object ( @objects ) { + 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; +} + +sub _target_query { + my $self = shift; + my %opt = @_; + my $time = $opt{'time'}; my $eventpart = $self->eventpart; $eventpart =~ /^\d+$/ or die "bad eventpart $eventpart"; @@ -285,23 +304,15 @@ sub targets { # 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", - }); - my @tested_objects; - foreach my $object ( @objects ) { - 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 @@ -323,26 +334,26 @@ sub initialize { my $self = shift; my $error; - my $oldAutoCommit = $FS::UID::AutoCommit; - local $FS::UID::AutoCommit = 0; - my $dbh = dbh; + my $time = time; + + local $FS::UID::AutoCommit = 1; + my $cursor = FS::Cursor->new( $self->_target_query('time' => $time) ); + while (my $object = $cursor->fetch) { + + my $cust_event = $self->new_cust_event($object, 'time' => $time); + next unless $cust_event->test_conditions; - 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; + die $error if $error; } - if ( !$error and $self->disabled ) { + + # on successful completion only, re-enable the event + if ( $self->disabled ) { $self->disabled(''); $error = $self->replace; + die $error if $error; } - if ( $error ) { - $dbh->rollback; - return $error; - } - $dbh->commit if $oldAutoCommit; return; } @@ -372,7 +383,7 @@ sub eventtable_labels { 'cust_pay' => 'Payment', 'cust_pay_batch' => 'Batch payment', 'cust_statement' => 'Statement', #too general a name here? "Invoice group"? - 'svc_acct' => 'Login service', + 'svc_acct' => 'Account service (svc_acct)', ; \%hash @@ -559,7 +570,7 @@ foreach my $INC ( @INC ) { } $actions{$mod} = { ( map { $_ => "FS::part_event::Action::$mod"->$_() } - qw( description eventtable_hashref default_weight deprecated ) + qw( description eventtable_hashref default_weight deprecated will_send_invoice ) #option_fields_hashref ), 'option_fields' => [ "FS::part_event::Action::$mod"->option_fields() ], @@ -571,9 +582,11 @@ sub actions { my( $class, $eventtable ) = @_; ( map { $_ => $actions{$_} } - sort { $actions{$a}->{'default_weight'}<=>$actions{$b}->{'default_weight'} } - # || $actions{$a}->{'description'} cmp $actions{$b}->{'description'} } - $class->all_actions( $eventtable ) + sort { + $actions{$a}->{'default_weight'} <=> $actions{$b}->{'default_weight'} + || $actions{$a}->{'description'} cmp $actions{$b}->{'description'} + } + $class->all_actions( $eventtable ) ); } @@ -591,6 +604,20 @@ sub all_actions { keys %actions } +=item invoice_send_actions + +Returns a list of action names that send invoices + +=cut + +sub invoice_send_actions { + my ( $class ) = @_; + + grep { $actions{$_}->{'will_send_invoice'} } + keys %actions + +} + =item process_initialize 'eventpart' => EVENTPART Job queue wrapper for "initialize". EVENTPART identifies the @@ -606,28 +633,12 @@ sub process_initialize { $part_event->initialize; } -sub _upgrade_data { #class method - my ($class, %opts) = @_; - - foreach my $part_event ( - qsearch('part_event', { 'action' => 'cust_bill_realtime_card' }), - qsearch('part_event', { 'action' => 'cust_bill_realtime_check' }), - ) { - - $part_event->action('realtime_auto'); - my $error = $part_event->replace; - die $error if $error; - - } - -} - =back =head1 SEE ALSO L, L, L, -L, L, L, L, +L, L, L, L, L, schema.html from the base documentation.