Пример #1
0
        /// <summary>
        ///     Deletes the given process definition from the database and cache.
        ///     If cascadeToHistory and cascadeToInstances is set to true it deletes
        ///     the history and the process instances.
        ///     *Note*: If more than one process definition, from one deployment, is deleted in
        ///     a single transaction and the cascadeToHistory and cascadeToInstances flag was set to true it
        ///     can cause a dirty deployment cache. The process instances of ALL process definitions must be deleted,
        ///     before every process definition can be deleted! In such cases the cascadeToInstances flag
        ///     have to set to false!
        ///     On deletion of all process instances, the task listeners will be deleted as well.
        ///     Deletion of tasks and listeners needs the redeployment of deployments.
        ///     It can cause to problems if is done sequential with the deletion of process definition
        ///     in a single transaction.
        ///     *For example*:
        ///     Deployment contains two process definition. First process definition
        ///     and instances will be removed, also cleared from the cache.
        ///     Second process definition will be removed and his instances.
        ///     Deletion of instances will cause redeployment this deploys again
        ///     first into the cache. Only the second will be removed from cache and
        ///     first remains in the cache after the deletion process.
        /// </summary>
        /// <param name="processDefinition"> the process definition which should be deleted </param>
        /// <param name="processDefinitionId"> the id of the process definition </param>
        /// <param name="cascadeToHistory"> if true the history will deleted as well </param>
        /// <param name="cascadeToInstances"> if true the process instances are deleted as well </param>
        /// <param name="skipCustomListeners"> if true skips the custom listeners on deletion of instances </param>
        public virtual void DeleteProcessDefinition(IProcessDefinition processDefinition, string processDefinitionId,
                                                    bool cascadeToHistory, bool cascadeToInstances, bool skipCustomListeners)
        {
            if (cascadeToHistory)
            {
                CascadeDeleteHistoryForProcessDefinition(processDefinitionId);
                if (cascadeToInstances)
                {
                    CascadeDeleteProcessInstancesForProcessDefinition(processDefinitionId, skipCustomListeners);
                }
            }
            else
            {
                var processInstanceCount =
                    _execuutionManager.FindProcessInstanceCountByProcessDefinitionId(processDefinitionId);
                if (processInstanceCount != 0)
                {
                    throw Log.DeleteProcessDefinitionWithProcessInstancesException(processDefinitionId,
                                                                                   processInstanceCount);
                }
            }

            // remove related authorization parameters in IdentityLink table
            _identityLinkManager.DeleteIdentityLinksByProcDef(processDefinitionId);

            // remove timer start events:
            DeleteTimerStartEventsForProcessDefinition(processDefinition);

            //delete process definition from database
            Delete(processDefinitionId);
            // remove process definition from cache:
            Context.ProcessEngineConfiguration.DeploymentCache.RemoveProcessDefinition(processDefinitionId);

            DeleteSubscriptionsForProcessDefinition(processDefinitionId);

            // delete job definitions
            _jobDefinitionManager.DeleteJobDefinitionsByProcessDefinitionId(processDefinition.Id);
        }