This commit is contained in:
root
2025-11-13 19:52:28 +03:00
parent 8aeeb05b7d
commit 807dec3b6c
4646 changed files with 163445 additions and 626017 deletions

View File

@@ -1,16 +1,18 @@
<?php
/**
* Bitrix Framework
* @package bitrix
* @subpackage main
* @copyright 2001-2012 Bitrix
* @copyright 2001-2025 Bitrix
*/
namespace Bitrix\Main\Mail;
use Bitrix\Main;
use Bitrix\Main\Mail\Internal as MailInternal;
use Bitrix\Main\Config as Config;
use Bitrix\Main\Config;
use Bitrix\Main\Application;
use Bitrix\Main\ORM\Data\AddResult;
class Event
{
@@ -27,6 +29,11 @@ class Event
*/
public static function sendImmediate(array $data)
{
if (!static::onBeforeEventAdd($data))
{
return static::SEND_RESULT_NONE;
}
$data["ID"] = 0;
return static::handleEvent($data);
@@ -36,21 +43,28 @@ class Event
* Send mail event
*
* @param array $data Params of event
* @return Main\Entity\AddResult
* @return AddResult
*/
public static function send(array $data)
{
if (!static::onBeforeEventAdd($data))
{
return (new AddResult())->addError(new Main\Error('OnBeforeEventAdd'));
}
$manageCache = Application::getInstance()->getManagedCache();
if(CACHED_b_event !== false && $manageCache->read(CACHED_b_event, "events"))
if (CACHED_b_event !== false && $manageCache->read(CACHED_b_event, "events"))
{
$manageCache->clean('events');
}
$fileList = [];
if(isset($data['FILE']))
if (isset($data['FILE']))
{
if(is_array($data['FILE']))
if (is_array($data['FILE']))
{
$fileList = $data['FILE'];
}
unset($data['FILE']);
}
@@ -79,7 +93,7 @@ class Event
$connection->startTransaction();
$result = MailInternal\EventTable::add($data);
$result = Internal\EventTable::add($data);
if ($result->isSuccess())
{
@@ -98,7 +112,7 @@ class Event
$attachment['FILE_ID'] = \CFile::SaveFile($file['FILE'], 'main');
}
MailInternal\EventAttachmentTable::add($attachment);
Internal\EventAttachmentTable::add($attachment);
}
}
@@ -107,38 +121,76 @@ class Event
return $result;
}
protected static function onBeforeEventAdd(array &$data): bool
{
foreach (GetModuleEvents("main", "OnBeforeEventAdd", true) as $arEvent)
{
if (ExecuteModuleEventEx($arEvent, [&$data["EVENT_NAME"], &$data["LID"], &$data["C_FIELDS"], &$data["MESSAGE_ID"], &$data["FILE"], &$data["LANGUAGE_ID"]]) === false)
{
return false;
}
}
if (isset($data['LID']) && is_array($data['LID']))
{
$data['LID'] = implode(",", $data['LID']);
}
if (!is_array($data["C_FIELDS"] ?? null))
{
$data["C_FIELDS"] = [];
}
if (isset($data["MESSAGE_ID"]) && (int)$data["MESSAGE_ID"] > 0)
{
$data["MESSAGE_ID"] = (int)$data["MESSAGE_ID"];
}
else
{
unset($data["MESSAGE_ID"]);
}
return true;
}
/**
* @param array $arEvent
* @return string
* @throws Main\ArgumentException
* @throws Main\ArgumentNullException
* @throws Main\ArgumentTypeException
*/
public static function handleEvent(array $arEvent)
{
if(!isset($arEvent['FIELDS']) && isset($arEvent['C_FIELDS']))
if (!isset($arEvent['FIELDS']) && isset($arEvent['C_FIELDS']))
{
$arEvent['FIELDS'] = $arEvent['C_FIELDS'];
}
if(!is_array($arEvent['FIELDS']))
throw new Main\ArgumentTypeException("FIELDS" );
if (!is_array($arEvent['FIELDS']))
{
throw new Main\ArgumentTypeException("FIELDS");
}
$flag = static::SEND_RESULT_TEMPLATE_NOT_FOUND; // no templates
$arResult = array(
$arResult = [
"Success" => false,
"Fail" => false,
"Was" => false,
"Skip" => false,
);
];
$trackRead = null;
$trackClick = null;
if(array_key_exists('TRACK_READ', $arEvent))
if (array_key_exists('TRACK_READ', $arEvent))
{
$trackRead = $arEvent['TRACK_READ'];
if(array_key_exists('TRACK_CLICK', $arEvent))
}
if (array_key_exists('TRACK_CLICK', $arEvent))
{
$trackClick = $arEvent['TRACK_CLICK'];
}
$arSites = explode(",", $arEvent["LID"]);
if(empty($arSites))
if (empty($arSites))
{
return $flag;
}
@@ -148,76 +200,76 @@ class Event
$charset = false;
$serverName = null;
static $sites = array();
static $sites = [];
$infoSite = reset($arSites);
if(!isset($sites[$infoSite]))
if (!isset($sites[$infoSite]))
{
$siteDb = Main\SiteTable::getList(array(
'select' => array('SERVER_NAME', 'CULTURE_CHARSET'=>'CULTURE.CHARSET'),
'filter' => array('=LID' => $infoSite)
));
$siteDb = Main\SiteTable::getList([
'select' => ['SERVER_NAME', 'CULTURE_CHARSET' => 'CULTURE.CHARSET'],
'filter' => ['=LID' => $infoSite],
]);
$sites[$infoSite] = $siteDb->fetch();
}
if(is_array($sites[$infoSite]))
if (is_array($sites[$infoSite]))
{
$charset = $sites[$infoSite]['CULTURE_CHARSET'];
$serverName = $sites[$infoSite]['SERVER_NAME'];
}
if(!$charset)
if (!$charset)
{
return $flag;
}
// get filter for list of message templates
$arEventMessageFilter = array();
$MESSAGE_ID = intval($arEvent["MESSAGE_ID"]);
if($MESSAGE_ID > 0)
$arEventMessageFilter = [];
$MESSAGE_ID = intval($arEvent["MESSAGE_ID"] ?? 0);
if ($MESSAGE_ID > 0)
{
$eventMessageDb = MailInternal\EventMessageTable::getById($MESSAGE_ID);
if($eventMessageDb->Fetch())
$eventMessageDb = Internal\EventMessageTable::getById($MESSAGE_ID);
if ($eventMessageDb->Fetch())
{
$arEventMessageFilter['=ID'] = $MESSAGE_ID;
$arEventMessageFilter['=ACTIVE'] = 'Y';
}
}
if(empty($arEventMessageFilter))
if (empty($arEventMessageFilter))
{
$arEventMessageFilter = array(
$arEventMessageFilter = [
'=ACTIVE' => 'Y',
'=EVENT_NAME' => $arEvent["EVENT_NAME"],
'=EVENT_MESSAGE_SITE.SITE_ID' => $arSites,
);
];
if($arEvent["LANGUAGE_ID"] <> '')
if ($arEvent["LANGUAGE_ID"] <> '')
{
$arEventMessageFilter[] = array(
$arEventMessageFilter[] = [
"LOGIC" => "OR",
array("=LANGUAGE_ID" => $arEvent["LANGUAGE_ID"]),
array("=LANGUAGE_ID" => null),
);
["=LANGUAGE_ID" => $arEvent["LANGUAGE_ID"]],
["=LANGUAGE_ID" => null],
];
}
}
// get list of message templates of event
$messageDb = MailInternal\EventMessageTable::getList(array(
'select' => array('ID'),
$messageDb = Internal\EventMessageTable::getList([
'select' => ['ID'],
'filter' => $arEventMessageFilter,
'group' => array('ID')
));
'group' => ['ID'],
]);
while($arMessage = $messageDb->fetch())
while ($arMessage = $messageDb->fetch())
{
$eventMessage = MailInternal\EventMessageTable::getRowById($arMessage['ID']);
$eventMessage = Internal\EventMessageTable::getRowById($arMessage['ID']);
$eventMessage['FILE'] = array();
$attachmentDb = MailInternal\EventMessageAttachmentTable::getList(array(
'select' => array('FILE_ID'),
'filter' => array('=EVENT_MESSAGE_ID' => $arMessage['ID']),
));
while($arAttachmentDb = $attachmentDb->fetch())
$eventMessage['FILE'] = [];
$attachmentDb = Internal\EventMessageAttachmentTable::getList([
'select' => ['FILE_ID'],
'filter' => ['=EVENT_MESSAGE_ID' => $arMessage['ID']],
]);
while ($arAttachmentDb = $attachmentDb->fetch())
{
$eventMessage['FILE'][] = $arAttachmentDb['FILE_ID'];
}
@@ -227,26 +279,26 @@ class Event
foreach (GetModuleEvents("main", "OnBeforeEventSend", true) as $event)
{
if(ExecuteModuleEventEx($event, array(&$arFields, &$eventMessage, $context, &$arResult)) === false)
if (ExecuteModuleEventEx($event, [&$arFields, &$eventMessage, $context, &$arResult]) === false)
{
continue 2;
}
}
// get message object for send mail
$arMessageParams = array(
$arMessageParams = [
'EVENT' => $arEvent,
'FIELDS' => $arFields,
'MESSAGE' => $eventMessage,
'SITE' => $arSites,
'CHARSET' => $charset,
);
];
$message = EventMessageCompiler::createInstance($arMessageParams);
try
{
$message->compile();
}
catch(StopException $e)
catch (StopException)
{
$arResult["Was"] = true;
$arResult["Fail"] = true;
@@ -254,7 +306,7 @@ class Event
}
// send mail
$result = Main\Mail\Mail::send(array(
$result = Main\Mail\Mail::send([
'TO' => $message->getMailTo(),
'SUBJECT' => $message->getMailSubject(),
'BODY' => $message->getMailBody(),
@@ -265,36 +317,50 @@ class Event
'ATTACHMENT' => $message->getMailAttachment(),
'TRACK_READ' => $trackRead,
'TRACK_CLICK' => $trackClick,
'LINK_PROTOCOL' => Config\Option::get("main", "mail_link_protocol", ''),
'LINK_PROTOCOL' => Config\Option::get("main", "mail_link_protocol"),
'LINK_DOMAIN' => $serverName,
'CONTEXT' => $context,
));
if($result)
]);
if ($result)
{
$arResult["Success"] = true;
}
else
{
$arResult["Fail"] = true;
}
$arResult["Was"] = true;
}
if($arResult["Was"])
if ($arResult["Was"])
{
if($arResult["Success"])
if ($arResult["Success"])
{
if($arResult["Fail"])
$flag = static::SEND_RESULT_PARTLY; // partly sent
if ($arResult["Fail"])
{
// partly sent
$flag = static::SEND_RESULT_PARTLY;
}
else
$flag = static::SEND_RESULT_SUCCESS; // all sent
{
// all sent
$flag = static::SEND_RESULT_SUCCESS;
}
}
else
{
if($arResult["Fail"])
$flag = static::SEND_RESULT_ERROR; // all templates failed
if ($arResult["Fail"])
{
// all templates failed
$flag = static::SEND_RESULT_ERROR;
}
}
}
elseif($arResult["Skip"])
elseif ($arResult["Skip"])
{
$flag = static::SEND_RESULT_NONE; // skip this event
// skip this event
$flag = static::SEND_RESULT_NONE;
}
return $flag;

View File

@@ -3,8 +3,8 @@
namespace Bitrix\Main\Mail\Internal;
use Bitrix\Main\Application;
use Bitrix\Main\Entity;
use Bitrix\Main\Type\DateTime;
use Bitrix\Main\ORM\Data\DataManager;
/**
* Class BlacklistTable
@@ -24,7 +24,7 @@ use Bitrix\Main\Type\DateTime;
* @method static \Bitrix\Main\Mail\Internal\EO_Blacklist wakeUpObject($row)
* @method static \Bitrix\Main\Mail\Internal\EO_Blacklist_Collection wakeUpCollection($rows)
*/
class BlacklistTable extends Entity\DataManager
class BlacklistTable extends DataManager
{
const CategoryAuto = 0;
const CategoryManual = 1;

View File

@@ -1,15 +1,18 @@
<?php
/**
* Bitrix Framework
* @package bitrix
* @subpackage main
* @copyright 2001-2012 Bitrix
* @copyright 2001-2025 Bitrix
*/
namespace Bitrix\Main\Mail\Internal;
use Bitrix\Main\Entity;
use Bitrix\Main\ORM\Fields\ArrayField;
use Bitrix\Main\Type as Type;
use Bitrix\Main\ORM\Data\DataManager;
use Bitrix\Main\ORM\Fields\StringField;
/**
* Class EventTable
@@ -27,7 +30,7 @@ use Bitrix\Main\Type as Type;
* @method static \Bitrix\Main\Mail\Internal\EO_Event wakeUpObject($row)
* @method static \Bitrix\Main\Mail\Internal\EO_Event_Collection wakeUpCollection($rows)
*/
class EventTable extends Entity\DataManager
class EventTable extends DataManager
{
/**
* @return string
@@ -107,7 +110,7 @@ class EventTable extends Entity\DataManager
{
return array(
array(__CLASS__, "getFetchModificationForFieldsField"),
array(new Entity\StringField('FIELDS', array()), "unserialize")
array(new StringField('FIELDS', array()), "unserialize")
);
}
@@ -198,7 +201,7 @@ class EventTable extends Entity\DataManager
$newar[$key] = $val;
}
$field = new Entity\StringField('FIELDS', array());
$field = new StringField('FIELDS', array());
return $field->serialize($newar);
}
}

View File

@@ -3,12 +3,12 @@
* Bitrix Framework
* @package bitrix
* @subpackage main
* @copyright 2001-2012 Bitrix
* @copyright 2001-2025 Bitrix
*/
namespace Bitrix\Main\Mail\Internal;
use Bitrix\Main\Entity;
use Bitrix\Main\ORM\Data\DataManager;
/**
* Class EventAttachmentTable
@@ -26,7 +26,7 @@ use Bitrix\Main\Entity;
* @method static \Bitrix\Main\Mail\Internal\EO_EventAttachment wakeUpObject($row)
* @method static \Bitrix\Main\Mail\Internal\EO_EventAttachment_Collection wakeUpCollection($rows)
*/
class EventAttachmentTable extends Entity\DataManager
class EventAttachmentTable extends DataManager
{
/**

View File

@@ -1,16 +1,18 @@
<?php
/**
* Bitrix Framework
* @package bitrix
* @subpackage main
* @copyright 2001-2012 Bitrix
* @copyright 2001-2025 Bitrix
*/
namespace Bitrix\Main\Mail\Internal;
use Bitrix\Main\Orm;
use Bitrix\Main\Entity;
use Bitrix\Main\Type as Type;
use Bitrix\Main\Type;
use Bitrix\Main\ORM;
use Bitrix\Main\ORM\Data\DataManager;
use Bitrix\Main\ORM\Fields\ArrayField;
/**
* Class EventMessageTable
@@ -28,7 +30,7 @@ use Bitrix\Main\Type as Type;
* @method static \Bitrix\Main\Mail\Internal\EO_EventMessage wakeUpObject($row)
* @method static \Bitrix\Main\Mail\Internal\EO_EventMessage_Collection wakeUpCollection($rows)
*/
class EventMessageTable extends Entity\DataManager
class EventMessageTable extends DataManager
{
/**
* @return string
@@ -52,7 +54,9 @@ class EventMessageTable extends Entity\DataManager
'TIMESTAMP_X' => array(
'data_type' => 'datetime',
'required' => true,
'default_value' => function(){return new Type\DateTime();},
'default_value' => function() {
return new Type\DateTime();
},
),
'EVENT_NAME' => array(
'data_type' => 'string',
@@ -120,7 +124,7 @@ class EventMessageTable extends Entity\DataManager
'SITE_TEMPLATE_ID' => array(
'data_type' => 'string',
),
(new Orm\Fields\ArrayField('ADDITIONAL_FIELD'))->configureSerializationPhp(),
(new ArrayField('ADDITIONAL_FIELD'))->configureSerializationPhp(),
'EVENT_MESSAGE_SITE' => array(
'data_type' => 'Bitrix\Main\Mail\Internal\EventMessageSite',
'reference' => array('=this.ID' => 'ref.EVENT_MESSAGE_ID'),
@@ -217,19 +221,19 @@ class EventMessageTable extends Entity\DataManager
if(!empty($arReplaceTagsOne))
$strResult = str_replace(array_keys($arReplaceTagsOne), array_values($arReplaceTagsOne), $strResult);
// php parser delete newline folowing the closing tag in string passed to eval
// php parser delete newline following the closing tag in string passed to eval
$strResult = str_replace(array("?>\n", "?>\r\n"), array("?>\n\n", "?>\r\n\r\n"), $strResult);
return $strResult;
}
/**
* @param Entity\Event $event
* @return Entity\EventResult
* @param ORM\Event $event
* @return ORM\EventResult
*/
public static function onBeforeUpdate(Entity\Event $event)
public static function onBeforeUpdate(ORM\Event $event)
{
$result = new Entity\EventResult;
$result = new ORM\EventResult();
$data = $event->getParameters();
if(array_key_exists('MESSAGE', $data['fields']))
@@ -242,12 +246,12 @@ class EventMessageTable extends Entity\DataManager
}
/**
* @param Entity\Event $event
* @return Entity\EventResult
* @param ORM\Event $event
* @return ORM\EventResult
*/
public static function onBeforeAdd(Entity\Event $event)
public static function onBeforeAdd(ORM\Event $event)
{
$result = new Entity\EventResult;
$result = new ORM\EventResult();
$data = $event->getParameters();
if(array_key_exists('MESSAGE', $data['fields']))

View File

@@ -1,4 +1,5 @@
<?php
/**
* Bitrix Framework
* @package bitrix
@@ -8,7 +9,7 @@
namespace Bitrix\Main\Mail\Internal;
use Bitrix\Main\Entity;
use Bitrix\Main\ORM\Data\DataManager;
/**
* Class EventMessageAttachmentTable
@@ -26,7 +27,7 @@ use Bitrix\Main\Entity;
* @method static \Bitrix\Main\Mail\Internal\EO_EventMessageAttachment wakeUpObject($row)
* @method static \Bitrix\Main\Mail\Internal\EO_EventMessageAttachment_Collection wakeUpCollection($rows)
*/
class EventMessageAttachmentTable extends Entity\DataManager
class EventMessageAttachmentTable extends DataManager
{
/**
* @return string
@@ -53,5 +54,4 @@ class EventMessageAttachmentTable extends Entity\DataManager
),
);
}
}

View File

@@ -7,7 +7,7 @@
*/
namespace Bitrix\Main\Mail\Internal;
use Bitrix\Main\Entity;
use Bitrix\Main\ORM\Data\DataManager;
/**
* Class SenderSendCounterTable
@@ -25,7 +25,7 @@ use Bitrix\Main\Entity;
* @method static \Bitrix\Main\Mail\Internal\EO_SenderSendCounter wakeUpObject($row)
* @method static \Bitrix\Main\Mail\Internal\EO_SenderSendCounter_Collection wakeUpCollection($rows)
*/
class SenderSendCounterTable extends Entity\DataManager
class SenderSendCounterTable extends DataManager
{
public static function getTableName()
{

View File

@@ -2,11 +2,11 @@
namespace Bitrix\Main\Mail\Internal;
use Bitrix\Main\Entity;
use Bitrix\Main\Config;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Security;
use Bitrix\Main\ORM\Fields;
use Bitrix\Main\ORM\Data\DataManager;
/**
* Class SenderTable
@@ -25,9 +25,8 @@ use Bitrix\Main\ORM\Fields;
* @method static \Bitrix\Main\Mail\Internal\Sender wakeUpObject($row)
* @method static \Bitrix\Main\Mail\Internal\EO_Sender_Collection wakeUpCollection($rows)
*/
class SenderTable extends Entity\DataManager
class SenderTable extends DataManager
{
public static function getTableName()
{
return 'b_main_mail_sender';
@@ -42,7 +41,6 @@ class SenderTable extends Entity\DataManager
return $result;
}
public static function getObjectClass()
{
return Sender::class;
@@ -163,5 +161,4 @@ class SenderTable extends Entity\DataManager
->configureNullable(),
];
}
}

View File

@@ -9,6 +9,8 @@
namespace Bitrix\Main\Mail;
use Bitrix\Main\Type;
use Bitrix\Main\ORM\Fields\ExpressionField;
use Bitrix\Main\DB\SqlExpression;
class SenderSendCounter
{
@@ -50,9 +52,9 @@ class SenderSendCounter
$counter = 0;
$date = new Type\Date(date("01.m.Y"), "d.m.Y");
$res = Internals\SenderSendCounterTable::getList(array(
$res = Internal\SenderSendCounterTable::getList(array(
"select" => array(
new \Bitrix\Main\Entity\ExpressionField('CNT', 'SUM(CNT)'),
new ExpressionField('CNT', 'SUM(CNT)'),
),
"filter" => array(
">=DATE_STAT" => $date,
@@ -80,7 +82,7 @@ class SenderSendCounter
"CNT" => $increment,
);
$update = array(
"CNT" => new \Bitrix\Main\DB\SqlExpression("?# + ?i", "CNT", $increment),
"CNT" => new SqlExpression("?# + ?i", "CNT", $increment),
);
Internal\SenderSendCounterTable::mergeData($insert, $update);