X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_event.pm;h=1c2389989d2d7cf3ba16c7c4b1f68084ad329c61;hp=9a1144c85dfc16f5927d0de651d9f0b336cb344e;hb=8282a324857d658d17061e3f0867d8c7d71b098a;hpb=376794a00e837317e35fefd61a29ab58c0303b35 diff --git a/FS/FS/part_event.pm b/FS/FS/part_event.pm index 9a1144c85..1c2389989 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 $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'} || time; + 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 @@ -606,22 +617,6 @@ 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