CBPRestActivity :: Execute: Bitrix method

      
<?php 
//  CBPRestActivity :: Execute()
//  /dist/bitrix/modules/bizproc/classes/general/restactivity.php:97

    
public function Execute()
    {
        
$activityData $this->getRestActivityData();
        if (!
$activityData)
            throw new 
Exception(Loc::getMessage('BPRA_NOT_FOUND_ERROR'));
        if (!
Loader::includeModule('rest') || !\Bitrix\Rest\OAuthService::getEngine()->isRegistered())
            return 
CBPActivityExecutionStatus::Closed;

        
$propertiesData = [];
        if (!empty(
$activityData['PROPERTIES']))
        {
            
/** @var CBPDocumentService $documentService */
            
$documentService $this->workflow->GetService('DocumentService');
            foreach (
$activityData['PROPERTIES'] as $name => $property)
            {
                
$property Bizproc\FieldType::normalizeProperty($property);
                
$propertiesData[$name] = $this->__get($name);

                if (
$propertiesData[$name])
                {
                    
$fieldTypeObject $documentService->getFieldTypeObject($this->GetDocumentType(), $property);
                    if (
$fieldTypeObject)
                    {
                        
$fieldTypeObject->setDocumentId($this->GetDocumentId());
                        
$propertiesData[$name] = $fieldTypeObject->externalizeValue($this->GetName(), $propertiesData[$name]);
                    }
                }

                if (
$propertiesData[$name] === null)
                {
                    
$propertiesData[$name] = '';
                }
            }
        }

        
$dbRes = \Bitrix\Rest\AppTable::getList(array(
            
'filter' => array(
                
'=CLIENT_ID' => $activityData['APP_ID'],
            )
        ));
        
$application $dbRes->fetch();

        if (!
$application)
        {
            throw new 
Exception('Rest application not found.');
        }

        
$appStatus = \Bitrix\Rest\AppTable::getAppStatusInfo($application'');
        if(
$appStatus['PAYMENT_ALLOW'] === 'N')
        {
            throw new 
Exception('Rest application status error: payment required');
        }

        
$userId CBPHelper::ExtractUsers($this->AuthUserId$this->GetDocumentId(), true);

        
$auth = array(
            
'WORKFLOW_ID' => $this->getWorkflowInstanceId(),
            
'ACTIVITY_NAME' => $this->name,
            
'CODE' => $activityData['CODE'],
            \
Bitrix\Rest\OAuth\Auth::PARAM_LOCAL_USER => $userId,
            
"application_token" => \CRestUtil::getApplicationToken($application),
        );

        
$this->eventId = \Bitrix\Main\Security\Random::getString(32true);

        
$queryItems = array(
            
Sqs::queryItem(
                
$activityData['APP_ID'],
                
$activityData['HANDLER'],
                array(
                    
'workflow_id' => $this->getWorkflowInstanceId(),
                    
'code' => $activityData['CODE'],
                    
'document_id' => $this->GetDocumentId(),
                    
'document_type' => $this->GetDocumentType(),
                    
'event_token' => self::generateToken($this->getWorkflowInstanceId(), $this->name$this->eventId),
                    
'properties' => $propertiesData,
                    
'use_subscription' => $this->UseSubscription,
                    
'timeout_duration' => $this->CalculateTimeoutDuration(),
                    
'ts' => time(),
                ),
                
$auth,
                array(
                    
"sendAuth" => true,
                    
"sendRefreshToken" => true,
                    
"category" => Sqs::CATEGORY_BIZPROC,
                )
            ),
        );

        \
Bitrix\Rest\OAuthService::getEngine()->getClient()->sendEvent($queryItems);

        if (
is_callable(['\Bitrix\Rest\UsageStatTable''logRobot']))
        {
            if (
$activityData['IS_ROBOT'] === 'Y')
            {
                \
Bitrix\Rest\UsageStatTable::logRobot($activityData['APP_ID'], $activityData['CODE']);
            }
            else
            {
                \
Bitrix\Rest\UsageStatTable::logActivity($activityData['APP_ID'], $activityData['CODE']);
            }

            \
Bitrix\Rest\UsageStatTable::finalize();
        }

        if (
$this->SetStatusMessage == 'Y')
        {
            
$message $this->StatusMessage;
            if (empty(
$message))
                
$message Loc::getMessage('BPRA_DEFAULT_STATUS_MESSAGE');
            
$this->SetStatusTitle($message);
        }

        if (
$this->UseSubscription != 'Y')
            return 
CBPActivityExecutionStatus::Closed;

        
$this->Subscribe($this);

        return 
CBPActivityExecutionStatus::Executing;
    }