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;
=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";
# 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<FS::cust_event>
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;
}
'cust_pkg' => 'Package',
'cust_bill' => 'Invoice',
'cust_main' => 'Customer',
+ '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
'cust_main' => 'custnum',
'cust_bill' => 'invnum',
'cust_pkg' => 'pkgnum',
+ 'cust_pay' => 'paynum',
'cust_pay_batch' => 'paybatchnum',
'cust_statement' => 'statementnum',
'svc_acct' => 'svcnum',
}
$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() ],
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 )
);
}
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
=head1 SEE ALSO
L<FS::part_event_option>, L<FS::part_event_condition>, L<FS::cust_main>,
-L<FS::cust_pkg>, L<FS::svc_acct>, L<FS::cust_bill>, L<FS::cust_bill_event>,
+L<FS::cust_pkg>, L<FS::svc_acct>, L<FS::cust_bill>, L<FS::cust_event>,
L<FS::Record>,
schema.html from the base documentation.