コード例 #1
0
 /**
  * Saves data to execution data handlers.
  */
 protected function saveToVariableHandlers()
 {
     foreach ($this->workflow->getVariableHandlers() as $variableName => $className) {
         if (isset($this->variables[$variableName])) {
             $object = $this->options->getWorkflowFactory()->createVariableHandler($className);
             $object->save($this, $variableName, $this->variables[$variableName]);
         }
     }
 }
コード例 #2
0
 /**
  *
  * @param  int $workflowId
  * @param  string $workflowName
  * @param  int $workflowVersion
  * @return \ezcWorkflow
  */
 protected function loadWorkflow($workflowId, $workflowName, $workflowVersion)
 {
     $workflowId = (int) $workflowId;
     $sql = "SELECT node_id, node_class, node_configuration FROM " . $this->options->nodeTable() . " WHERE workflow_id = ?";
     $stmt = $this->conn->prepare($sql);
     $stmt->bindParam(1, $workflowId);
     $stmt->execute();
     $result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $this->workflowNodeIds[$workflowId] = array();
     // Create node objects.
     foreach ($result as $node) {
         $node = array_change_key_case($node, \CASE_LOWER);
         $configuration = $this->options->getSerializer()->unserialize($node['node_configuration'], null);
         if (is_null($configuration)) {
             $configuration = \ezcWorkflowUtil::getDefaultConfiguration($node['node_class']);
         }
         $nodes[$node['node_id']] = $this->options->getWorkflowFactory()->createNode($node['node_class'], $configuration);
         $nodes[$node['node_id']]->setId($node['node_id']);
         $this->nodeMap[spl_object_hash($nodes[$node['node_id']])] = $node['node_id'];
         $this->workflowNodeIds[$workflowId][] = $node['node_id'];
         if ($nodes[$node['node_id']] instanceof \ezcWorkflowNodeFinally && !isset($finallyNode)) {
             $finallyNode = $nodes[$node['node_id']];
         } else {
             if ($nodes[$node['node_id']] instanceof \ezcWorkflowNodeEnd && !isset($defaultEndNode)) {
                 $defaultEndNode = $nodes[$node['node_id']];
             } else {
                 if ($nodes[$node['node_id']] instanceof \ezcWorkflowNodeStart && !isset($startNode)) {
                     $startNode = $nodes[$node['node_id']];
                 }
             }
         }
     }
     if (!isset($startNode) || !isset($defaultEndNode)) {
         throw new \ezcWorkflowDefinitionStorageException('Could not load workflow definition.');
     }
     $sql = "SELECT nc.outgoing_node_id, nc.incoming_node_id FROM " . $this->options->nodeConnectionTable() . " nc " . "INNER JOIN " . $this->options->nodeTable() . " n ON n.node_id = nc.incoming_node_id WHERE n.workflow_id = ?";
     $stmt = $this->conn->prepare($sql);
     $stmt->bindParam(1, $workflowId);
     $stmt->execute();
     $connections = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     foreach ($connections as $connection) {
         $connection = array_change_key_case($connection, \CASE_LOWER);
         $nodes[$connection['incoming_node_id']]->addOutNode($nodes[$connection['outgoing_node_id']]);
     }
     if (!isset($finallyNode) || count($finallyNode->getInNodes()) > 0) {
         $finallyNode = null;
     }
     // Create workflow object and add the node objects to it.
     $workflowClassName = $this->options->workflowClassName();
     $workflow = new $workflowClassName($workflowName, $startNode, $defaultEndNode, $finallyNode);
     $workflow->definitionStorage = $this;
     $workflow->id = (int) $workflowId;
     $workflow->version = (int) $workflowVersion;
     $sql = "SELECT variable, class FROM " . $this->options->variableHandlerTable() . " WHERE workflow_id = ?";
     $stmt = $this->conn->prepare($sql);
     $stmt->bindParam(1, $workflowId);
     $stmt->execute();
     $result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $nodes = array();
     if ($result !== false) {
         foreach ($result as $variableHandler) {
             $workflow->addVariableHandler($variableHandler['variable'], $variableHandler['class']);
         }
     }
     // Verify the loaded workflow.
     $workflow->verify();
     return $workflow;
 }