• Модуль: sender
  • Путь к файлу: ~/bitrix/modules/sender/lib/internals/sqlbatch.php
  • Класс: Bitrix\Sender\Internals\SqlBatch
  • Вызов: SqlBatch::update
static function update($tableName, array $fields)
{
	$ids = []; $sets = [];
	foreach ($fields as $item)
	{
		if (!isset($item['ID']) || !$item['ID'])
		{
			continue;
		}

		$id = (int) $item['ID'];
		if ($id <= 0)
		{
			continue;
		}
		$ids[] = $id;
		unset($item['ID']);

		foreach ($item as $key => $value)
		{
			if (!isset($sets[$key]))
			{
				$sets[$key] = [];
			}

			$sets[$key][$id] = $value;
		}
	}

	if (count($ids) <= 0 || count($sets) <= 0)
	{
		return;
	}

	$conHelper = Application::getConnection()->getSqlHelper();
	$ids = implode(',', $ids);
	$stringSets = [];
	foreach ($sets as $key => $values)
	{
		$stringSet = "";
		foreach ($values as $id => $value)
		{
			$value = $conHelper->forSql($value);
			$stringSet .= "\nWHEN ID = $id THEN \"$value\"";
		}
		$stringSet = "\n$key = CASE $stringSet ELSE $key END";
		$stringSets[] = $stringSet;
	}
	$stringSets = implode(', ', $stringSets) . "\n";


	$sql = "UPDATE $tableName SET $stringSets WHERE ID in ($ids)";
	Application::getConnection()->query($sql);
}