78 lines
1.8 KiB
Perl
78 lines
1.8 KiB
Perl
package WebGUI::Workflow::Activity::SendQueuedMailings;
|
|
|
|
use WebGUI::Mailing;
|
|
use WebGUI::Mailing::Email;
|
|
|
|
use base 'WebGUI::Workflow::Activity';
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
=head2 definition ( session, definition )
|
|
|
|
See WebGUI::Workflow::Activity::definition() for details.
|
|
|
|
=cut
|
|
|
|
sub definition {
|
|
my $class = shift;
|
|
my $session = shift;
|
|
my $definition = shift;
|
|
|
|
push( @{ $definition }, {
|
|
name => 'Send queued newsletter mailings',
|
|
# properties => {
|
|
# someField => {
|
|
# fieldType=>"integer",
|
|
# label=>"Some Field",
|
|
# defaultValue=>0,
|
|
# hoverHelp=>"Hover help for some field."
|
|
# },
|
|
# }
|
|
} );
|
|
|
|
return $class->SUPER::definition( $session, $definition );
|
|
}
|
|
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
=head2 execute ( [ object ] )
|
|
|
|
See WebGUI::Workflow::Activity::execute() for details.
|
|
|
|
=cut
|
|
|
|
sub execute {
|
|
my $self = shift;
|
|
my $object = shift;
|
|
my $instance = shift;
|
|
my $session = $self->session;
|
|
|
|
my $maxTime = time + $self->getTTL;
|
|
|
|
# First send all queued test emails.
|
|
my $it = WebGUI::Mailing::Email->getQueuedTestEmails( $session );
|
|
while ( my $email = $it->() ) {
|
|
return $self->WAITING(1) if time >= $maxTime;
|
|
|
|
$email->send;
|
|
}
|
|
|
|
# Queue all mailings that are ready to send.
|
|
WebGUI::Mailing->queueScheduled( $session );
|
|
|
|
# Fetch mailings that are queued to be sent one by one, and send them.
|
|
while ( my $mailing = WebGUI::Mailing->getNextInSendQueue( $session ) ) {
|
|
return $self->WAITING(1) if time >= $maxTime;
|
|
|
|
$mailing->send( $maxTime ) || return $self->WAITING(1);
|
|
}
|
|
|
|
return $self->COMPLETE;
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
#vim:ft=perl
|