CBPVirtualDocument :: UpdateDocument: Bitrix method

      
<?php 
//  CBPVirtualDocument :: UpdateDocument()
//  /dist/bitrix/modules/bizproc/classes/general/virtualdocument.php:1794

    
public function UpdateDocument($documentId$arFields)
    {
        
$documentId intval($documentId);
        if (
$documentId <= 0)
            throw new 
CBPArgumentNullException("documentId");

        
CIBlockElement::WF_CleanUpHistoryCopies($documentId0);

        
$arFieldsPropertyValues = array();

        
$dbResult CIBlockElement::GetList(array(), array("ID" => $documentId"SHOW_NEW" => "Y"), falsefalse, array("ID""IBLOCK_ID"));
        
$arResult $dbResult->Fetch();
        if (!
$arResult)
            throw new 
Exception("Element is not found");

        
$arDocumentFields self::GetDocumentFields("type_".$arResult["IBLOCK_ID"]);

        
$arKeys array_keys($arFields);
        foreach (
$arKeys as $key)
        {
            if (!
array_key_exists($key$arDocumentFields))
                continue;

            if (
$arDocumentFields[$key]["Multiple"] && is_string($arFields[$key]))
            {
                
$arFieldsTmp explode(","$arFields[$key]);
                
$arFields[$key] = array();
                foreach (
$arFieldsTmp as $value)
                    
$arFields[$key][] = trim($value);
            }

            
$arFields[$key] = (is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key])) ? $arFields[$key] : array($arFields[$key]);

            if (
$arDocumentFields[$key]["Type"] == "S:UserID")
            {
                
$ar = array();
                foreach (
$arFields[$key] as $v1)
                {
                    if (
substr($v10strlen("user_")) == "user_")
                    {
                        
$ar[] = substr($v1strlen("user_"));
                    }
                    else
                    {
                        
$a1 self::GetUsersFromUserGroup($v1$documentId);
                        foreach (
$a1 as $a11)
                            
$ar[] = $a11;
                    }
                }

                
$arFields[$key] = $ar;
            }
            elseif (
$arDocumentFields[$key]['Type'] == 'S:employee')
            {
                
$arFields[$key] = CBPHelper::StripUserPrefix($arFields[$key]);
            }
            elseif (
$arDocumentFields[$key]["Type"] == "L")
            {
                
$realKey = ((substr($key0strlen("PROPERTY_")) == "PROPERTY_") ? substr($keystrlen("PROPERTY_")) : $key);

                
$arV = array();
                
$db CIBlockProperty::GetPropertyEnum($realKeyfalse, array("IBLOCK_ID" => $arResult["IBLOCK_ID"]));
                while (
$ar $db->GetNext())
                    
$arV[$ar["XML_ID"]] = $ar["ID"];

                foreach (
$arFields[$key] as &$value)
                {
                    if (
array_key_exists($value$arV))
                        
$value $arV[$value];
                }
            }
            elseif (
$arDocumentFields[$key]["Type"] == "F")
            {
                foreach (
$arFields[$key] as &$value)
                    
$value CFile::MakeFileArray($value);
            }
            elseif (
$arDocumentFields[$key]["Type"] == "S:HTML")
            {
                foreach (
$arFields[$key] as &$value)
                    
$value = array("VALUE" => $value);
            }

            if (!
$arDocumentFields[$key]["Multiple"] && is_array($arFields[$key]))
            {
                if (
count($arFields[$key]) > 0)
                {
                    
$a array_values($arFields[$key]);
                    
$arFields[$key] = $a[0];
                }
                else
                {
                    
$arFields[$key] = null;
                }
            }

            if (
substr($key0strlen("PROPERTY_")) == "PROPERTY_")
            {
                
$realKey substr($keystrlen("PROPERTY_"));
                
$arFieldsPropertyValues[$realKey] = (is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key])) ? $arFields[$key] : array($arFields[$key]);
                unset(
$arFields[$key]);
            }
        }

        
$iblockElement = new CIBlockElement();

        if (
count($arFieldsPropertyValues) > 0)
            
$iblockElement->SetPropertyValuesEx($documentId$arResult["IBLOCK_ID"], $arFieldsPropertyValues);

        if (
count($arFields) > 0)
        {
            
$res $iblockElement->Update($documentId$arFieldsfalsetruetrue);
            if (!
$res)
                throw new 
Exception($iblockElement->LAST_ERROR);
        }
    }