Exemplo n.º 1
0
 /**
  * Applies the differences defined in $dbSchemaDiff to the database referenced by $db.
  *
  * This method uses {@link convertDiffToDDL} to create SQL for the
  * differences and then executes the returned SQL statements on the
  * database handler $db.
  *
  * @todo check for failed transaction
  *
  * @param ezcDbHandler    $db
  * @param ezcDbSchemaDiff $dbSchemaDiff
  */
 public function applyDiffToDb(ezcDbHandler $db, ezcDbSchemaDiff $dbSchemaDiff)
 {
     $db->beginTransaction();
     foreach ($this->convertDiffToDDL($dbSchemaDiff) as $query) {
         $db->exec($query);
     }
     $db->commit();
 }
Exemplo n.º 2
0
 /**
  * End workflow execution.
  *
  * @throws ezcDbException
  */
 protected function doEnd()
 {
     $this->cleanupTable('execution');
     $this->cleanupTable('execution_state');
     if (!$this->isCancelled()) {
         $this->db->commit();
     }
 }
 /**
  * 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();
 }
Exemplo 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();
 }