/**
  * Save a scheduled transition. If the transition is executed, save as logged transition.
  */
 public function save()
 {
     // If executed, save as logged transition.
     if ($this->is_executed) {
         return parent::save();
     }
     // Avoid duplicate entries.
     $this->delete();
     // Save (insert or update) a record to the database based upon the schema.
     drupal_write_record('workflow_scheduled_transition', $this);
     // Get name of state.
     if ($state = WorkflowState::load($this->new_sid)) {
         $message = '@entity_title scheduled for state change to %state_name on %scheduled_date';
         $args = array('@entity_type' => $this->entity_type, '@entity_title' => $this->entity->title, '%state_name' => $state->label(), '%scheduled_date' => format_date($this->scheduled));
         $uri = entity_uri($this->entity_type, $this->entity);
         watchdog('workflow', $message, $args, WATCHDOG_NOTICE, l('view', $uri['path'] . '/workflow'));
         drupal_set_message(t($message, $args));
     }
 }
Exemple #2
0
 /**
  * Implements hook_field_delete() -> FieldItemInterface::delete().
  */
 public function delete($items)
 {
     global $user;
     $entity_type = $this->entity_type;
     $entity = $this->entity;
     $entity_id = entity_id($entity_type, $entity);
     $field_name = $this->field['field_name'];
     // Delete the record in {workflow_node} - not for Workflow Field.
     // Use a one-liner for better code analysis when grepping on old code.
     !$field_name ? workflow_delete_workflow_node_by_nid($entity_id) : NULL;
     // Add a history record in {workflow_node_history}.
     // @see drupal.org/node/2165349, comment by Bastlynn:
     // The reason for this history log upon delete is because Workflow module
     // has historically been used to track node states and accountability in
     // business environments where accountability for changes over time is
     // *absolutely* required. Think banking and/or particularly strict
     // retention policies for legal reasons.
     //
     // However, a deleted nid may be re-used under certain circumstances:
     // e.g., working with InnoDB or after restart the DB server.
     // This may cause that old history is associated with a new node.
     $old_sid = _workflow_get_sid_by_items($items);
     $new_sid = (int) WORKFLOW_DELETION;
     $comment = t('Entity deleted.');
     $transition = new WorkflowTransition();
     $transition->setValues($entity_type, $entity, $field_name, $old_sid, $new_sid, $user->uid, REQUEST_TIME, $comment);
     $transition->save();
     // Delete all records for this node in {workflow_scheduled_transition}.
     foreach (WorkflowScheduledTransition::load($entity_type, $entity_id, $field_name) as $scheduled_transition) {
         $scheduled_transition->delete();
     }
 }
 /**
  * Save a scheduled transition. If the transition is executed, save in history.
  */
 public function save()
 {
     // If executed, save in history.
     if ($this->is_executed) {
         // Be careful, we are not a WorkflowScheduleTransition anymore!
         $this->entityType = 'WorkflowTransition';
         $this->setUp();
         return parent::save();
         // <--- exit !!
     }
     // Since we do not have an entity_id here, we cannot use entity_delete.
     // @todo: Add an 'entity id' to WorkflowScheduledTransition entity class.
     // $result = parent::save();
     // Avoid duplicate entries.
     $clone = clone $this;
     $clone->delete();
     // Save (insert or update) a record to the database based upon the schema.
     drupal_write_record('workflow_scheduled_transition', $this);
     // Create user message.
     if ($state = $this->getNewState()) {
         $entity_type = $this->entity_type;
         $entity = $this->getEntity();
         $message = '%entity_title scheduled for state change to %state_name on %scheduled_date';
         $args = array('@entity_type' => $entity_type, '%entity_title' => entity_label($entity_type, $entity), '%state_name' => entity_label('WorkflowState', $state), '%scheduled_date' => format_date($this->scheduled));
         $uri = entity_uri($entity_type, $entity);
         watchdog('workflow', $message, $args, WATCHDOG_NOTICE, l('view', $uri['path'] . '/workflow'));
         drupal_set_message(t($message, $args));
     }
 }