CBPWorkflow::Terminate: Bitrix method

      
<?php 
//  CBPWorkflow :: Terminate()
//  /dist/bitrix/modules/bizproc/classes/general/workflow.php:547

    
public function Terminate(Exception $e null$stateTitle '')
    {
        
/** @var CBPTaskService $taskService */
        
$taskService $this->GetService("TaskService");
        
$taskService->DeleteAllWorkflowTasks($this->GetInstanceId());

        
$this->SetWorkflowStatus(CBPWorkflowStatus::Terminated);

        
$persister CBPWorkflowPersister::GetPersister();
        
$persister->SaveWorkflow($this->rootActivitytrue);

        
/** @var CBPStateService $stateService */
        
$stateService $this->GetService("StateService");
        
$stateService->SetState(
            
$this->instanceId,
            array(
                
"STATE" => "Terminated",
                
"TITLE" => $stateTitle $stateTitle GetMessage("BPCGWF_TERMINATED"),
                
"PARAMETERS" => array()
            ),
            
false//array()
        
);

        if (
$e != null)
        {
            
$trackingService $this->GetService("TrackingService");
            
$trackingService->Write($this->instanceIdCBPTrackingType::FaultActivity"none"CBPActivityExecutionStatus::FaultingCBPActivityExecutionResult::Faulted"Exception", ($e->getCode()? "[".$e->getCode()."] " '').$e->getMessage());
        }
    }