Fixed two new Survey bugs
* Survey response startDate stored twice startDate was being stored both in a column in Survey_response and also inside the serialised responseJSON. Consolidated to column and moved startDate methods to Survey.pm where they are actually used. Was not causing errors because both copies were initialised to "now" at response creation time, and then never changed (this is also why we don't need any repair code to fix existing survey repsonses in the wild). * Survey ExpireIncompleteSurveyResponses Workflow Activity not enabled The only time you'd actually want to modify startDate is when you're trying to simulate response expiry in test code, which is why I found the above bug when I was writing the missing test suite for ExpireIncompleteSurveyResponses. Along with test suite, added upgrade code to enable workflow activity and add it to the Daily Maintenance Tasks workflow. Also made minor fixes to the workflow activity, such as making sure it uses the correct isComplete code.
This commit is contained in:
parent
0bfc16bf9a
commit
146373937d
9 changed files with 236 additions and 102 deletions
|
|
@ -106,20 +106,32 @@ sub execute {
|
|||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
my $sql = "select r.Survey_responseId, r.username, r.userId, upd.email,upd.firstName,upd.lastName, r.startDate, s.timeLimit, 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 s.revisionDate = (select max(revisionDate) from Survey where assetId = s.assetId)
|
||||
and ad.assetId = s.assetId and ad.revisionDate = s.revisionDate and upd.userId = r.userId";
|
||||
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 s.revisionDate = r.revisionDate
|
||||
and ad.assetId = s.assetId
|
||||
and ad.revisionDate = s.revisionDate
|
||||
and upd.userId = r.userId
|
||||
END_SQL
|
||||
|
||||
my $refs = $self->session->db->buildArrayRefOfHashRefs($sql);
|
||||
for my $ref (@{$refs}) {
|
||||
if($self->get("deleteExpired") == 1){
|
||||
if($self->get("deleteExpired")){
|
||||
$session->log->debug("deleting response: $ref->{Survey_responseId} ");
|
||||
$self->session->db->write("delete from Survey_response where Survey_responseId = ?",[$ref->{Survey_responseId}]);
|
||||
}else{#else sent to expired but not deleted
|
||||
$self->session->db->write("update Survey_response set isComplete = 99 where Survey_responseId = ?",[$ref->{Survey_responseId}]);
|
||||
}else{
|
||||
# Mark response as expired (with appropriate completeCode)
|
||||
my $completeCode = $ref->{doAfterTimeLimit} eq 'restartSurvey' ? 4 : 3;
|
||||
$self->session->db->write("update Survey_response set isComplete = ?, endDate = ? where Survey_responseId = ?",
|
||||
[$completeCode, scalar time, $ref->{Survey_responseId}]
|
||||
);
|
||||
}
|
||||
if($self->get("emailUsers") == 1 && $ref->{email} =~ /\@/){
|
||||
|
||||
my $var = {
|
||||
to => $ref->{email},
|
||||
from => $self->get("from"),
|
||||
|
|
@ -147,6 +159,4 @@ sub execute {
|
|||
return $self->COMPLETE;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue