Exemple #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();
 }
 /**
  * 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();
 }
 /**
  * Creates the tables contained in $schema in the database that is related to $db
  *
  * This method takes the table definitions from $schema and will create the
  * tables according to this definition in the database that is references
  * by the $db handler. If tables with the same name as contained in the
  * definitions already exist they will be removed and recreated with the
  * new definition.
  *
  * @param ezcDbHandler $db
  * @param ezcDbSchema  $dbSchema
  */
 public function saveToDb(ezcDbHandler $db, ezcDbSchema $dbSchema)
 {
     $db->beginTransaction();
     foreach ($this->convertToDDL($dbSchema) as $query) {
         if ($this->isQueryAllowed($db, $query)) {
             $db->exec($query);
         }
     }
     $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.
     $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();
 }
Exemple #5
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, $db) as $query) {
         if ($this->isQueryAllowed($db, $query)) {
             $db->exec($query);
         } else {
             if (strstr($query, 'AUTO_INCREMENT')) {
                 $db->commit();
                 $db->beginTransaction();
                 if (preg_match("/ALTER TABLE (.*) MODIFY (.*?) (.*) AUTO_INCREMENT/", $query, $matches)) {
                     $tableName = trim($matches[1], '"');
                     $autoIncrementFieldName = trim($matches[2], '"');
                     $autoIncrementFieldType = trim($matches[3], '"');
                     $this->addAutoIncrementField($db, $tableName, $autoIncrementFieldName, $autoIncrementFieldType);
                 }
             }
             $db->commit();
             $db->beginTransaction();
         }
     }
     $db->commit();
 }
Exemple #6
0
 /**
  * Resume workflow execution.
  *
  * @throws ezcDbException
  */
 protected function doResume()
 {
     $this->db->beginTransaction();
 }
Exemple #7
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) {
         if ($this->isQueryAllowed($db, $query)) {
             $db->exec($query);
         } else {
             // SQLite don't support SQL clause for removing columns
             // perform emulation for this
             if (strstr($query, 'DROP COLUMN')) {
                 $db->commit();
                 $db->beginTransaction();
                 try {
                     preg_match("/ALTER TABLE (.*) DROP COLUMN (.*)/", $query, $matches);
                     if (!$matches) {
                         throw new ezcDbSchemaSqliteDropFieldException("Can't fetch field for droping from SQL query: {$query}");
                     }
                     $tableName = trim($matches[1], "'");
                     $dropFieldName = trim($matches[2], "'");
                     $this->dropField($db, $tableName, $dropFieldName);
                 } catch (ezcDbSchemaSqliteDropFieldException $e) {
                 }
                 $db->commit();
                 $db->beginTransaction();
             } else {
                 if (strstr($query, 'CHANGE')) {
                     $db->commit();
                     $db->beginTransaction();
                     try {
                         preg_match("/ALTER TABLE (.*) CHANGE (.*?) (.*?) (.*)/", $query, $matches);
                         $tableName = trim($matches[1], "'");
                         $changeFieldName = trim($matches[2], "'");
                         $changeFieldNewName = trim($matches[3], "'");
                         $changeFieldNewType = $matches[4];
                         $this->changeField($db, $tableName, $changeFieldName, $changeFieldNewName, $changeFieldNewType);
                     } catch (ezcDbSchemaSqliteDropFieldException $e) {
                     }
                     $db->commit();
                     $db->beginTransaction();
                 }
             }
         }
     }
     $db->commit();
 }
Exemple #8
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) {
         if ($this->isQueryAllowed($db, $query)) {
             $db->exec($query);
         } else {
             // workarounds for SQL syntax
             // "ALTER TABLE tab ALTER col TYPE type"
             // and "ALTER TABLE tab ADD col type NOT NULL"
             // that works in PostgreSQL 8.x but not
             // supported in PostgreSQL 7.x
             if (preg_match("/ALTER TABLE (.*) ALTER (.*) TYPE (.*) USING CAST\\((.*)\\)/", $query, $matches)) {
                 $tableName = trim($matches[1], '"');
                 $fieldName = trim($matches[2], '"');
                 $fieldType = trim($matches[3], '"');
                 $this->changeField($db, $tableName, $fieldName, $fieldType);
             } else {
                 if (preg_match("/ALTER TABLE (.*) ADD (.*) (.*) NOT NULL/", $query, $matches)) {
                     $tableName = trim($matches[1], '"');
                     $fieldName = trim($matches[2], '"');
                     $fieldType = trim($matches[3], '"');
                     $this->addField($db, $tableName, $fieldName, $fieldType);
                 }
             }
         }
     }
     $db->commit();
 }
Exemple #9
0
 /**
  * Resume workflow execution.
  *
  * @throws ezcDbException
  */
 protected function doResume()
 {
     $this->db->beginTransaction();
     $this->cleanupTable('execution_state');
 }