CCrmWebDavHelper::SaveFile

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmWebDavHelper
  4. SaveFile
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_webdav_helper.php
  • Класс: \CCrmWebDavHelper
  • Вызов: CCrmWebDavHelper::SaveFile
static function SaveFile($arFile, $siteID = SITE_ID, $params = array())
{
	if (!(IsModuleInstalled('iblock')
		&& CModule::IncludeModule('iblock')))
	{
		return false;
	}

	$siteID = strval($siteID);
	if($siteID === '')
	{
		if(!(defined('ADMIN_SECTION') && ADMIN_SECTION))
		{
			$siteID = SITE_ID;
		}
		else
		{
			$dbSites = CSite::GetList('sort', 'desc', array('DEFAULT' => 'Y'));
			while($arSite = $dbSites->Fetch())
			{
				$siteID = $arSite['LID'];
			}
		}
	}

	if($siteID === '')
	{
		return false;
	}

	$blockID = self::ResolveSharedFileIBlockID($siteID);
	if($blockID <= 0)
	{
		return false;
	}

	if(!is_array($params))
	{
		$params = array();
	}
	$typeID = isset($params['TYPE_ID']) ? intval($params['TYPE_ID']) : CCrmWebDavFileType::Undefined;
	if(!CCrmWebDavFileType::IsDefined($typeID))
	{
		$typeID = CCrmWebDavFileType::EmailAttachment;
	}

	$blockSectionID = self::EnsureSharedFileSectionCreated($blockID, $typeID, $siteID);
	if($blockSectionID <= 0)
	{
		return false;
	}

	$elementName = $arFile['ORIGINAL_NAME'];
	$fileInfo = pathinfo($elementName);
	$element = new CIBlockElement();
	$alreadyExists = false;
	$i = 0;
	do
	{
		if($alreadyExists)
		{
			$i++;
			$elementName  = isset($fileInfo['extension']) ? "{$fileInfo['filename']}_{$i}.{$fileInfo['extension']}" : "{$fileInfo['filename']}_{$i}";
		}

		$dbRes = $element->GetList(array(), array('=NAME' => $elementName, 'IBLOCK_ID'=> $blockID, 'IBLOCK_SECTION_ID'=> $blockSectionID), false, array('nTopCount'=>1), array('ID'));
		$arRes = $dbRes ? $dbRes->Fetch() : false;
		$alreadyExists = $arRes !== false;
	} while($alreadyExists);

	$arFields = array(
		'ACTIVE' => 'Y',
		'IBLOCK_ID' => $blockID,
		'IBLOCK_SECTION_ID' => $blockSectionID,
		'NAME' => $elementName,
		//'TAGS' => '',
		//'MODIFIED_BY' => $GLOBALS['USER']->GetID(),
		//'PREVIEW_TEXT_TYPE' => 'html',
		//'PREVIEW_TEXT' => '',
		'WF_COMMENTS' => '',
		'PROPERTY_VALUES' => array(
			'FILE' => $arFile,
			'WEBDAV_SIZE' => $arFile['FILE_SIZE']
		),
	);
	return $element->Add($arFields, false, true, false);
}

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