You are here

public function WorkflowTransitionController::save in Workflow 7.2

Insert (no update) a transition.

deprecated workflow_insert_workflow_node_history() --> WorkflowTransition::save()

Overrides EntityAPIController::save

File

includes/Entity/WorkflowTransition.php, line 708
Contains workflow\includes\Entity\WorkflowTransition. Contains workflow\includes\Entity\WorkflowTransitionController.

Class

WorkflowTransitionController
Implements a controller class for WorkflowTransition.

Code

public function save($entity, DatabaseTransaction $transaction = NULL) {

  // Check for no transition.
  if ($entity->old_sid == $entity->new_sid) {
    if (!$entity->comment) {

      // Write comment into history though.
      return;
    }
  }
  if (empty($entity->hid)) {

    // Insert the transition. Make sure it hasn't already been inserted.
    $last_history = workflow_transition_load_single($entity->entity_type, $entity->entity_id, $entity->field_name, $entity->language);
    if ($last_history && $last_history->stamp == REQUEST_TIME && $last_history->new_sid == $entity->new_sid) {
      return;
    }
    else {
      unset($entity->hid);
      $entity->stamp = isset($entity->stamp) ? $entity->stamp : REQUEST_TIME;
      return parent::save($entity, $transaction);
    }
  }
  else {

    // Update the transition.
    return parent::save($entity, $transaction);
  }
}