public function execute()
    {
        if (!$this->CurrentActionID) {
            throw new Exception(
                sprintf(_t(
                    'WorkflowInstance.EXECUTE_EXCEPTION',
                    'Attempted to start an invalid workflow instance #%s!'
                ), $this->ID)
            );
        }

        $action     = $this->CurrentAction();
        $transition = false;

        // if the action has already finished, it means it has either multiple (or no
        // transitions at the time), so a subsequent check should be run.
        if ($action->Finished) {
            $transition = $this->checkTransitions($action);
        } else {
            $result = $action->BaseAction()->execute($this);

            // if the action was successful, then the action has finished running and
            // next transition should be run (if only one).
            // input.
            if ($result) {
                $action->MemberID = Security::getCurrentUser()->ID;
                $action->Finished = true;
                $action->write();
                $transition = $this->checkTransitions($action);
            }
        }

        // if the action finished, and there's only one available transition then
        // move onto that step - otherwise check if the workflow has finished.
        if ($transition) {
            $this->performTransition($transition);
        } else {
            // see if there are any transitions available, even if they are not valid.
            if ($action->Finished && !count($action->BaseAction()->Transitions())) {
                $this->WorkflowStatus  = 'Complete';
                $this->CurrentActionID = 0;
            } else {
                $this->WorkflowStatus = 'Paused';
            }

            $this->write();
        }
    }
public function execute()
    {
        if (!$this->CurrentActionID) {
            throw new Exception(
                sprintf(_t(
                    'WorkflowInstance.EXECUTE_EXCEPTION',
                    'Attempted to start an invalid workflow instance #%s!'
                ), $this->ID)
            );
        }

        $action     = $this->CurrentAction();
        $transition = false;

        // if the action has already finished, it means it has either multiple (or no
        // transitions at the time), so a subsequent check should be run.
        if ($action->Finished) {
            $transition = $this->checkTransitions($action);
        } else {
            $result = $action->BaseAction()->execute($this);

            // if the action was successful, then the action has finished running and
            // next transition should be run (if only one).
            // input.
            if ($result) {
                $action->MemberID = Security::getCurrentUser()->ID;
                $action->Finished = true;
                $action->write();
                $transition = $this->checkTransitions($action);
            }
        }

        // if the action finished, and there's only one available transition then
        // move onto that step - otherwise check if the workflow has finished.
        if ($transition) {
            $this->performTransition($transition);
        } else {
            // see if there are any transitions available, even if they are not valid.
            if ($action->Finished && !count($action->BaseAction()->Transitions())) {
                $this->WorkflowStatus  = 'Complete';
                $this->CurrentActionID = 0;
            } else {
                $this->WorkflowStatus = 'Paused';
            }

            $this->write();
        }
    }
public function execute ( ) { if ( ! $ this -> CurrentActionID ) { throw new Exception ( sprintf ( _t ( 'WorkflowInstance.EXECUTE_EXCEPTION' , 'Attempted to start an invalid workflow instance #%s!' ) , $ this -> ID ) ) ; } $ action = $ this -> CurrentAction ( ) ; $ transition = false ; // if the action has already finished, it means it has either multiple (or no // transitions at the time), so a subsequent check should be run. if ( $ action -> Finished ) { $ transition = $ this -> checkTransitions ( $ action ) ; } else { $ result = $ action -> BaseAction ( ) -> execute ( $ this ) ; // if the action was successful, then the action has finished running and // next transition should be run (if only one). // input. if ( $ result ) { $ action -> MemberID = Security :: getCurrentUser ( ) -> ID ; $ action -> Finished = true ; $ action -> write ( ) ; $ transition = $ this -> checkTransitions ( $ action ) ; } } // if the action finished, and there's only one available transition then // move onto that step - otherwise check if the workflow has finished. if ( $ transition ) { $ this -> performTransition ( $ transition ) ; } else { // see if there are any transitions available, even if they are not valid. if ( $ action -> Finished && ! count ( $ action -> BaseAction ( ) -> Transitions ( ) ) ) { $ this -> WorkflowStatus = 'Complete' ; $ this -> CurrentActionID = 0 ; } else { $ this -> WorkflowStatus = 'Paused' ; } $ this -> write ( ) ; } }
Execute this workflow. In rare cases this will actually execute all actions,
but typically, it will stop and wait for the user to input something

The basic process is to get the current action, and see whether it has been finished
by some process, if not it attempts to execute it.

If it has been finished, we check to see if there's some transitions to follow. If there's
only one transition, then we execute that immediately.

If there's multiple transitions, we just stop and wait for the user to manually
trigger a transition.

If there's no transitions, we make the assumption that we've finished the workflow and
mark it as such.
Execute this workflow . In rare cases this will actually execute all actions but typically it will stop and wait for the user to input something