• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/counter/entitycountableactivitytable.php
  • Класс: Bitrix\Crm\Counter\EntityCountableActivityTable
  • Вызов: EntityCountableActivityTable::upsert
static function upsert(array $fields): \Bitrix\Main\ORM\Data\Result
{
	$existedRecordId = self::query()
		->where('ENTITY_TYPE_ID', $fields['ENTITY_TYPE_ID'])
		->where('ENTITY_ID', $fields['ENTITY_ID'])
		->where('ACTIVITY_ID', $fields['ACTIVITY_ID'])
		->setSelect(['ID'])
		->setLimit(1)
		->fetch()['ID'] ?? null
	;
	if ($existedRecordId)
	{
		return self::update($existedRecordId, $fields);
	}

	return self::add($fields);
}