Ejemplo n.º 1
0
 /**
  * Load execution state.
  *
  * @param int $executionId  ID of the execution to load.
  * @throws ezcWorkflowExecutionException
  */
 protected function loadExecution($executionId)
 {
     $query = $this->db->createSelectQuery();
     $query->select($this->db->quoteIdentifier('workflow_id'))->select($this->db->quoteIdentifier('execution_variables'))->select($this->db->quoteIdentifier('execution_threads'))->select($this->db->quoteIdentifier('execution_next_thread_id'))->select($this->db->quoteIdentifier('execution_waiting_for'))->from($this->db->quoteIdentifier($this->options['prefix'] . 'execution'))->where($query->expr->eq($this->db->quoteIdentifier('execution_id'), $query->bindValue((int) $executionId)));
     $stmt = $query->prepare();
     $stmt->execute();
     $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
     if ($result === false || empty($result)) {
         throw new ezcWorkflowExecutionException('Could not load execution state.');
     }
     $this->id = $executionId;
     $this->nextThreadId = $result[0]['execution_next_thread_id'];
     $this->threads = ezcWorkflowDatabaseUtil::unserialize($result[0]['execution_threads']);
     $this->variables = ezcWorkflowDatabaseUtil::unserialize($result[0]['execution_variables']);
     $this->waitingFor = ezcWorkflowDatabaseUtil::unserialize($result[0]['execution_waiting_for']);
     $workflowId = $result[0]['workflow_id'];
     $this->workflow = $this->properties['definitionStorage']->loadById($workflowId);
     $query = $this->db->createSelectQuery();
     $query->select($this->db->quoteIdentifier('node_id'))->select($this->db->quoteIdentifier('node_state'))->select($this->db->quoteIdentifier('node_activated_from'))->select($this->db->quoteIdentifier('node_thread_id'))->from($this->db->quoteIdentifier($this->options['prefix'] . 'execution_state'))->where($query->expr->eq($this->db->quoteIdentifier('execution_id'), $query->bindValue((int) $executionId)));
     $stmt = $query->prepare();
     $stmt->execute();
     $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $active = array();
     foreach ($result as $row) {
         $active[$row['node_id']] = array('activated_from' => ezcWorkflowDatabaseUtil::unserialize($row['node_activated_from']), 'state' => ezcWorkflowDatabaseUtil::unserialize($row['node_state'], null), 'thread_id' => $row['node_thread_id']);
     }
     foreach ($this->workflow->nodes as $node) {
         $nodeId = $node->getId();
         if (isset($active[$nodeId])) {
             $node->setActivationState(ezcWorkflowNode::WAITING_FOR_EXECUTION);
             $node->setThreadId($active[$nodeId]['thread_id']);
             $node->setState($active[$nodeId]['state'], null);
             $node->setActivatedFrom($active[$nodeId]['activated_from']);
             $this->activate($node, false);
         }
     }
     $this->cancelled = false;
     $this->ended = false;
     $this->loaded = true;
     $this->resumed = false;
     $this->suspended = true;
 }
Ejemplo n.º 2
0
 public function unserialize($value, $defaultValue = array())
 {
     return \ezcWorkflowDatabaseUtil::unserialize($value, $defaultValue);
 }
Ejemplo n.º 3
0
 /**
  * Save a workflow definition to the database.
  *
  * @param  ezcWorkflow $workflow
  * @throws ezcWorkflowDefinitionStorageException
  * @throws ezcDbException
  */
 public function save(ezcWorkflow $workflow)
 {
     // Verify the workflow.
     $workflow->verify();
     $this->db->beginTransaction();
     // Calculate new version number.
     $workflowVersion = $this->getCurrentVersionNumber($workflow->name) + 1;
     // Write workflow table row.
     $query = $this->db->createInsertQuery();
     $query->insertInto($this->db->quoteIdentifier($this->options['prefix'] . 'workflow'))->set($this->db->quoteIdentifier('workflow_name'), $query->bindValue($workflow->name))->set($this->db->quoteIdentifier('workflow_version'), $query->bindValue((int) $workflowVersion))->set($this->db->quoteIdentifier('workflow_created'), $query->bindValue(time()));
     $statement = $query->prepare();
     $statement->execute();
     $workflow->definitionStorage = $this;
     $workflow->id = (int) $this->db->lastInsertId('workflow_workflow_id_seq');
     $workflow->version = (int) $workflowVersion;
     // Write node table rows.
     $nodeMap = array();
     foreach ($workflow->nodes as $node) {
         $query = $this->db->createInsertQuery();
         $query->insertInto($this->db->quoteIdentifier($this->options['prefix'] . 'node'))->set($this->db->quoteIdentifier('workflow_id'), $query->bindValue((int) $workflow->id))->set($this->db->quoteIdentifier('node_class'), $query->bindValue(get_class($node)))->set($this->db->quoteIdentifier('node_configuration'), $query->bindValue(ezcWorkflowDatabaseUtil::serialize($node->getConfiguration())));
         $statement = $query->prepare();
         $statement->execute();
         $nodeMap[$this->db->lastInsertId($this->db->quoteIdentifier('node_node_id_seq'))] = $node;
     }
     // Connect node table rows.
     foreach ($workflow->nodes as $node) {
         foreach ($node->getOutNodes() as $outNode) {
             $incomingNodeId = null;
             $outgoingNodeId = null;
             foreach ($nodeMap as $_id => $_node) {
                 if ($_node === $node) {
                     $incomingNodeId = $_id;
                 } else {
                     if ($_node === $outNode) {
                         $outgoingNodeId = $_id;
                     }
                 }
                 if ($incomingNodeId !== NULL && $outgoingNodeId !== NULL) {
                     break;
                 }
             }
             $query = $this->db->createInsertQuery();
             $query->insertInto($this->db->quoteIdentifier($this->options['prefix'] . 'node_connection'))->set($this->db->quoteIdentifier('incoming_node_id'), $query->bindValue($incomingNodeId))->set($this->db->quoteIdentifier('outgoing_node_id'), $query->bindValue($outgoingNodeId));
             $statement = $query->prepare();
             $statement->execute();
         }
     }
     unset($nodeMap);
     // Write variable handler rows.
     foreach ($workflow->getVariableHandlers() as $variable => $class) {
         $query = $this->db->createInsertQuery();
         $query->insertInto($this->db->quoteIdentifier($this->options['prefix'] . 'variable_handler'))->set($this->db->quoteIdentifier('workflow_id'), $query->bindValue((int) $workflow->id))->set($this->db->quoteIdentifier('variable'), $query->bindValue($variable))->set($this->db->quoteIdentifier('class'), $query->bindValue($class));
         $statement = $query->prepare();
         $statement->execute();
     }
     $this->db->commit();
 }
Ejemplo n.º 4
0
 /**
  * Save a workflow definition to the database.
  *
  * @param  ezcWorkflow $workflow
  * @throws ezcWorkflowDefinitionStorageException
  * @throws ezcDbException
  */
 public function save(ezcWorkflow $workflow)
 {
     // Verify the workflow.
     $workflow->verify();
     $this->db->beginTransaction();
     // Calculate new version number.
     $workflowVersion = $this->getCurrentVersionNumber($workflow->name) + 1;
     // Write workflow table row.
     $query = $this->db->createInsertQuery();
     $query->insertInto($this->db->quoteIdentifier($this->options['prefix'] . 'workflow'))->set($this->db->quoteIdentifier('workflow_name'), $query->bindValue($workflow->name))->set($this->db->quoteIdentifier('workflow_version'), $query->bindValue((int) $workflowVersion))->set($this->db->quoteIdentifier('workflow_created'), $query->bindValue(time()));
     $statement = $query->prepare();
     $statement->execute();
     $workflow->definitionStorage = $this;
     $workflow->id = (int) $this->db->lastInsertId('workflow_workflow_id_seq');
     $workflow->version = (int) $workflowVersion;
     // Write node table rows.
     $nodes = $workflow->nodes;
     $keys = array_keys($nodes);
     $numNodes = count($nodes);
     for ($i = 0; $i < $numNodes; $i++) {
         $id = $keys[$i];
         $node = $nodes[$id];
         $query = $this->db->createInsertQuery();
         $query->insertInto($this->db->quoteIdentifier($this->options['prefix'] . 'node'))->set($this->db->quoteIdentifier('workflow_id'), $query->bindValue((int) $workflow->id))->set($this->db->quoteIdentifier('node_class'), $query->bindValue(get_class($node)))->set($this->db->quoteIdentifier('node_configuration'), $query->bindValue(ezcWorkflowDatabaseUtil::serialize($node->getConfiguration())));
         $statement = $query->prepare();
         $statement->execute();
         $node->setId($this->db->lastInsertId($this->db->quoteIdentifier('node_node_id_seq')));
     }
     // Connect node table rows.
     for ($i = 0; $i < $numNodes; $i++) {
         $id = $keys[$i];
         $node = $nodes[$id];
         foreach ($node->getOutNodes() as $outNode) {
             $query = $this->db->createInsertQuery();
             $query->insertInto($this->db->quoteIdentifier($this->options['prefix'] . 'node_connection'))->set($this->db->quoteIdentifier('incoming_node_id'), $query->bindValue((int) $node->getId()))->set($this->db->quoteIdentifier('outgoing_node_id'), $query->bindValue((int) $outNode->getId()));
             $statement = $query->prepare();
             $statement->execute();
         }
     }
     // Write variable handler rows.
     foreach ($workflow->getVariableHandlers() as $variable => $class) {
         $query = $this->db->createInsertQuery();
         $query->insertInto($this->db->quoteIdentifier($this->options['prefix'] . 'variable_handler'))->set($this->db->quoteIdentifier('workflow_id'), $query->bindValue((int) $workflow->id))->set($this->db->quoteIdentifier('variable'), $query->bindValue($variable))->set($this->db->quoteIdentifier('class'), $query->bindValue($class));
         $statement = $query->prepare();
         $statement->execute();
     }
     $this->db->commit();
 }