20 (defined(
"DisableEventsCheck") && DisableEventsCheck ===
true)
23 defined(
"BX_CRONTAB_SUPPORT") && BX_CRONTAB_SUPPORT ===
true
25 (!defined(
"BX_CRONTAB") || BX_CRONTAB !==
true)
32 $manage_cache = Main\Application::getInstance()->getManagedCache();
33 if(CACHED_b_event !==
false && $manage_cache->read(CACHED_b_event,
"events"))
36 return static::executeEvents();
46 $manage_cache = Main\Application::getInstance()->getManagedCache();
48 $bulk = intval(Main\
Config\Option::get(
"main",
"mail_event_bulk", 5));
54 $connection = Main\Application::getConnection();
55 $helper = $connection->getSqlHelper();
57 $strSql=
"SELECT 'x' FROM b_event WHERE SUCCESS_EXEC='N' LIMIT 1";
58 $resultEventDb = $connection->query($strSql);
59 if($resultEventDb->fetch())
61 if(!$connection->lock(
'event'))
66 if(CACHED_b_event!==
false)
67 $manage_cache->set(
"events",
true);
73 SELECT ID, C_FIELDS, EVENT_NAME, MESSAGE_ID, LID,
74 " . $helper->formatDate(
'DD.MM.YYYY HH24:MI:SS',
'DATE_INSERT') .
" as DATE_INSERT,
75 DUPLICATE, LANGUAGE_ID
77 WHERE SUCCESS_EXEC='N'
81 $rsMails = $connection->query($strSql);
85 $arCallableModificator = array();
87 foreach(Internal\EventTable::getFetchModificatorsForFieldsField() as $callableModificator)
89 if(is_callable($callableModificator))
91 $arCallableModificator[] = $callableModificator;
94 while($arMail = $rsMails->fetch())
96 foreach($arCallableModificator as $callableModificator)
97 $arMail[
'C_FIELDS'] = call_user_func_array($callableModificator, array($arMail[
'C_FIELDS']));
100 $fileListDb = Internal\EventAttachmentTable::getList(array(
101 'select' => array(
'FILE_ID'),
102 'filter' => array(
'=EVENT_ID' => $arMail[
"ID"])
104 while($file = $fileListDb->fetch())
106 $arFiles[] = $file[
'FILE_ID'];
108 $arMail[
'FILE'] = $arFiles;
110 if(!is_array($arMail[
'C_FIELDS']))
112 $arMail[
'C_FIELDS'] = array();
116 $flag = Event::handleEvent($arMail);
117 Internal\EventTable::update($arMail[
"ID"], array(
'SUCCESS_EXEC' => $flag,
'DATE_EXEC' =>
new Main\
Type\
DateTime));
119 catch (\Exception $e)
121 Internal\EventTable::update($arMail[
"ID"], array(
'SUCCESS_EXEC' =>
"E",
'DATE_EXEC' =>
new Main\
Type\
DateTime));
123 $application = Main\Application::getInstance();
124 $exceptionHandler = $application->getExceptionHandler();
125 $exceptionHandler->writeToLog($e);
136 $connection->unlock(
'event');
138 if($cnt === 0 && CACHED_b_event !==
false)
139 $manage_cache->set(
"events",
true);
150 $period = abs(intval(Main\
Config\Option::get(
"main",
"mail_event_period", 14)));
151 $periodInSeconds = $period * 24 * 3600;
153 $connection = Main\Application::getConnection();
154 $datetime = $connection->getSqlHelper()->addSecondsToDateTime(
'-' . $periodInSeconds);
156 $strSql =
"DELETE FROM b_event WHERE DATE_EXEC <= " . $datetime;
157 $connection->query($strSql);
159 $strSql =
"DELETE FROM b_event_attachment "
160 .
" WHERE IS_FILE_COPIED='N'"
161 .
" AND NOT EXISTS(SELECT e.ID FROM b_event e WHERE e.ID=EVENT_ID)";
162 $connection->query($strSql);
165 self::class .
'::cleanUpAttachmentAgent();',
173 return "CEvent::CleanUpAgent();";