Back to Workflow class

Method executeTransition

public bool
executeTransition
(array $pks, int $transitionId)
Executes a transition to change the current state in the association table
Parameters
  • int[] $pks The item IDs, which should use the transition
  • int $transitionId The transition which should be executed
Returns
  • bool
Class: Workflow
Project: Joomla

Method executeTransition - Source code

/**
 * Executes a transition to change the current state in the association table
 *
 * @param   integer[]  $pks           The item IDs, which should use the transition
 * @param   integer    $transitionId  The transition which should be executed
 *
 * @return  boolean
 */
public function executeTransition(array $pks, int $transitionId) : bool
{
    $pks = ArrayHelper::toInteger($pks);
    $pks = array_filter($pks);
    if (!\count($pks)) {
        return true;
    }
    $transition = $this->getValidTransition($pks, $transitionId);
    if (is_null($transition)) {
        return false;
    }
    $transition->options = new Registry($transition->options);
    // Check if the items can execute this transition
    foreach ($pks as $pk) {
        $assoc = $this->getAssociation($pk);
        // The transition has to be in the same workflow
        if (!\in_array($transition->from_stage_id, [$assoc->stage_id, -1]) || $transition->workflow_id !== $assoc->workflow_id) {
            return false;
        }
    }
    PluginHelper::importPlugin('workflow');
    $eventResult = $this->app->getDispatcher()->dispatch('onWorkflowBeforeTransition', AbstractEvent::create('onWorkflowBeforeTransition', ['eventClass' => 'Joomla\\CMS\\Event\\Workflow\\WorkflowTransitionEvent', 'subject' => $this, 'extension' => $this->extension, 'pks' => $pks, 'transition' => $transition, 'stopTransition' => false]));
    if ($eventResult->getArgument('stopTransition')) {
        return false;
    }
    $success = $this->updateAssociations($pks, (int) $transition->to_stage_id);
    if ($success) {
        $this->app->getDispatcher()->dispatch('onWorkflowAfterTransition', AbstractEvent::create('onWorkflowAfterTransition', ['eventClass' => 'Joomla\\CMS\\Event\\Workflow\\WorkflowTransitionEvent', 'subject' => $this, 'extension' => $this->extension, 'pks' => $pks, 'transition' => $transition]));
    }
    return $success;
}