Exemple #1
0
 /**
  * @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 "";
 }
$sTableID = "tbl_sender_mailing_chain";
$MAILING_ID = intval($_REQUEST["MAILING_ID"]);
$ID = intval($_REQUEST["ID"]);
if ($_REQUEST["action"] == "send_to_me" && check_bitrix_sessid() && $POST_RIGHT >= "W") {
    require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_js.php";
    $adminMessage = new CAdminMessage('');
    $sendToMeAddr = $_POST["send_to_me_addr"];
    $sendToMeAddr = explode(",", $sendToMeAddr);
    $arResult = array();
    $mailingChain = MailingChainTable::getRowById(array('ID' => $ID));
    if ($mailingChain) {
        try {
            foreach ($sendToMeAddr as $address) {
                $address = trim($address);
                if (!empty($address)) {
                    $sendResult = \Bitrix\Sender\PostingManager::sendToAddress($mailingChain['ID'], $address);
                    if ($sendResult == \Bitrix\Sender\PostingManager::SEND_RESULT_SENT) {
                        $arResult[] = $address;
                        MailingChainTable::setEmailToMeList($address);
                    }
                }
            }
            if (!empty($arResult)) {
                $adminMessage->ShowNote(GetMessage("sender_mailing_chain_adm_test_send_success") . implode(', ', $arResult));
            } else {
                $adminMessage->ShowMessage(GetMessage("sender_mailing_chain_adm_test_send_empty"));
            }
        } catch (Exception $e) {
            $adminMessage->ShowMessage($e->getMessage());
        }
    } else {
 /**
  * @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 "";
 }