• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/rest/externalchannel.php
  • Класс: Bitrix\Crm\Rest\CCrmExternalChannelImportActivity
  • Вызов: CCrmExternalChannelImportActivity::onAfterEntityModify
public function onAfterEntityModify($entityFields, &$errors=array())
{
	$ownerEntity = $this->getOwnerEntity();

	if($ownerEntity->getOwnerTypeID() <> \CCrmOwnerType::Contact)
	{
		return false;
	}

	if(is_array($entityFields['FILES'][0]) && intval($entityFields['FILES'][0]['FILE_ID'])>0)
	{
		$file = File::getById($entityFields['FILES'][0]['FILE_ID']);
		$fileId = $file->getFileId();

		$dbRes = \CCrmContact::GetListEx(
			array(),
			array('=ID' => $this->getOwnerEntityId()),
			false,
			false,
			array(),
			array()
		);

		$result = $dbRes ? $dbRes->Fetch() : null;
		if(is_array($result))
		{
			if(empty($result['PHOTO']))
			{
				$fields = array();
				$agent = new CCrmExternalChannelImportAgent();
				$agent->internalizeFileFieldPhoto($fields, $fileId);

				$errors = array();
				if(count($fields)>0)
				{
					$ownerEntity->innerUpdate($this->getOwnerEntityId(), $fields, $errors);
				}
			}
		}
	}

	return true;
}