CBPAllStateService :: getWorkflowIntegerId: Bitrix method

      
<?php 
//  CBPAllStateService :: getWorkflowIntegerId()
//  /dist/bitrix/modules/bizproc/classes/general/stateservice.php:354

    
public static function getWorkflowIntegerId($workflowId)
    {
        global 
$DB;

        
$workflowId trim($workflowId);
        if (
strlen($workflowId) <= 0)
            throw new 
Exception("workflowId");

        
$dbResult $DB->Query(
            
"SELECT ID FROM b_bp_workflow_state_identify WHERE WORKFLOW_ID = '".$DB->ForSql($workflowId)."' "
        
);

        
$result $dbResult->fetch();
        if (!
$result)
        {
            
$strSql =
                
"INSERT INTO b_bp_workflow_state_identify (WORKFLOW_ID) ".
                
"VALUES ('".$DB->ForSql($workflowId)."')";
            
$res $DB->Query($strSqltrue);
            
//crutch for #0071996
            
if ($res)
            {
                
$result = array('ID' => $DB->LastID());
            }
            else
            {
                
$dbResult $DB->Query(
                    
"SELECT ID FROM b_bp_workflow_state_identify WHERE WORKFLOW_ID = '".$DB->ForSql($workflowId)."' "
                
);

                
$result $dbResult->fetch();
            }
        }
        return (int)
$result['ID'];
    }