• Модуль: imopenlines
  • Путь к файлу: ~/bitrix/modules/imopenlines/lib/session/agent.php
  • Класс: BitrixImOpenLinesSessionAgent
  • Вызов: Agent::mailByTime
static function mailByTime($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_MAIL))
	{
		ExecLog::setExecFunction(__METHOD__);
		return $emptyResultReturn;
	}

	$configCount = SessionCheckTable::getList(array(
		'select' => array('CNT'),
		'runtime' => array(new ExpressionField('CNT', 'COUNT(*)')),
		'filter' => array('!=DATE_MAIL' => null)
	))->fetch();
	if ($configCount['CNT'] <= 0)
	{
		Session::setQueueFlagCache(Session::CACHE_MAIL);
		ExecLog::setExecFunction(__METHOD__);
		return $emptyResultReturn;
	}

	$res = SessionCheckTable::getList(Array(
		'select' => Array('SESSION_ID'),
		'filter' => Array(
			'<=DATE_MAIL' => new DateTime()
		),
		'limit' => 100
	));
	while ($row = $res->fetch())
	{
		Mail::sendOperatorAnswer($row['SESSION_ID']);
	}

	if (Loader::includeModule('pull'))
	{
		PullEvent::send();
	}

	ExecLog::setExecFunction(__METHOD__);

	Debug::addAgent('stop ' . __METHOD__);

	return __METHOD__. '(1);';
}