• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/update/expiredagentcreator.php
  • Класс: BitrixTasksUpdateExpiredAgentCreator
  • Вызов: ExpiredAgentCreator::execute
public function execute(array &$result): bool
{
	if (!Loader::includeModule("tasks"))
	{
		return false;
	}

	$found = false;
	$parameters = static::getParameters();

	static::clearOldAgents($parameters);

	if ($parameters["count"] > 0)
	{
		$result["count"] = $parameters["count"];

		$res = Application::getConnection()->query("
			SELECT ID, DEADLINE
			FROM b_tasks 
			WHERE 
				STATUS < 4
				AND DEADLINE IS NOT NULL
				AND DEADLINE > NOW()
				AND ID > {$parameters['last_id']}
			ORDER BY ID
			LIMIT 100
		");
		while ($task = $res->fetch())
		{
			$taskId = $task['ID'];

			if ($deadline = DateTime::createFromInstance($task['DEADLINE']))
			{
				Agent::add($taskId, $deadline);
			}

			$parameters["last_id"] = $taskId;
			$found = true;
		}

		if ($found)
		{
			Option::set("tasks", "expiredAgentCreator", serialize($parameters));
		}
	}

	if ($found === false)
	{
		Option::delete("tasks", ["name" => "expiredAgentCreator"]);
	}

	return $found;
}