mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°7082 Ability to forcefully send e-mails asynchronously (#501)
Will be usefull in use cases like sending mass emails in customer-survey
This commit is contained in:
@@ -304,22 +304,53 @@ class EMailLaminas extends Email
|
||||
return $aImagesParts;
|
||||
}
|
||||
|
||||
public function Send(&$aIssues, $bForceSynchronous = false, $oLog = null)
|
||||
/**
|
||||
* Sends an e-mail.
|
||||
*
|
||||
* @param string[] $aIssues Array to add any potentially encountered issues to.
|
||||
* @param int|bool $iSyncAsync Specify whether the e-mail will be sent per default configuration, or whether there will be a forced (a)synchronous sending. One of Email::ENUM_SEND_* constants. To support legacy, it also allows a boolean (true = send synchronous).
|
||||
* @param Object|null $oLog Log
|
||||
*
|
||||
* @details By default, the send method will respect the preference to send e-mails in an (a)synchronous way as defined in the iTop configuration by the administrator.
|
||||
* In some use cases, it may be necessary to override this behavior. For example, for some tests it may be best if e-mails are always sent instantly (synchronous).
|
||||
* Asynchronous may be preferred when sending a lot of bulk e-mails at once, to avoid hitting rate limits of e-mail providers (e.g. customer survey extension).
|
||||
*
|
||||
* @since 3.2.0 Previously, $iSyncAsync was a boolean ($bForceSynchronous) and this method only allowed to forcefully send e-mails synchronously even when the default was asynchronous.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public function Send(&$aIssues, $iSyncAsync = Email::ENUM_SEND_DEFAULT, $oLog = null)
|
||||
{
|
||||
//select a default sender if none is provided.
|
||||
if (empty($this->m_aData['from']['address']) && !empty($this->m_aData['to'])) {
|
||||
$this->SetRecipientFrom($this->m_aData['to']);
|
||||
}
|
||||
|
||||
if ($bForceSynchronous) {
|
||||
// In previous iTop versions, $iSyncAsync was $bForceSynchronous. To retain backward compatibility, this check is in place.
|
||||
if($iSyncAsync === true) {
|
||||
// This legacy mode forces synchronous sending, ignoring whatever default was configured.
|
||||
return $this->SendSynchronous($aIssues, $oLog);
|
||||
} else {
|
||||
$oConfig = $this->LoadConfig();
|
||||
$bConfigASYNC = $oConfig->Get('email_asynchronous');
|
||||
if ($bConfigASYNC) {
|
||||
return $this->SendAsynchronous($aIssues, $oLog);
|
||||
} else {
|
||||
return $this->SendSynchronous($aIssues, $oLog);
|
||||
|
||||
switch($iSyncAsync) {
|
||||
|
||||
case Email::ENUM_SEND_FORCE_SYNCHRONOUS:
|
||||
return $this->SendSynchronous($aIssues, $oLog);
|
||||
|
||||
case Email::ENUM_SEND_FORCE_ASYNCHRONOUS:
|
||||
return $this->SendAsynchronous($aIssues, $oLog);
|
||||
|
||||
case Email::ENUM_SEND_DEFAULT:
|
||||
default:
|
||||
|
||||
// Default behavior.
|
||||
$oConfig = $this->LoadConfig();
|
||||
$bConfigASYNC = $oConfig->Get('email_asynchronous');
|
||||
if($bConfigASYNC) {
|
||||
return $this->SendAsynchronous($aIssues, $oLog);
|
||||
} else {
|
||||
return $this->SendSynchronous($aIssues, $oLog);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user