Ejemplo n.º 1
0
 /**
  * @param array $data
  * @return Main\Entity\AddResult
  */
 public static function send(array $data)
 {
     $manageCache = Application::getInstance()->getManagedCache();
     if (CACHED_b_event !== false && $manageCache->read(CACHED_b_event, "events")) {
         $manageCache->clean('events');
     }
     $arFiles = array();
     if (isset($data['FILE'])) {
         if (is_array($data['FILE'])) {
             $arFiles = $data['FILE'];
         }
         unset($data['FILE']);
     }
     $result = MailInternal\EventTable::add($data);
     if ($result->isSuccess()) {
         $id = $result->getId();
         foreach ($arFiles as $file) {
             $arFile = \CFile::MakeFileArray($file);
             $arFile["MODULE_ID"] = "main";
             $fid = \CFile::SaveFile($arFile, "main");
             $dataAttachment = array('EVENT_ID' => $id, 'FILE_ID' => $fid);
             MailInternal\EventAttachmentTable::add($dataAttachment);
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * @param array $data
  * @return Main\Entity\AddResult
  */
 public static function send(array $data)
 {
     $arFiles = array();
     if (isset($data['FILE'])) {
         if (is_array($data['FILE'])) {
             $arFiles = $data['FILE'];
         }
         unset($data['FILE']);
     }
     $result = MailInternal\EventTable::add($data);
     if ($result->isSuccess()) {
         $id = $result->getId();
         foreach ($arFiles as $file) {
             $arFile = \CFile::MakeFileArray($file);
             $arFile["MODULE_ID"] = "main";
             $fid = \CFile::SaveFile($arFile, "main");
             $dataAttachment = array('EVENT_ID' => $id, 'FILE_ID' => $fid);
             MailInternal\EventAttachmentTable::add($dataAttachment);
         }
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * @return string
  * @throws \Bitrix\Main\ArgumentException
  * @throws \Bitrix\Main\ArgumentNullException
  * @throws \Bitrix\Main\ArgumentTypeException
  */
 public static function executeEvents()
 {
     $manage_cache = \Bitrix\Main\Application::getInstance()->getManagedCache();
     if (defined("BX_FORK_AGENTS_AND_EVENTS_FUNCTION")) {
         if (\CMain::ForkActions(array("CEvent", "ExecuteEvents"))) {
             return "";
         }
     }
     $bulk = intval(Config\Option::get("main", "mail_event_bulk", 5));
     if ($bulk <= 0) {
         $bulk = 5;
     }
     $connection = \Bitrix\Main\Application::getConnection();
     if ($connection instanceof \Bitrix\Main\DB\MysqlCommonConnection) {
         $uniq = Config\Option::get("main", "server_uniq_id", "");
         if (strlen($uniq) <= 0) {
             $uniq = md5(uniqid(rand(), true));
             Config\Option::set("main", "server_uniq_id", $uniq);
         }
         $strSql = "SELECT 'x' FROM b_event WHERE SUCCESS_EXEC='N' LIMIT 1";
         $resultEventDb = $connection->query($strSql);
         if ($resultEventDb->fetch()) {
             $lockDb = $connection->query("SELECT GET_LOCK('" . $uniq . "_event', 0) as L");
             $arLock = $lockDb->fetch();
             if ($arLock["L"] == "0") {
                 return "";
             }
         } else {
             if (CACHED_b_event !== false) {
                 $manage_cache->set("events", true);
             }
             return "";
         }
         $strSql = "\n\t\t\t\tSELECT ID, C_FIELDS, EVENT_NAME, MESSAGE_ID, LID, DATE_FORMAT(DATE_INSERT, '%d.%m.%Y %H:%i:%s') as DATE_INSERT, DUPLICATE\n\t\t\t\tFROM b_event\n\t\t\t\tWHERE SUCCESS_EXEC='N'\n\t\t\t\tORDER BY ID\n\t\t\t\tLIMIT " . $bulk;
         $rsMails = $connection->query($strSql);
     } elseif ($connection instanceof \Bitrix\Main\DB\MssqlConnection) {
         $connection->startTransaction();
         $connection->query("SET LOCK_TIMEOUT 0");
         \CTimeZone::Disable();
         $strSql = "\n\t\t\t\tSELECT TOP " . $bulk . "\n\t\t\t\t\tID,\n\t\t\t\t\tC_FIELDS,\n\t\t\t\t\tEVENT_NAME,\n\t\t\t\t\tMESSAGE_ID,\n\t\t\t\t\tLID,\n\t\t\t\t\t" . $connection->getSqlHelper()->getDateToCharFunction("DATE_INSERT") . " as DATE_INSERT,\n\t\t\t\t\tDUPLICATE\n\t\t\t\tFROM b_event\n\t\t\t\tWITH (TABLOCKX)\n\t\t\t\tWHERE SUCCESS_EXEC = 'N'\n\t\t\t\tORDER BY ID\n\t\t\t\t";
         $rsMails = $connection->query($strSql);
         \CTimeZone::Enable();
     } elseif ($connection instanceof \Bitrix\Main\DB\OracleConnection) {
         $connection->startTransaction();
         $strSql = "\n\t\t\t\tSELECT /*+RULE*/ E.ID, E.C_FIELDS, E.EVENT_NAME, E.MESSAGE_ID, E.LID,\n\t\t\t\t\tTO_CHAR(E.DATE_INSERT, 'DD.MM.YYYY HH24:MI:SS') as DATE_INSERT, DUPLICATE\n\t\t\t\tFROM b_event E\n\t\t\t\tWHERE E.SUCCESS_EXEC='N'\n\t\t\t\tORDER BY E.ID\n\t\t\t\tFOR UPDATE NOWAIT\n\t\t\t\t";
         $rsMails = $connection->query($strSql);
     }
     if ($rsMails) {
         $arCallableModificator = array();
         $cnt = 0;
         foreach (EventTable::getFetchModificatorsForFieldsField() as $callableModificator) {
             if (is_callable($callableModificator)) {
                 $arCallableModificator[] = $callableModificator;
             }
         }
         while ($arMail = $rsMails->fetch()) {
             foreach ($arCallableModificator as $callableModificator) {
                 $arMail['C_FIELDS'] = call_user_func_array($callableModificator, array($arMail['C_FIELDS']));
             }
             $arFiles = array();
             $fileListDb = EventAttachmentTable::getList(array('select' => array('FILE_ID'), 'filter' => array('EVENT_ID' => $arMail["ID"])));
             while ($file = $fileListDb->fetch()) {
                 $arFiles[] = $file['FILE_ID'];
             }
             $arMail['FILE'] = $arFiles;
             if (!is_array($arMail['C_FIELDS'])) {
                 $arMail['C_FIELDS'] = array();
             }
             $flag = Event::handleEvent($arMail);
             EventTable::update($arMail["ID"], array('SUCCESS_EXEC' => $flag, 'DATE_EXEC' => new Type\DateTime()));
             $cnt++;
             if ($cnt >= $bulk) {
                 break;
             }
         }
     }
     if ($connection instanceof \Bitrix\Main\DB\MysqlCommonConnection) {
         $connection->query("SELECT RELEASE_LOCK('" . $uniq . "_event')");
     } elseif ($connection instanceof \Bitrix\Main\DB\MssqlConnection) {
         $connection->query("SET LOCK_TIMEOUT -1");
         $connection->commitTransaction();
     } elseif ($connection instanceof \Bitrix\Main\DB\OracleConnection) {
         $connection->commitTransaction();
     }
     if ($cnt === 0 && CACHED_b_event !== false) {
         $manage_cache->set("events", true);
     }
 }