/** * Evaluate all the transitions of an action and determine whether we should * follow any of them yet. * * @param WorkflowActionInstance $action * @return WorkflowTransition */ protected function checkTransitions(WorkflowActionInstance $action) { $transitions = $action->getValidTransitions(); // if there's JUST ONE transition, then we need should // immediately follow it. if ($transitions && $transitions->count() == 1) { return $transitions->First(); } }
/** * When deleting an action from a workflow definition, make sure that workflows currently paused on that action * are deleted * Also removes all outbound transitions */ public function onAfterDelete() { parent::onAfterDelete(); $wfActionInstances = WorkflowActionInstance::get()->leftJoin("WorkflowInstance", '"WorkflowInstance"."ID" = "WorkflowActionInstance"."WorkflowID"')->where(sprintf('"BaseActionID" = %d AND ("WorkflowStatus" IN (\'Active\',\'Paused\'))', $this->ID)); foreach ($wfActionInstances as $wfActionInstance) { $wfInstances = WorkflowInstance::get()->filter('CurrentActionID', $wfActionInstance->ID); foreach ($wfInstances as $wfInstance) { $wfInstance->Groups()->removeAll(); $wfInstance->Users()->removeAll(); $wfInstance->delete(); } $wfActionInstance->delete(); } // Delete outbound transitions $transitions = WorkflowTransition::get()->filter('ActionID', $this->ID); foreach ($transitions as $transition) { $transition->Groups()->removeAll(); $transition->Users()->removeAll(); $transition->delete(); } }