Fix phpcs
More secured sendEmailsReminder()
This commit is contained in:
parent
9868140693
commit
ed743c9dbb
@ -1965,6 +1965,8 @@ class ActionComm extends CommonObject
|
|||||||
$error = 0;
|
$error = 0;
|
||||||
$this->output = '';
|
$this->output = '';
|
||||||
$this->error = '';
|
$this->error = '';
|
||||||
|
$nbMailSend = 0;
|
||||||
|
$errorsMsg = array();
|
||||||
|
|
||||||
if (empty($conf->agenda->enabled)) // Should not happen. If module disabled, cron job should not be visible.
|
if (empty($conf->agenda->enabled)) // Should not happen. If module disabled, cron job should not be visible.
|
||||||
{
|
{
|
||||||
@ -2005,68 +2007,68 @@ class ActionComm extends CommonObject
|
|||||||
|
|
||||||
if (!$error)
|
if (!$error)
|
||||||
{
|
{
|
||||||
//Select email template
|
//Select email template
|
||||||
$arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1);
|
$arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1);
|
||||||
|
|
||||||
// Load event
|
// Load event
|
||||||
$res = $this->fetch($actionCommReminder->fk_actioncomm);
|
$res = $this->fetch($actionCommReminder->fk_actioncomm);
|
||||||
if ($res > 0)
|
if ($res > 0)
|
||||||
{
|
{
|
||||||
// PREPARE EMAIL
|
// PREPARE EMAIL
|
||||||
|
|
||||||
// Make substitution in email content
|
// Make substitution in email content
|
||||||
$substitutionarray = getCommonSubstitutionArray($langs, 0, '', $this);
|
$substitutionarray = getCommonSubstitutionArray($langs, 0, '', $this);
|
||||||
|
|
||||||
complete_substitutions_array($substitutionarray, $langs, $this);
|
complete_substitutions_array($substitutionarray, $langs, $this);
|
||||||
|
|
||||||
// Content
|
// Content
|
||||||
$sendContent = make_substitutions($langs->trans($arraymessage->content), $substitutionarray);
|
$sendContent = make_substitutions($langs->trans($arraymessage->content), $substitutionarray);
|
||||||
|
|
||||||
//Topic
|
//Topic
|
||||||
$sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->trans('EventReminder'));
|
$sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->trans('EventReminder'));
|
||||||
|
|
||||||
// Recipient
|
// Recipient
|
||||||
$recipient = new User($this->db);
|
$recipient = new User($this->db);
|
||||||
$res = $recipient->fetch($actionCommReminder->fk_user);
|
$res = $recipient->fetch($actionCommReminder->fk_user);
|
||||||
if ($res > 0 && !empty($recipient->email)) $to = $recipient->email;
|
if ($res > 0 && !empty($recipient->email)) $to = $recipient->email;
|
||||||
else {
|
else {
|
||||||
$errorsMsg[] = "Failed to load recipient";
|
$errorsMsg[] = "Failed to load recipient";
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sender
|
// Sender
|
||||||
$from = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
$from = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
||||||
if (empty($from)) {
|
if (empty($from)) {
|
||||||
$errorsMsg[] = "Failed to load recipient";
|
$errorsMsg[] = "Failed to load recipient";
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errors Recipient
|
// Errors Recipient
|
||||||
$errors_to = $conf->global->MAIN_MAIL_ERRORS_TO;
|
$errors_to = $conf->global->MAIN_MAIL_ERRORS_TO;
|
||||||
|
|
||||||
// Mail Creation
|
// Mail Creation
|
||||||
$cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', '', '', '', '');
|
$cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', '', '', '', '');
|
||||||
|
|
||||||
// Sending Mail
|
// Sending Mail
|
||||||
if ($cMailFile->sendfile())
|
if ($cMailFile->sendfile())
|
||||||
{
|
{
|
||||||
$actionCommReminder->status = $actionCommReminder::STATUS_DONE;
|
$actionCommReminder->status = $actionCommReminder::STATUS_DONE;
|
||||||
$res = $actionCommReminder->update($user);
|
$res = $actionCommReminder->update($user);
|
||||||
if ($res < 0)
|
if ($res < 0)
|
||||||
{
|
{
|
||||||
$errorsMsg[] = "Failed to update status of ActionComm Reminder";
|
$errorsMsg[] = "Failed to update status of ActionComm Reminder";
|
||||||
$error++;
|
//$error++; Do not add error here.
|
||||||
}
|
break; // This is to avoid to have this error on all the selected email. If we fails here for one record, it may fails for others. We must solve first.
|
||||||
else $nbMailSend++;
|
} else {
|
||||||
}
|
$nbMailSend++;
|
||||||
else {
|
}
|
||||||
$errorsMsg[] = $cMailFile->error.' : '.$to;
|
} else {
|
||||||
$error++;
|
$errorsMsg[] = $cMailFile->error.' : '.$to;
|
||||||
}
|
$error++;
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -2087,12 +2089,14 @@ class ActionComm extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
|
$this->output = 'Nb of emails sent : '.$nbMailSend;
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return (!empty($errorsMsg)) ? end($errorsMsg) : $error;
|
$this->error = (!empty($errorsMsg)) ? join(', ', $errorsMsg) : $error;
|
||||||
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7977,6 +7977,7 @@ class Form
|
|||||||
*
|
*
|
||||||
* @param string $prefix Prefix
|
* @param string $prefix Prefix
|
||||||
* @param string $modelType Model type
|
* @param string $modelType Model type
|
||||||
|
* @param int $default 1=Show also Default mail template
|
||||||
* @return string HTML select string
|
* @return string HTML select string
|
||||||
*/
|
*/
|
||||||
public function selectModelMail($prefix, $modelType = '', $default = 0)
|
public function selectModelMail($prefix, $modelType = '', $default = 0)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user