- Модуль: imopenlines
- Путь к файлу: ~/bitrix/modules/imopenlines/lib/session/agent.php
- Класс: BitrixImOpenLinesSessionAgent
- Вызов: Agent::closeByTime
static function closeByTime($nextExec = 0)
{
Debug::addAgent('start ' . __METHOD__);
$emptyResultReturn = __METHOD__. '(0);';
if (self::isCronCall() && self::isExecModeAgent() || !self::isCronCall() && self::isExecModeCron())
{
return $emptyResultReturn;
}
if (Session::getQueueFlagCache(Session::CACHE_CLOSE))
{
ExecLog::setExecFunction(__METHOD__);
return $emptyResultReturn;
}
$configCount = SessionCheckTable::getList(array(
'select' => array('CNT'),
'runtime' => array(new ExpressionField('CNT', 'COUNT(*)')),
'filter' => array('!=DATE_CLOSE' => null)
))->fetch();
if ($configCount['CNT'] <= 0)
{
Session::setQueueFlagCache(Session::CACHE_CLOSE);
ExecLog::setExecFunction(__METHOD__);
return $emptyResultReturn;
}
$configs = [];
$chats = [];
$configManager = new Config();
$select = SessionTable::getSelectFieldsPerformance('SESSION');
$res = SessionCheckTable::getList(Array(
'select' => $select,
'filter' => Array(
'<=DATE_CLOSE' => new DateTime()
),
'limit' => 100
));
while ($row = $res->fetch())
{
$fields = [];
foreach($row as $key=>$value)
{
$key = str_replace('IMOPENLINES_MODEL_SESSION_CHECK_SESSION_', '', $key);
$fields[$key] = $value;
}
if (!empty($fields['CONFIG_ID']) && empty($configs[$fields['CONFIG_ID']]))
{
$configs[$fields['CONFIG_ID']] = $configManager->get($fields['CONFIG_ID']);
}
if (!empty($fields['CHAT_ID']) && empty($chats[$fields['CHAT_ID']]))
{
$chats[$fields['CHAT_ID']] = new Chat($fields['CHAT_ID']);
}
if(!empty($fields) && !empty($configs[$fields['CONFIG_ID']]) && !empty($chats[$fields['CHAT_ID']]))
{
$session = new Session();
$session->loadByArray($fields, $configs[$fields['CONFIG_ID']], $chats[$fields['CHAT_ID']]);
$session->finish(true);
}
}
if (Loader::includeModule('pull'))
{
PullEvent::send();
}
ExecLog::setExecFunction(__METHOD__);
Debug::addAgent('stop ' . __METHOD__);
return __METHOD__. '(1);';
}