CAllCrmMailTemplate::Update

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmMailTemplate
  4. Update
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/mail_template.php
  • Класс: \CAllCrmMailTemplate
  • Вызов: CAllCrmMailTemplate::Update
static function Update($ID, &$arFields, $options = null)
{
	global $DB;

	self::ClearErrors();

	if(!is_array($options))
	{
		$options = array();
	}
	$ID = (int)$ID;

	self::prepareAttachmentsForOldTemplate($ID);
	
	if (!self::CheckFields('UPDATE', $arFields, $ID))
	{
		return false;
	}

	if(isset($arFields['SCOPE']) && !CCrmMailTemplateScope::IsDefined($arFields['SCOPE']))
	{
		$arFields['SCOPE'] = CCrmMailTemplateScope::Personal;
	}

	if (isset($arFields['CREATED']))
	{
		unset($arFields['CREATED']);
	}

	if (isset($arFields['LAST_UPDATED']))
	{
		unset($arFields['LAST_UPDATED']);
	}

	$arFields['~LAST_UPDATED'] = $DB->CurrentTimeFunction();

	if(isset($arFields['AUTHOR_ID']))
	{
		unset($arFields['AUTHOR_ID']);
	}

	$currentUserID =  isset($options['CURRENT_USER_ID']) ? intval($options['CURRENT_USER_ID']) : CCrmPerms::GetCurrentUserID();

	if(!isset($arFields['EDITOR_ID']))
	{
		$arFields['EDITOR_ID'] = $currentUserID;
	}

	$arRecordBindings = array();
	if(isset($arFields['BODY']))
	{
		$arRecordBindings['BODY'] = $arFields['BODY'];
	}

	$tableName = CCrmMailTemplate::TABLE_NAME;
	$sql = 'UPDATE '.$tableName.' SET '.$DB->PrepareUpdate($tableName, $arFields).' WHERE ID = '.$ID;
	if(!empty($arRecordBindings))
	{
		$DB->QueryBind($sql, $arRecordBindings, false);
	}
	else
	{
		$DB->Query($sql, false, 'File: '.__FILE__.'
Line: '.__LINE__); } self::updateUserFields($ID, $arFields); $rsEvents = GetModuleEvents('crm', 'OnMailTemplateUpdate'); while ($arEvent = $rsEvents->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID, &$arFields)); } return true; }

Добавить комментарий