CBPDocument :: OnDocumentDelete: Bitrix method

      
<?php 
//  CBPDocument :: OnDocumentDelete()
//  /dist/bitrix/modules/bizproc/classes/general/document.php:486

    
public static function OnDocumentDelete($documentId, &$errors)
    {
        
$errors = [];

        
$instanceIds WorkflowInstanceTable::getIdsByDocument($documentId);
        foreach (
$instanceIds as $instanceId)
        {
            static::
TerminateWorkflow($instanceId$documentId$errors);
        }

        
$statesIds = \CBPStateService::getIdsByDocument($documentId);
        foreach (
$statesIds as $stateId)
        {
            \
CBPTaskService::DeleteByWorkflow($stateId);
            \
CBPTrackingService::DeleteByWorkflow($stateId);
        }

        \
CBPStateService::deleteCompletedStates($documentId);
        
CBPHistoryService::DeleteByDocument($documentId);
    }