Пример #1
0
 /**
  * {@inheritdoc}
  */
 public static function executeScheduledTransitionsBetween($start = 0, $end = 0)
 {
     $clear_cache = FALSE;
     // If the time now is greater than the time to execute a transition, do it.
     foreach (WorkflowScheduledTransition::loadBetween($start, $end) as $scheduled_transition) {
         $field_name = $scheduled_transition->getFieldName();
         $entity = $scheduled_transition->getTargetEntity();
         // Make sure transition is still valid: the entity must still be in
         // the state it was in, when the transition was scheduled.
         // Scheduling on comments is a testing error, and leads to 'recoverable error'.
         $current_sid = '';
         if ($entity && $entity->getEntityTypeId() !== 'comment') {
             $current_sid = workflow_node_current_state($entity, $field_name);
         }
         if ($current_sid && $current_sid == $scheduled_transition->getFromSid()) {
             // If user didn't give a comment, create one.
             $comment = $scheduled_transition->getComment();
             if (empty($comment)) {
                 $scheduled_transition->addDefaultComment();
             }
             // Do transition. Force it because user who scheduled was checked.
             // The scheduled transition is not scheduled anymore, and is also deleted from DB.
             // A watchdog message is created with the result.
             $scheduled_transition->schedule(FALSE);
             $scheduled_transition->force(TRUE);
             workflow_execute_transition($scheduled_transition, TRUE);
             if (!$field_name) {
                 $clear_cache = TRUE;
             }
         } else {
             // Entity is not in the same state it was when the transition
             // was scheduled. Defer to the entity's current state and
             // abandon the scheduled transition.
             $scheduled_transition->delete();
         }
     }
     if ($clear_cache) {
         // Clear the cache so that if the transition resulted in a entity
         // being published, the anonymous user can see it.
         Cache::invalidateTags(array('rendered'));
     }
 }