Skip to content

Commit

Permalink
Fixed issue: Skipping on invitation/reminder sendout
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Nov 12, 2019
1 parent ef83d05 commit b42332f
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions application/controllers/admin/tokens.php
Expand Up @@ -1291,7 +1291,7 @@ public function email($iSurveyId)

$aTokenIds = $this->getTokenIds();
$sSubAction = $this->getSubAction();
$bEmail = $sSubAction == 'invite';
$bIsInvitation = $sSubAction == 'invite';

Yii::app()->loadHelper('surveytranslator');
Yii::app()->loadHelper('/admin/htmleditor');
Expand All @@ -1315,7 +1315,7 @@ public function email($iSurveyId)
}
$aData['surveyid'] = $iSurveyId;
$aData['sSubAction'] = $sSubAction;
$aData['bEmail'] = $bEmail;
$aData['bEmail'] = $bIsInvitation;
$aData['aSurveyLangs'] = $aData['surveylangs'] = $aSurveyLangs;
$aData['baselang'] = $sBaseLanguage;
$aData['tokenfields'] = array_keys($aTokenFields);
Expand All @@ -1332,12 +1332,12 @@ public function email($iSurveyId)
} else {
$SQLemailstatuscondition = $this->getSQLemailstatuscondition();
$SQLremindercountcondition = $this->getSQLremindercountcondition();
$SQLreminderdelaycondition = $this->getSQLreminderdelaycondition($bEmail);
$SQLreminderdelaycondition = $this->getSQLreminderdelaycondition($bIsInvitation);

$ctresult = TokenDynamic::model($iSurveyId)->findUninvitedIDs($aTokenIds, 0, $bEmail, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition);
$ctresult = TokenDynamic::model($iSurveyId)->findUninvitedIDs($aTokenIds, 0, $bIsInvitation, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition);
$ctcount = count($ctresult);

$emresult = TokenDynamic::model($iSurveyId)->findUninvited($aTokenIds, $iMaxEmails, $bEmail, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition);
$emresult = TokenDynamic::model($iSurveyId)->findUninvited($aTokenIds, $iMaxEmails, $bIsInvitation, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition);
$emcount = count($emresult);

foreach ($aSurveyLangs as $language) {
Expand All @@ -1353,10 +1353,10 @@ public function email($iSurveyId)
$bSendError = false;
if ($emcount > 0) {
foreach ($emresult as $emrow) {
if ($this->tokenIsSetInEmailCache($iSurveyId, $emrow['tid'])) {
if ($this->tokenIsSetInEmailCache($iSurveyId, $emrow['tid'],$bIsInvitation)) {
// The email has already been send this session, skip.
// Happens if user reloads page or double clicks on "Send".
if ($bEmail) {
if ($bIsInvitation) {
$tokenoutput .= sprintf(gT("Invitation %s skipped, already sent."), $emrow['tid']) . "<br/>";
} else {
$tokenoutput .= sprintf(gT("Reminder %s skipped, already sent."), $emrow['tid']) . "<br/>";
Expand Down Expand Up @@ -1481,7 +1481,7 @@ public function email($iSurveyId)
if ($success) {
// Put date into sent
$token = Token::model($iSurveyId)->findByPk($emrow['tid']);
if ($bEmail) {
if ($bIsInvitation) {
$tokenoutput .= gT("Invitation sent to:");
$token->sent = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
} else {
Expand All @@ -1493,9 +1493,10 @@ public function email($iSurveyId)

// Mark token email as send this session.
// NB: This cache is cleared on form page for invitation/reminder.
$_SESSION[$this->getEmailCacheName($iSurveyId)][$emrow['tid']] = 1;
$sType = $bIsInvitation?'i':'r';
$_SESSION[$this->getEmailCacheName($iSurveyId)][$sType][$emrow['tid']] = 1;

//Update central participant survey_links
//Update central participant survey_links
if (!empty($emrow['participant_id'])) {
$slquery = SurveyLink::model()->find('participant_id = :pid AND survey_id = :sid AND token_id = :tid', array(':pid' => $emrow['participant_id'], ':sid' => $iSurveyId, ':tid' => $emrow['tid']));
if (!is_null($slquery)) {
Expand Down Expand Up @@ -2757,13 +2758,15 @@ protected function getEmailCacheName($iSurveyId)
* Being set means the email has already been send.
* @param int $iSurveyId
* @param string $token
* $return boolean
* @param boolean $bIsInvitation
* $return boolean
*/
protected function tokenIsSetInEmailCache($iSurveyId, $tid)
protected function tokenIsSetInEmailCache($iSurveyId, $tid, $bIsInvitation)
{
$sType = $bIsInvitation?'i':'r';
$cacheName = $this->getEmailCacheName($iSurveyId);
return isset($_SESSION[$cacheName])
&& isset($_SESSION[$cacheName][$tid])
&& $_SESSION[$cacheName][$tid] > 0;
&& isset($_SESSION[$cacheName][$sType][$tid])
&& $_SESSION[$cacheName][$sType][$tid] > 0;
}
}

0 comments on commit b42332f

Please sign in to comment.