CBPWorkflowPersister::InsertWorkflow: Bitrix method

      
<?php 
//  CBPWorkflowPersister :: InsertWorkflow()
//  /dist/bitrix/modules/bizproc/classes/mysql/workflowpersister.php:69

    
protected function InsertWorkflow($id$buffer$status$bUnlocked)
    {
        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'));
                }
            }
            else
            {
                
$DB->Query(
                    
"INSERT INTO b_bp_workflow_instance (ID, WORKFLOW, STATUS, MODIFIED, OWNER_ID, OWNED_UNTIL) ".
                    
"VALUES ('".$DB->ForSql($id)."', '".$DB->ForSql($buffer)."', ".intval($status).", ".$DB->CurrentTimeFunction().", ".($bUnlocked "NULL" "'".$DB->ForSql($this->serviceInstanceId)."'").", ".($bUnlocked "NULL" $DB->CharToDateFunction(date($GLOBALS["DB"]->DateFormatToPHP(FORMAT_DATETIME), $this->GetOwnershipTimeout()))).")"
                
);
            }
        }
    }