only update last_msg_date if a message is really sent.

This commit is contained in:
Thomas Negre 2022-02-07 17:38:32 +01:00
parent 26648e4f12
commit b6b5eb633b
2 changed files with 16 additions and 10 deletions

View File

@ -280,9 +280,11 @@ class InterfaceTicketEmail extends DolibarrTriggers
dol_syslog($mailfile->error, LOG_DEBUG);
} else {
$result = $mailfile->sendfile();
// update last_msg_sent date
$object->date_last_msg_sent = dol_now();
$object->update($user);
if ($result) {
// update last_msg_sent date
$object->date_last_msg_sent = dol_now();
$object->update($user);
}
}
if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
$conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;

View File

@ -2756,13 +2756,14 @@ class Ticket extends CommonObject
// altairis: dont try to send email when no recipient
if (!empty($sendto)) {
$this->sendTicketMessageByEmail($subject, $message, '', $sendto, $listofpaths, $listofmimes, $listofnames);
$result = $this->sendTicketMessageByEmail($subject, $message, '', $sendto, $listofpaths, $listofmimes, $listofnames);
if ($result) {
// update last_msg_sent date
$object->date_last_msg_sent = dol_now();
$object->update($user);
}
}
}
// update last_msg_sent date
$object->date_last_msg_sent = dol_now();
$object->update($user);
}
}
}
@ -2793,7 +2794,7 @@ class Ticket extends CommonObject
* @param array $filename_list List of files to attach (full path of filename on file system)
* @param array $mimetype_list List of MIME type of attached files
* @param array $mimefilename_list List of attached file name in message
* @return void
* @return boolean True if mail sent to at least one receiver, false otherwise
*/
public function sendTicketMessageByEmail($subject, $message, $send_internal_cc = 0, $array_receiver = array(), $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
{
@ -2801,7 +2802,7 @@ class Ticket extends CommonObject
if ($conf->global->TICKET_DISABLE_ALL_MAILS) {
dol_syslog(get_class($this).'::sendTicketMessageByEmail: Emails are disable into ticket setup by option TICKET_DISABLE_ALL_MAILS', LOG_WARNING);
return '';
return false;
}
$langs->load("mails");
@ -2820,6 +2821,7 @@ class Ticket extends CommonObject
}
$from = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
$is_sent = false;
if (is_array($array_receiver) && count($array_receiver) > 0) {
foreach ($array_receiver as $key => $receiver) {
$deliveryreceipt = 0;
@ -2841,6 +2843,7 @@ class Ticket extends CommonObject
$result = $mailfile->sendfile();
if ($result) {
setEventMessages($langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($receiver, 2)), null, 'mesgs');
$is_sent = true;
} else {
$langs->load("other");
if ($mailfile->error) {
@ -2859,6 +2862,7 @@ class Ticket extends CommonObject
$langs->load("other");
setEventMessages($langs->trans('ErrorMailRecipientIsEmptyForSendTicketMessage'), null, 'warnings');
}
return $is_sent;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps