예제 #1
0
$lastEventStatus = $process->attribute("last_event_status");
if ($http->hasPostVariable("RunProcess")) {
    //     $Module->redirectTo( $Module->functionURI( "process" ) . "/" . $WorkflowProcessID );
    //     return;
    if ($workflowEvent instanceof eZWorkflowEvent) {
        $eventType = $workflowEvent->eventType();
        $lastEventStatus = $eventType->execute($process, $workflowEvent);
    }
    $event_pos = $process->attribute("event_position");
    $next_event_pos = $event_pos + 1;
    $next_event_id = $workflow->fetchEventIndexed($next_event_pos);
    if ($next_event_id !== null) {
        $process->advance($next_event_id, $next_event_pos, $lastEventStatus);
        $workflowEvent = eZWorkflowEvent::fetch($next_event_id);
    } else {
        unset($workflowEvent);
        $workflowEvent = false;
        $process->advance();
    }
    $process->setAttribute("modified", time());
    $process->store();
}
$tpl->setVariable("event_status", eZWorkflowType::statusName($lastEventStatus));
$tpl->setVariable("current_workflow", $workflow);
$tpl->setVariable("current_event", $workflowEvent);
$Module->setTitle("Workflow process");
$tpl->setVariable("process", $process);
$tpl->setVariable("module", $Module);
$tpl->setVariable("http", $http);
$Result = array();
$Result['content'] = $tpl->fetch("design:workflow/process.tpl");
예제 #2
0
 function run(&$workflow, &$workflowEvent, &$eventLog)
 {
     $eventLog = array();
     eZDebugSetting::writeDebug('workflow-process', $workflowEvent, "workflowEvent in process->run beginning");
     $runCurrentEvent = true;
     $done = false;
     $workflowStatus = $this->attribute('status');
     eZDebugSetting::writeDebug('workflow-process', $workflowStatus, 'workflowStatus');
     $currentEventStatus = $this->attribute('event_status');
     // just temporary. needs to be removed from parameters
     if ($workflowEvent == null) {
         $workflowEvent = eZWorkflowEvent::fetch($this->attribute('event_id'));
     }
     switch ($currentEventStatus) {
         case eZWorkflowType::STATUS_DEFERRED_TO_CRON:
         case eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT:
         case eZWorkflowType::STATUS_FETCH_TEMPLATE:
         case eZWorkflowType::STATUS_FETCH_TEMPLATE_REPEAT:
         case eZWorkflowType::STATUS_REDIRECT:
         case eZWorkflowType::STATUS_REDIRECT_REPEAT:
         case eZWorkflowType::STATUS_WORKFLOW_RESET:
             if ($workflowEvent !== null) {
                 $activationDate = 0;
                 if ($this->hasAttribute('activation_date')) {
                     $activationDate = $this->attribute("activation_date");
                 }
                 eZDebugSetting::writeDebug('workflow-process', "Checking activation date");
                 if ($activationDate == 0) {
                     $eventType = $workflowEvent->eventType();
                     $eventLog[] = array("status" => $currentEventStatus, "status_text" => eZWorkflowType::statusName($currentEventStatus), "information" => $eventType->attribute("information"), "description" => $workflowEvent->attribute("description"), "type_name" => $eventType->attribute("name"), "type_group" => $eventType->attribute("group_name"));
                     if ($currentEventStatus == eZWorkflowType::STATUS_DEFERRED_TO_CRON || $currentEventStatus == eZWorkflowType::STATUS_FETCH_TEMPLATE || $currentEventStatus == eZWorkflowType::STATUS_REDIRECT) {
                         $runCurrentEvent = false;
                     }
                 } else {
                     if (time() < $activationDate) {
                         eZDebugSetting::writeDebug('workflow-process', "Date failed, not running events");
                         $eventType = $workflowEvent->eventType();
                         $eventLog[] = array("status" => $currentEventStatus, "status_text" => eZWorkflowType::statusName($currentEventStatus), "information" => $eventType->attribute("information"), "description" => $workflowEvent->attribute("description"), "type_name" => $eventType->attribute("name"), "type_group" => $eventType->attribute("group_name"));
                         $done = true;
                     } else {
                         eZDebugSetting::writeDebug('workflow-process', "Date ok, running events");
                         eZDebugSetting::writeDebug('workflow-process', $currentEventStatus, 'WORKFLOW_TYPE_STATUS');
                         if ($currentEventStatus == eZWorkflowType::STATUS_DEFERRED_TO_CRON || $currentEventStatus == eZWorkflowType::STATUS_FETCH_TEMPLATE || $currentEventStatus == eZWorkflowType::STATUS_REDIRECT) {
                             $runCurrentEvent = false;
                         }
                     }
                 }
             }
             break;
         default:
             break;
     }
     while (!$done) {
         if ($runCurrentEvent) {
             eZDebugSetting::writeDebug('workflow-process', "runCurrentEvent is true");
         } else {
             eZDebugSetting::writeDebug('workflow-process', "runCurrentEvent is false");
         }
         if ($workflowEvent != null) {
             //eZDebugSetting::writeDebug( 'workflow-process', $workflowEvent ,"workflowEvent  is not null" );
         } else {
             //eZDebugSetting::writeDebug( 'workflow-process', $workflowEvent ,"workflowEvent  is  null" );
         }
         if ($workflowEvent instanceof eZWorkflowEvent) {
             eZDebugSetting::writeDebug('workflow-process', get_class($workflowEvent), "workflowEvent class is ezworkflowevent");
         } else {
             if ($workflowEvent !== null) {
                 eZDebugSetting::writeDebug('workflow-process', get_class($workflowEvent), "workflowEvent class is not ezworkflowevent");
             }
         }
         eZDebugSetting::writeDebug('workflow-process', $done, "in while");
         if ($runCurrentEvent and $workflowEvent !== null and $workflowEvent instanceof eZWorkflowEvent) {
             $eventType = $workflowEvent->eventType();
             if ($eventType instanceof eZWorkflowType) {
                 $currentEventStatus = $eventType->execute($this, $workflowEvent);
                 $this->setAttribute("event_status", $currentEventStatus);
                 $workflowParameters = $this->attribute('parameter_list');
                 if (isset($workflowParameters['cleanup_list'])) {
                     $cleanupList = $workflowParameters['cleanup_list'];
                 } else {
                     unset($cleanupList);
                     $cleanupList = array();
                 }
                 if ($eventType->needCleanup()) {
                     $cleanupList[] = $workflowEvent->attribute('id');
                     $workflowParameters['cleanup_list'] = $cleanupList;
                     $this->setAttribute('parameters', serialize($workflowParameters));
                 }
                 eZDebugSetting::writeDebug('workflow-process', $currentEventStatus, "currentEventStatus");
                 switch ($currentEventStatus) {
                     case eZWorkflowType::STATUS_ACCEPTED:
                         $done = false;
                         $workflowStatus = eZWorkflow::STATUS_DONE;
                         break;
                     case eZWorkflowType::STATUS_WORKFLOW_DONE:
                         $done = true;
                         $workflowStatus = eZWorkflow::STATUS_DONE;
                         break;
                     case eZWorkflowType::STATUS_REJECTED:
                         $done = true;
                         $workflowStatus = eZWorkflow::STATUS_FAILED;
                         break;
                     case eZWorkflowType::STATUS_DEFERRED_TO_CRON:
                     case eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT:
                         if ($eventType->hasAttribute("activation_date")) {
                             $date = $eventType->attribute("activation_date");
                             $this->setAttribute("activation_date", $date);
                         }
                         $workflowStatus = eZWorkflow::STATUS_DEFERRED_TO_CRON;
                         $done = true;
                         break;
                     case eZWorkflowType::STATUS_FETCH_TEMPLATE:
                         $workflowStatus = eZWorkflow::STATUS_FETCH_TEMPLATE;
                         $done = true;
                         break;
                     case eZWorkflowType::STATUS_FETCH_TEMPLATE_REPEAT:
                         $workflowStatus = eZWorkflow::STATUS_FETCH_TEMPLATE_REPEAT;
                         $done = true;
                         break;
                     case eZWorkflowType::STATUS_REDIRECT:
                     case eZWorkflowType::STATUS_REDIRECT_REPEAT:
                         $workflowStatus = eZWorkflow::STATUS_REDIRECT;
                         $done = true;
                         $this->advance();
                         break;
                     case eZWorkflowType::STATUS_RUN_SUB_EVENT:
                         eZDebug::writeWarning("Run sub event not supported yet", "eZWorkflowProcess::run");
                         break;
                     case eZWorkflowType::STATUS_WORKFLOW_CANCELLED:
                         $done = true;
                         $this->advance();
                         $workflowStatus = eZWorkflow::STATUS_CANCELLED;
                         break;
                     case eZWorkflowType::STATUS_WORKFLOW_RESET:
                         $done = true;
                         $this->reset();
                         $workflowStatus = eZWorkflow::STATUS_RESET;
                         break;
                     case eZWorkflowType::STATUS_NONE:
                         eZDebug::writeWarning("Workflow executing status is eZWorkflowType::STATUS_NONE", "eZWorkflowProcess::run");
                         break;
                     default:
                         eZDebug::writeWarning("Unknown status '{$currentEventStatus}'", "eZWorkflowProcess::run");
                         break;
                 }
                 $eventLog[] = array("status" => $currentEventStatus, "status_text" => eZWorkflowType::statusName($currentEventStatus), "information" => $eventType->attribute("information"), "description" => $workflowEvent->attribute("description"), "type_name" => $eventType->attribute("name"), "type_group" => $eventType->attribute("group_name"));
             } else {
                 eZDebug::writeError("Expected an eZWorkFlowType object", "eZWorkflowProcess::run");
             }
         } else {
             eZDebugSetting::writeDebug('workflow-process', "Not running current event. Trying next");
         }
         $runCurrentEvent = true;
         // still not done
         if (!$done) {
             // fetch next event
             $event_pos = $this->attribute("event_position");
             $next_event_pos = $event_pos + 1;
             $next_event_id = $workflow->fetchEventIndexed($next_event_pos);
             if ($next_event_id !== null) {
                 eZDebugSetting::writeDebug('workflow-process', $event_pos, "workflow not done");
                 $this->advance($next_event_id, $next_event_pos, $currentEventStatus);
                 $workflowEvent = eZWorkflowEvent::fetch($next_event_id);
             } else {
                 $done = true;
                 unset($workflowEvent);
                 eZDebugSetting::writeDebug('workflow-process', $event_pos, "workflow done");
                 $workflowStatus = eZWorkflow::STATUS_DONE;
                 $this->advance();
             }
         }
     }
     $this->setAttribute("status", $workflowStatus);
     $this->setAttribute("modified", time());
     return $workflowStatus;
 }