Пример #1
0
 /**
  * Suspend workflow execution.
  *
  * @throws ezcDbException
  */
 protected function doSuspend()
 {
     $this->cleanupTable('execution_state');
     $query = $this->db->createUpdateQuery();
     $query->update($this->db->quoteIdentifier($this->options['prefix'] . 'execution'))->where($query->expr->eq($this->db->quoteIdentifier('execution_id'), $query->bindValue((int) $this->id)))->set($this->db->quoteIdentifier('execution_suspended'), $query->bindValue(time()))->set($this->db->quoteIdentifier('execution_variables'), $query->bindValue(ezcWorkflowDatabaseUtil::serialize($this->variables)))->set($this->db->quoteIdentifier('execution_waiting_for'), $query->bindValue(ezcWorkflowDatabaseUtil::serialize($this->waitingFor)))->set($this->db->quoteIdentifier('execution_threads'), $query->bindValue(ezcWorkflowDatabaseUtil::serialize($this->threads)))->set($this->db->quoteIdentifier('execution_next_thread_id'), $query->bindValue((int) $this->nextThreadId));
     $statement = $query->prepare();
     $statement->execute();
     foreach ($this->activatedNodes as $node) {
         $query = $this->db->createInsertQuery();
         $query->insertInto($this->db->quoteIdentifier($this->options['prefix'] . 'execution_state'))->set($this->db->quoteIdentifier('execution_id'), $query->bindValue((int) $this->id))->set($this->db->quoteIdentifier('node_id'), $query->bindValue((int) $node->getId()))->set($this->db->quoteIdentifier('node_state'), $query->bindValue(ezcWorkflowDatabaseUtil::serialize($node->getState())))->set($this->db->quoteIdentifier('node_activated_from'), $query->bindValue(ezcWorkflowDatabaseUtil::serialize($node->getActivatedFrom())))->set($this->db->quoteIdentifier('node_thread_id'), $query->bindValue((int) $node->getThreadId()));
         $statement = $query->prepare();
         $statement->execute();
     }
     $this->db->commit();
 }
Пример #2
0
 public function serialize($value)
 {
     return \ezcWorkflowDatabaseUtil::serialize($value);
 }
 /**
  * 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();
 }
Пример #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();
 }