/** * Start workflow execution. * * @param int $parentId * @throws ezcDbException */ protected function doStart($parentId) { $this->db->beginTransaction(); $query = $this->db->createInsertQuery(); $query->insertInto($this->db->quoteIdentifier($this->options['prefix'] . 'execution'))->set($this->db->quoteIdentifier('workflow_id'), $query->bindValue((int) $this->workflow->id))->set($this->db->quoteIdentifier('execution_parent'), $query->bindValue((int) $parentId))->set($this->db->quoteIdentifier('execution_started'), $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(); $this->id = (int) $this->db->lastInsertId('execution_execution_id_seq'); }
/** * Returns the integer value of the generated identifier for the new object. * Called right after execution of the insert query. * * @param ezcPersistentObjectDefinition $def * @param ezcDbHandler $db * @return int */ public function postSave(ezcPersistentObjectDefinition $def, ezcDbHandler $db) { $id = (int) $db->lastInsertId(); // check that the value was in fact successfully received. if ($db->errorCode() != 0) { return null; } return $id; }
/** * 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(); }
/** * Inserts a $fieldDefinition for $typeId. * * @param mixed $typeId * @param int $status * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDefinition * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageFieldDef * * @return mixed Field definition ID */ public function insertFieldDefinition($typeId, $status, FieldDefinition $fieldDefinition, StorageFieldDefinition $storageFieldDef) { $q = $this->dbHandler->createInsertQuery(); $q->insertInto($this->dbHandler->quoteTable('ezcontentclass_attribute')); $q->set($this->dbHandler->quoteColumn('id'), isset($fieldDefinition->id) ? $q->bindValue($fieldDefinition->id, null, \PDO::PARAM_INT) : $this->dbHandler->getAutoIncrementValue('ezcontentclass_attribute', 'id'))->set($this->dbHandler->quoteColumn('contentclass_id'), $q->bindValue($typeId, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('version'), $q->bindValue($status, null, \PDO::PARAM_INT)); $this->setCommonFieldColumns($q, $fieldDefinition, $storageFieldDef); $q->prepare()->execute(); if (!isset($fieldDefinition->id)) { return $this->dbHandler->lastInsertId($this->dbHandler->getSequenceName('ezcontentclass_attribute', 'id')); } return $fieldDefinition->id; }
/** * 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(); }
/** * Returns next value for "id" column. * * @return mixed */ public function getNextId() { $sequence = $this->dbHandler->getSequenceName('ezurlalias_ml_incr', 'id'); /** @var $query \ezcQueryInsert */ $query = $this->dbHandler->createInsertQuery(); $query->insertInto($this->dbHandler->quoteTable("ezurlalias_ml_incr")); // ezcDatabase does not abstract the "auto increment id" // INSERT INTO ezurlalias_ml_incr VALUES(DEFAULT) is not an option due // to this mysql bug: http://bugs.mysql.com/bug.php?id=42270 // as a result we are forced to check which database is currently used // to generate the correct SQL query // see https://jira.ez.no/browse/EZP-20652 if ($this->dbHandler->getName() === 'pgsql') { $query->set($this->dbHandler->quoteColumn("id"), "nextval('{$sequence}')"); } else { $query->set($this->dbHandler->quoteColumn("id"), $query->bindValue(null, null, \PDO::PARAM_NULL)); } $query->prepare()->execute(); return $this->dbHandler->lastInsertId($sequence); }