CBPAllTaskService :: DeleteByWorkflow: Bitrix method

      
<?php 
//  CBPAllTaskService :: DeleteByWorkflow()
//  /dist/bitrix/modules/bizproc/classes/general/taskservice.php:226

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

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

        
$dbRes $DB->Query(
            
"SELECT ID ".
            
"FROM b_bp_task ".
            
"WHERE WORKFLOW_ID = '".$DB->ForSql($workflowId)."' "
        
);
        while (
$arRes $dbRes->Fetch())
        {
            
$taskId intval($arRes["ID"]);
            
$removedUsers $decremented = [];
            
$dbResUser $DB->Query("SELECT USER_ID, STATUS FROM b_bp_task_user WHERE TASK_ID = ".$taskId." ");
            while (
$arResUser $dbResUser->Fetch())
            {
                if (
$arResUser['STATUS'] == CBPTaskUserStatus::Waiting)
                {
                    
CUserCounter::Decrement($arResUser["USER_ID"], 'bp_tasks''**');
                    
$decremented[] = $arResUser["USER_ID"];
                }
                
$removedUsers[] = $arResUser['USER_ID'];
            }
            
$DB->Query("DELETE FROM b_bp_task_user WHERE TASK_ID = ".$taskId." "true);

            
self::onTaskChange(
                
$taskId,
                [
                    
'USERS_REMOVED' => $removedUsers,
                    
'COUNTERS_DECREMENTED' => $decremented
                
],
                
CBPTaskChangedStatus::Delete
            
);
            foreach (
GetModuleEvents("bizproc""OnTaskDelete"true) as $arEvent)
                
ExecuteModuleEventEx($arEvent, array($taskId));
        }

        
$DB->Query(
            
"DELETE FROM b_bp_task ".
            
"WHERE WORKFLOW_ID = '".$DB->ForSql($workflowId)."' ",
            
true
        
);
    }