CBPWorkflowTemplateLoader::DeleteTemplate: Bitrix method

      
<?php 
//  CBPWorkflowTemplateLoader :: DeleteTemplate()
//  /dist/bitrix/modules/bizproc/classes/general/workflowtemplateloader.php:258

    
public function DeleteTemplate($id)
    {
        global 
$DB;

        
$id intval($id);
        if (
$id <= 0)
            throw new 
Exception("id");

        
$dbResult $DB->Query(
            
"SELECT COUNT('x') as CNT ".
            
"FROM b_bp_workflow_instance WI ".
            
"WHERE WI.WORKFLOW_TEMPLATE_ID = ".intval($id)." "
        
);

        if (
$arResult $dbResult->Fetch())
        {
            
$cnt intval($arResult["CNT"]);

            if (
$cnt <= 0)
            {
                
$DB->Query(
                    
"DELETE FROM b_bp_workflow_template ".
                    
"WHERE ID = ".intval($id)." "
                
);
            }
            else
            {
                throw new 
CBPInvalidOperationException(GetMessage("BPCGWTL_CANT_DELETE"));
            }
        }
        else
        {
            throw new 
Exception(GetMessage("BPCGWTL_UNKNOWN_ERROR"));
        }
    }