• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/integration/disk.php
  • Класс: BitrixTasksIntegrationDisk
  • Вызов: Disk::cloneFileAttachmentHash
static function cloneFileAttachmentHash(array $attachments = array(), $userId = 0)
{
	$result = array();

	if(!static::includeModule())
	{
		return $result;
	}

	if(!$userId)
	{
		$userId = User::getId();
	}

	// transform UF files
	if(!empty($attachments))
	{
		// find which files are unattached and which are attached
		$attached = array();
		$unattached = array();
		foreach($attachments as $attachmentId)
		{
			if((string) $attachmentId != '')
			{
				if(mb_strpos($attachmentId, FileUserType::NEW_FILE_PREFIX) === 0)
				{
					$unattached[$attachmentId] = $attachmentId;
				}
				else
				{
					$attached[] = $attachmentId;
				}
			}
		}

		// clone all attached files, leave unattached unchanged
		if(!empty($attached))
		{
			$userFieldManager = Driver::getInstance()->getUserFieldManager();
			$clones = $userFieldManager->cloneUfValuesFromAttachedObject($attached, $userId);

			foreach($clones as $i => $clone)
			{
				$unattached[$i] = $clone;
			}
		}

		$result = $unattached;
	}

	return $result;
}