public virtual void DeleteAttachmentsByTaskId(string taskId) { CheckHistoryEnabled(); IList <IAttachmentEntity> attachments = FindAttachmentsByTaskId(taskId); bool dispatchEvents = EventDispatcher.Enabled; string processInstanceId = null; string processDefinitionId = null; string executionId = null; if (dispatchEvents && attachments != null && attachments.Count > 0) { // Forced to fetch the task to get hold of the process definition // for event-dispatching, if available ITask task = TaskEntityManager.FindById <ITask>(new KeyValuePair <string, object>("id", taskId)); if (task != null) { processDefinitionId = task.ProcessDefinitionId; processInstanceId = task.ProcessInstanceId; executionId = task.ExecutionId; } } foreach (IAttachment attachment in attachments) { string contentId = attachment.ContentId; if (!(contentId is null)) { ByteArrayEntityManager.DeleteByteArrayById(contentId); } attachmentDataManager.Delete((IAttachmentEntity)attachment); if (dispatchEvents) { EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_DELETED, attachment, executionId, processInstanceId, processDefinitionId)); } } }
protected internal virtual void DeleteProcessInstanceCascade(IExecutionEntity execution, string deleteReason, bool deleteHistory) { // fill default reason if none provided if (deleteReason is null) { deleteReason = DeleteReasonFields.PROCESS_INSTANCE_DELETED; } foreach (IExecutionEntity subExecutionEntity in execution.Executions) { if (subExecutionEntity.IsMultiInstanceRoot) { foreach (IExecutionEntity miExecutionEntity in subExecutionEntity.Executions) { if (miExecutionEntity.SubProcessInstance != null) { DeleteProcessInstanceCascade(miExecutionEntity.SubProcessInstance, deleteReason, deleteHistory); } } } else if (subExecutionEntity.SubProcessInstance != null) { DeleteProcessInstanceCascade(subExecutionEntity.SubProcessInstance, deleteReason, deleteHistory); } } TaskEntityManager.DeleteTasksByProcessInstanceId(execution.Id, deleteReason, deleteHistory); if (EventDispatcher.Enabled) { EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateCancelledEvent(execution.ProcessInstanceId, execution.ProcessInstanceId, null, deleteReason)); } // delete the execution BEFORE we delete the history, otherwise we will // produce orphan HistoricVariableInstance instances IExecutionEntity processInstanceExecutionEntity = execution.ProcessInstance; if (processInstanceExecutionEntity == null) { return; } IList <IExecutionEntity> childExecutions = CollectChildren(execution.ProcessInstance); for (int i = childExecutions.Count - 1; i >= 0; i--) { IExecutionEntity childExecutionEntity = childExecutions[i]; DeleteExecutionAndRelatedData(childExecutionEntity, deleteReason, false); } DeleteExecutionAndRelatedData(execution, deleteReason, false); if (deleteHistory) { HistoricProcessInstanceEntityManager.Delete(new KeyValuePair <string, object>("id", execution.Id)); } HistoryManager.RecordProcessInstanceEnd(processInstanceExecutionEntity.Id, deleteReason, null); processInstanceExecutionEntity.Deleted = true; }