/** * @param $mailingChainId * @return string */ public static function chainSend($mailingChainId) { static::$error = null; $mailingChainPrimary = array('ID' => $mailingChainId); $mailingChainDb = MailingChainTable::getById($mailingChainPrimary); $arMailingChain = $mailingChainDb->fetch(); if ($arMailingChain && $arMailingChain['STATUS'] == MailingChainTable::STATUS_SEND) { if (\COption::GetOptionString("sender", "auto_method") === 'cron') { $maxMailCount = 0; $timeout = 0; } else { $maxMailCount = \COption::GetOptionInt("sender", "max_emails_per_hit"); $timeout = \COption::GetOptionInt("sender", "interval"); } try { $postingSendStatus = PostingManager::send($arMailingChain['POSTING_ID'], $timeout, $maxMailCount); } catch (Exception $e) { static::$error = $e; } if (empty(static::$error) && $postingSendStatus !== PostingManager::SEND_RESULT_CONTINUE) { if ($arMailingChain['REITERATE'] == 'Y') { MailingChainTable::update($mailingChainPrimary, array('POSTING_ID' => null, 'STATUS' => MailingChainTable::STATUS_WAIT, 'AUTO_SEND_TIME' => null)); } else { MailingChainTable::update($mailingChainPrimary, array('STATUS' => MailingChainTable::STATUS_END)); } } else { return static::getAgentName($mailingChainId); } } return ""; }
/** * @param $mailingChainId * @return string */ public static function chainSend($mailingChainId) { static::$error = null; $mailingChainPrimary = array('ID' => $mailingChainId); $mailingChainDb = MailingChainTable::getById($mailingChainPrimary); $mailingChain = $mailingChainDb->fetch(); if ($mailingChain && $mailingChain['STATUS'] == MailingChainTable::STATUS_SEND) { if (\COption::GetOptionString("sender", "auto_method") === 'cron') { $maxMailCount = 0; $timeout = 0; } else { $maxMailCount = \COption::GetOptionInt("sender", "max_emails_per_hit"); $timeout = \COption::GetOptionInt("sender", "interval"); } $postingSendStatus = ''; if (!empty($mailingChain['POSTING_ID'])) { try { $postingSendStatus = PostingManager::send($mailingChain['POSTING_ID'], $timeout, $maxMailCount); } catch (Exception $e) { static::$error = $e; $postingSendStatus = PostingManager::SEND_RESULT_ERROR; } } if (empty(static::$error) && $postingSendStatus !== PostingManager::SEND_RESULT_CONTINUE) { if ($mailingChain['REITERATE'] == 'Y') { $mailingChainFields = array('STATUS' => MailingChainTable::STATUS_WAIT, 'AUTO_SEND_TIME' => null, 'POSTING_ID' => null); if ($mailingChain['IS_TRIGGER'] == 'Y') { $postingDb = PostingTable::getList(array('select' => array('ID', 'DATE_CREATE'), 'filter' => array('STATUS' => PostingTable::STATUS_NEW, 'MAILING_CHAIN_ID' => $mailingChain['ID']), 'order' => array('DATE_CREATE' => 'ASC'), 'limit' => 1)); if ($posting = $postingDb->fetch()) { $mailingChainFields['AUTO_SEND_TIME'] = $posting['DATE_CREATE']->add($mailingChain['TIME_SHIFT'] . ' minutes'); $mailingChainFields['STATUS'] = MailingChainTable::STATUS_SEND; $mailingChainFields['POSTING_ID'] = $posting['ID']; } } MailingChainTable::update($mailingChainPrimary, $mailingChainFields); $eventData = array('MAILING_CHAIN' => $mailingChain); $event = new \Bitrix\Main\Event('sender', 'OnAfterMailingChainSend', array($eventData)); $event->send(); } else { MailingChainTable::update($mailingChainPrimary, array('STATUS' => MailingChainTable::STATUS_END)); } } else { return static::getAgentName($mailingChainId); } } return ""; }