CBPAllWorkflowPersister :: InsertWorkflow: Bitrix method

      
<?php 
//  CBPAllWorkflowPersister :: InsertWorkflow()
//  /dist/bitrix/modules/bizproc/classes/general/workflowpersister.php:78

    
protected function InsertWorkflow($id$buffer$status$bUnlocked, array $creationData = [])
    {
        global 
$DB;

        
$queryCondition $this->getLockerQueryCondition();

        if (
$status == CBPWorkflowStatus::Completed || $status == CBPWorkflowStatus::Terminated)
        {
            
$DB->Query(
                
"DELETE FROM b_bp_workflow_instance ".
                
"WHERE ID = '".$DB->ForSql($id)."'"
            
);
        }
        else
        {
            
$dbResult $DB->Query(
                
"SELECT ID, IF (".$queryCondition.", 'Y', 'N') as UPDATEABLE ".
                
"FROM b_bp_workflow_instance ".
                
"WHERE ID = '".$DB->ForSql($id)."' "
            
);
            if (
$arResult $dbResult->Fetch())
            {
                if (
$arResult["UPDATEABLE"] == "Y")
                {
                    
$DB->Query(
                        
"UPDATE b_bp_workflow_instance SET ".
                        
"    WORKFLOW = '".$DB->ForSql($buffer)."', ".
                        
"    STATUS = ".intval($status).", ".
                        
"    MODIFIED = ".$DB->CurrentTimeFunction().", ".
                        
"    OWNER_ID = ".($bUnlocked "NULL" "'".$DB->ForSql($this->serviceInstanceId)."'").", ".
                        
"    OWNED_UNTIL = ".($bUnlocked "NULL" $DB->CharToDateFunction(date($GLOBALS["DB"]->DateFormatToPHP(FORMAT_DATETIME), $this->GetOwnershipTimeout())))." ".
                        
"WHERE ID = '".$DB->ForSql($id)."' "
                    
);
                }
                else
                {
                    throw new 
Exception(GetMessage('BPCGWP_WF_LOCKED'), \CBPRuntime::EXCEPTION_CODE_INSTANCE_LOCKED);
                }
            }
            else
            {
                
$status = (int) $status;
                
$ownerId = ($bUnlocked "NULL" "'".$DB->ForSql($this->serviceInstanceId)."'");
                
$ownedUntil = ($bUnlocked "NULL" $DB->CharToDateFunction(date($GLOBALS["DB"]->DateFormatToPHP(FORMAT_DATETIME), $this->GetOwnershipTimeout())));

                
$moduleId = isset($creationData['MODULE_ID']) ? $creationData['MODULE_ID'] : '';
                
$entity = isset($creationData['ENTITY']) ? $creationData['ENTITY'] : '';
                
$documentId = isset($creationData['DOCUMENT_ID']) ? $creationData['DOCUMENT_ID'] : '';
                
$tplId = isset($creationData['WORKFLOW_TEMPLATE_ID']) ? (int) $creationData['WORKFLOW_TEMPLATE_ID'] : 0;
                
$startedBy = isset($creationData['STARTED_BY']) ? (int) $creationData['STARTED_BY'] : 0;
                
$startedEventType = isset($creationData['STARTED_EVENT_TYPE']) ? (int) $creationData['STARTED_EVENT_TYPE'] : 0;

                
$DB->Query(
                    
"INSERT INTO b_bp_workflow_instance (
                        ID, WORKFLOW, STATUS, MODIFIED, OWNER_ID, OWNED_UNTIL,
                        MODULE_ID, ENTITY, DOCUMENT_ID, WORKFLOW_TEMPLATE_ID, STARTED, STARTED_BY, STARTED_EVENT_TYPE
                    ) "
.
                    
"VALUES ('".$DB->ForSql($id)."', '".$DB->ForSql($buffer)."', ".$status.", ".
                    
$DB->CurrentTimeFunction().", ".$ownerId.", ".$ownedUntil.", '".
                    
$DB->ForSql($moduleId)."', '".$DB->ForSql($entity)."', '".$DB->ForSql($documentId)."', ".
                    
$tplId.", ".$DB->CurrentTimeFunction().", ".$startedBy.", ".$startedEventType.")"
                
);
            }
        }
    }