- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/update/stepper.php
- Класс: BitrixMainUpdateStepper
- Вызов: Stepper::bindClass
static function bindClass($className, $moduleId, $delay = 300, $withArguments = [])
{
if (class_exists("CAgent"))
{
$addAgent = true;
$withArguments = is_array($withArguments) ? $withArguments : [];
$delay = (int)$delay;
if ($delay <= 0)
{
/** @var Stepper $className */
$addAgent = ('' !== call_user_func_array([$className, "execAgent"], $withArguments));
}
if ($addAgent)
{
if (Option::get("main.stepper.".$moduleId, $className, "") === "")
Option::set("main.stepper.".$moduleId, $className, serialize([]));
CTimeZone::Disable();
CAgent::AddAgent(
$className.'::execAgent('.(empty($withArguments) ? '' : call_user_func_array([$className, "makeArguments"], [$withArguments])).');',
$moduleId,
"Y",
1,
"",
"Y",
date(MainTypeDate::convertFormatToPhp(CSite::GetDateFormat("FULL")), time() + $delay),
100,
false,
false
);
CTimeZone::Enable();
}
}
else
{
$connection = BitrixMainApplication::getConnection();
$helper = $connection->getSqlHelper();
$arguments = '';
if (!empty($withArguments))
{
$arguments = class_exists($className)
? call_user_func_array([$className, "makeArguments"], [$withArguments])
: self::makeArguments($withArguments)
;
}
$name = $helper->forSql($className.'::execAgent('.$arguments.');', 2000);
$className = $helper->forSql($className);
$moduleId = $helper->forSql($moduleId);
$agent = $connection->query("SELECT ID FROM b_agent WHERE MODULE_ID='".$moduleId."' AND NAME = '".$name."' AND USER_ID IS NULL")->fetch();
if (!$agent)
{
$connection->query("INSERT INTO b_agent (MODULE_ID, SORT, NAME, ACTIVE, AGENT_INTERVAL, IS_PERIOD, NEXT_EXEC) VALUES ('".$moduleId."', 100, '".$name."', 'Y', 1, 'Y', ".($delay > 0 ? $helper->addSecondsToDateTime($delay) : $helper->getCurrentDateTimeFunction()).")");
$merge = $helper->prepareMerge('b_option', ['MODULE_ID', 'NAME'], [
'MODULE_ID' => 'main.stepper.' . $moduleId,
'NAME' => $className,
'VALUE' => 'a:0:{}',
], [
'VALUE' => 'a:0:{}',
]);
if ($merge)
{
$connection->Query($merge[0]);
}
}
}
}