Fix bugs in ExpireIncompleteSurveyResponses Workflow

Need to join on revisionDate otherwise one email per Survey revision
will be sent. (Added explicit test for this)

Some standard template vars were also missing - username and userId.

(forward-port from webgui-7.7)
This commit is contained in:
Patrick Donelan 2009-09-25 14:13:15 +10:00
parent 79f84aec68
commit 549f9ce650
3 changed files with 85 additions and 14 deletions

View file

@ -20,6 +20,7 @@ use base 'WebGUI::Workflow::Activity';
use WebGUI::Asset;
use WebGUI::DateTime;
use DateTime::Duration;
use WebGUI::Mail::Send;
=head1 NAME
@ -106,19 +107,7 @@ sub execute {
my $self = shift;
my $session = $self->session;
my $sql = <<END_SQL;
select r.Survey_responseId, r.username, r.userId, upd.email, upd.firstName, upd.lastName, r.startDate, s.timeLimit, s.doAfterTimeLimit, ad.title, ad.url
from Survey s, Survey_response r, assetData ad, userProfileData upd
where r.isComplete = 0
and s.timeLimit > 0
and ( unix_timestamp() - r.startDate ) > ( s.timeLimit * 60 )
and r.assetId = s.assetId
and ad.assetId = s.assetId
and ad.revisionDate = s.revisionDate
and upd.userId = r.userId
END_SQL
my $refs = $self->session->db->buildArrayRefOfHashRefs($sql);
my $refs = $self->session->db->buildArrayRefOfHashRefs( $self->getSql );
for my $ref (@{$refs}) {
if($self->get("deleteExpired")){
$session->log->debug("deleting response: $ref->{Survey_responseId} ");
@ -141,6 +130,8 @@ END_SQL
responseId => $ref->{Survey_responseId},
deleted => $self->get("deleteExpired"),
companyName => $self->session->setting->get("companyName"),
username => $ref->{username},
userId => $ref->{userId},
};
my $template = WebGUI::Asset->newByDynamicClass($self->session,$self->get('emailTemplateId'));
my $message = $template->processTemplate($var, $self->get("emailTemplateId"));
@ -158,4 +149,35 @@ END_SQL
return $self->COMPLETE;
}
=head2 getSql
Returns the SQL used to look up incomplete survey responses.
Factored out into a separate subroutine for the sake of testability.
=cut
sub getSql {
return <<END_SQL;
select
r.Survey_responseId, r.username, r.userId, r.startDate,
upd.email, upd.firstName, upd.lastName,
s.timeLimit, s.doAfterTimeLimit,
ad.title, ad.url
from
Survey_response r, Survey s, assetData ad, userProfileData upd
where
r.isComplete = 0
and s.timeLimit > 0
and ( unix_timestamp() - r.startDate ) > ( s.timeLimit * 60 )
and r.assetId = s.assetId
and ad.assetId = s.assetId
and ad.revisionDate = s.revisionDate
and s.revisionDate = r.revisionDate
and upd.userId = r.userId
END_SQL
}
1;