Add test email queueing and mailing status report lines in manager.
This commit is contained in:
parent
643a63c568
commit
3f3ee717b7
2 changed files with 118 additions and 1 deletions
|
|
@ -2,6 +2,9 @@ package WebGUI::Mailing;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
use Carp;
|
||||||
|
|
||||||
|
use WebGUI::Newsletter::Admin;
|
||||||
|
|
||||||
use base 'WebGUI::Crud';
|
use base 'WebGUI::Crud';
|
||||||
|
|
||||||
|
|
@ -43,5 +46,115 @@ sub crud_definition {
|
||||||
return $definition;
|
return $definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub getStatusLine {
|
||||||
|
my $self = shift;
|
||||||
|
my $db = $self->session->db;
|
||||||
|
|
||||||
|
my $sth = $db->read(
|
||||||
|
'select status, isTest, count( status ) as cnt from WGMailing_queue where mailingId=? group by status,isTest',
|
||||||
|
[
|
||||||
|
$self->getId,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
my $status = {};
|
||||||
|
while ( my $row = $sth->hashRef ) {
|
||||||
|
$status->{ $row->{status} }->{ $row->{ isTest } ? 'test' : 'regular' } = $row->{ cnt };
|
||||||
|
};
|
||||||
|
|
||||||
|
my $output;
|
||||||
|
foreach ( qw{ queued sent error } ) {
|
||||||
|
$output .= sprintf '%s ( %i + %i (test) ) | ',
|
||||||
|
$_,
|
||||||
|
$status->{$_}->{regular},
|
||||||
|
$status->{$_}->{test},
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub queueTestEmails {
|
||||||
|
my $self = shift;
|
||||||
|
my $to = shift;
|
||||||
|
my $userIds = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
|
||||||
|
croak "No or invalid to address: [$to]" unless ( $to && !ref $to );
|
||||||
|
croak "User ids must be an array ref" unless ( ref $userIds eq 'ARRAY' );
|
||||||
|
|
||||||
|
foreach my $userId ( @{ $userIds } ) {
|
||||||
|
WebGUI::Mailing::Email->create( $session, {
|
||||||
|
mailingId => $self->getId,
|
||||||
|
userId => $userId,
|
||||||
|
recipientEmail => $to,
|
||||||
|
isTest => 1,
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub www_sendTestEmails {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
|
||||||
|
my $asset = WebGUI::Asset->newByDynamicClass( $session, $self->get('assetId') );
|
||||||
|
croak "Cannot instaciate asset " . $self->get('assetId') unless $asset;
|
||||||
|
|
||||||
|
my $userIds = $asset->getRecipients;
|
||||||
|
|
||||||
|
tie my %options, 'Tie::IxHash', (
|
||||||
|
map { $_->getId => $_->username . "(" . $_->get('email') . ")" }
|
||||||
|
sort { $a->username <=> $b->username }
|
||||||
|
grep { defined $_ }
|
||||||
|
map { WebGUI::User->new( $session, $_ ) }
|
||||||
|
@{ $userIds }
|
||||||
|
);
|
||||||
|
|
||||||
|
my $f = WebGUI::HTMLForm->new( $session );
|
||||||
|
$f->hidden(
|
||||||
|
name => 'newsletter',
|
||||||
|
value => 'mailing',
|
||||||
|
);
|
||||||
|
$f->hidden(
|
||||||
|
name => 'func',
|
||||||
|
value => 'sendTestEmailsConfirm',
|
||||||
|
);
|
||||||
|
$f->hidden(
|
||||||
|
name => 'id',
|
||||||
|
value => $self->getId,
|
||||||
|
);
|
||||||
|
$f->email(
|
||||||
|
name => 'to',
|
||||||
|
label => 'Send emails to test address',
|
||||||
|
);
|
||||||
|
$f->selectList(
|
||||||
|
name => 'userIds',
|
||||||
|
label => 'Generate test emails for user(s)',
|
||||||
|
size => 10,
|
||||||
|
multiple=> 1,
|
||||||
|
options => \%options,
|
||||||
|
);
|
||||||
|
$f->submit( 'Send' );
|
||||||
|
|
||||||
|
return $f->print;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub www_sendTestEmailsConfirm {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
my $form = $session->form;
|
||||||
|
|
||||||
|
my $to = $form->email( 'to' );
|
||||||
|
my @userIds = $form->selectList( 'userIds' );
|
||||||
|
|
||||||
|
$self->queueTestEmails( $to, \@userIds );
|
||||||
|
|
||||||
|
return WebGUI::Newsletter::Admin->new( $session )->www_view;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,11 @@ sub www_view {
|
||||||
my @mailings;
|
my @mailings;
|
||||||
my $it = WebGUI::Mailing->getAllIterator( $session, { sequenceKeyValue => $issueId } );
|
my $it = WebGUI::Mailing->getAllIterator( $session, { sequenceKeyValue => $issueId } );
|
||||||
while ( my $mailing = $it->() ) {
|
while ( my $mailing = $it->() ) {
|
||||||
push @mailings, $mailing->get;
|
push @mailings, {
|
||||||
|
%{ $mailing->get },
|
||||||
|
status => $mailing->getStatusLine,
|
||||||
|
sendTestUrl => $url->page('newsletter=mailing;func=sendTestEmails;id='.$mailing->getId),
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
push @issues, {
|
push @issues, {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue