ClearVariables: Bitrix method

      
<?php 
//  ClearVariables()
//  /dist/bitrix/modules/bizproc/classes/general/activity.php:199

    
protected function ClearVariables()
    {
        
$rootActivity $this->GetRootActivity();
        
$documentId $rootActivity->GetDocumentId();
        
$documentType $this->GetDocumentType();
        
/** @var CBPDocumentService $documentService */
        
$documentService $this->workflow->GetService("DocumentService");

        if (
is_array($rootActivity->arVariablesTypes) && count($rootActivity->arVariablesTypes) > 0
            
&& is_array($rootActivity->arFieldTypes) && count($rootActivity->arFieldTypes) > 0)
        {
            foreach (
$rootActivity->arVariablesTypes as $key => $value)
            {
                if (
$rootActivity->arFieldTypes[$value["Type"]]["BaseType"] == "file")
                {
                    foreach ((array) 
$rootActivity->arVariables[$key] as $v)
                    {
                        if (
intval($v) > 0)
                        {
                            
$iterator = \CFile::getByID($v);
                            if (
$file $iterator->fetch())
                            {
                                if (
$file['MODULE_ID'] === 'bizproc')
                                    
CFile::Delete($v);
                            }
                        }
                    }
                }

                
$fieldType = \Bitrix\Bizproc\FieldType::normalizeProperty($value);
                if (
$fieldTypeObject $documentService->getFieldTypeObject($documentType$fieldType))
                {
                    
$fieldTypeObject->setDocumentId($documentId)
                        ->
clearValue($rootActivity->arVariables[$key]);
                }
            }
        }
    }