Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixes for #6 and #7 #10

Merged
merged 1 commit into from

2 participants

@koenedaele

Fixes for working with postgresql and sequences in general.

What's changed:

  • WorkFlowOptions has methods like nodeSequence(), executionSequence()
  • Fixed #6 by using a subselect for selecting max version. Not tested with other databases.
  • Changed DefintionStorage and DoctrineExcution to use sequences if the platform prefers this

I've tried to stick to your coding style. Feel free to reformat stuff.

I haven't run the unit tests because I didn't have the ezcWorkflow Tests handy (I installed via pear).

@beberlei beberlei merged commit 0a625fb into beberlei:master
@beberlei
Owner

Thank you very much for this.

This was referenced
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
54 lib/DoctrineExtensions/Workflow/DefinitionStorage.php
@@ -294,13 +294,26 @@ public function save( \ezcWorkflow $workflow )
), array('workflow_id' => $workflow->id)
);
} else {
- $this->conn->insert($this->options->workflowTable(), array(
+ $data = array(
'workflow_name' => $workflow->name,
'workflow_version' => $workflowVersion,
'workflow_created' => $date->format($platform->getDateTimeFormatString()),
'workflow_outdated' => 0,
- ));
- $workflow->id = (int)$this->conn->lastInsertId();
+ );
+ // For sequences: get id before insert
+ if ( $platform->prefersSequences( ) ) {
+ $id = (int) $this->conn->fetchColumn($platform->getSequenceNextValSQL($this->options->workflowSequence()));
+ $data['workflow_id'] = $id;
+ $workflow->id = $id;
+ }
+
+ $this->conn->insert($this->options->workflowTable(), $data);
+
+ if ( $platform->prefersIdentityColumns( ) ) {
+ $workflow->id = (int)$this->conn->lastInsertId();
+ }
+
+
$workflow->definitionStorage = $this;
}
@@ -318,13 +331,23 @@ public function save( \ezcWorkflow $workflow )
'node_configuration' => $this->options->getSerializer()->serialize( $node->getConfiguration() ),
), array('node_id' => $nodeId));
} else {
- $this->conn->insert($this->options->nodeTable(), array(
+ $data = array(
'workflow_id' => (int)$workflow->id,
'node_class' => get_class($node),
'node_configuration' => $this->options->getSerializer()->serialize( $node->getConfiguration() ),
- ));
+ );
+
+ if ( $platform->prefersSequences( ) ) {
+ $nodeId = (int) $this->conn->fetchColumn($platform->getSequenceNextValSQL($this->options->nodeSequence()));
+ $data['node_id'] = $nodeId;
+ }
+
+ $this->conn->insert($this->options->nodeTable(), $data);
+
+ if ( $platform->prefersIdentityColumns( ) ) {
+ $nodeId = (int)$this->conn->lastInsertId();
+ }
- $nodeId = (int)$this->conn->lastInsertId();
}
$nodeMap[$nodeId] = $node;
@@ -359,10 +382,18 @@ public function save( \ezcWorkflow $workflow )
}
}
- $this->conn->insert($this->options->nodeConnectionTable(), array(
+ $data = array(
'incoming_node_id' => $incomingNodeId,
'outgoing_node_id' => $outgoingNodeId,
- ));
+ );
+
+ if ( $platform->prefersSequences( ) ) {
+ $id = (int) $this->conn->fetchColumn($platform->getSequenceNextValSQL($this->options->nodeConnectionSequence()));
+ $data['id'] = $id;
+ }
+
+ $this->conn->insert($this->options->nodeConnectionTable(), $data );
+
}
}
unset($nodeMap);
@@ -390,10 +421,13 @@ protected function getCurrentVersion($name)
{
$platform = $this->conn->getDatabasePlatform();
- $sql = "SELECT MAX(workflow_version) AS version FROM " . $this->options->workflowTable() . " ".
- "WHERE workflow_name = ? " . $platform->getForUpdateSQL();
+ $sql = "SELECT workflow_version AS version FROM " . $this->options->workflowTable() . " ".
+ "WHERE workflow_name = ? " .
+ " AND workflow_version = ( SELECT MAX(workflow_version) FROM " . $this->options->workflowTable( ) . " WHERE workflow_name = ? )" .
+ $platform->getForUpdateSQL();
$stmt = $this->conn->prepare($sql);
$stmt->bindParam(1, $name);
+ $stmt->bindParam(2, $name);
$stmt->execute();
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
View
10 lib/DoctrineExtensions/Workflow/DoctrineExecution.php
@@ -75,10 +75,16 @@ protected function doStart($parentId)
'execution_next_thread_id' => (int)$this->nextThreadId,
'execution_next_poll_date' => $executionNextPollDate,
);
+ if ( $platform->prefersSequences( ) ) {
+ $data['execution_id'] = (int) $this->conn->fetchColumn($platform->getSequenceNextValSQL($this->options->executionSequence()));
+ $this->id = $data['execution_id'];
+ }
$this->conn->insert($this->options->executionTable(), $data);
// execution_id
- $this->id = (int)$this->conn->lastInsertId();
+ if ( !$platform->prefersSequences( ) ) {
+ $this->id = (int)$this->conn->lastInsertId();
+ }
}
protected function doResume()
@@ -261,4 +267,4 @@ protected function saveToVariableHandlers()
}
}
}
-}
+}
View
36 lib/DoctrineExtensions/Workflow/SchemaBuilder.php
@@ -4,6 +4,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Table;
+use Doctrine\DBAL\Schema\Schema;
class SchemaBuilder
{
@@ -46,10 +47,7 @@ public function getWorkflowSchema(WorkflowOptions $options)
$schema = new \Doctrine\DBAL\Schema\Schema();
$workflowTable = $schema->createTable($options->workflowTable());
- $columnOptions = array();
- if ($this->conn->getDatabasePlatform()->prefersIdentityColumns()) {
- $columnOptions = array('autoincrement' => true);
- }
+ $columnOptions = $this->_handlePrimaryKey($schema, $options->workflowTable(), $options->workflowSequence() );
$workflowTable->addColumn('workflow_id', 'integer', $columnOptions);
$workflowTable->addColumn('workflow_name', 'string');
$workflowTable->addColumn('workflow_version', 'integer');
@@ -59,10 +57,7 @@ public function getWorkflowSchema(WorkflowOptions $options)
$workflowTable->addUniqueIndex(array('workflow_name', 'workflow_version'));
$nodeTable = $schema->createTable($options->nodeTable());
- $columnOptions = array();
- if ($this->conn->getDatabasePlatform()->prefersIdentityColumns()) {
- $columnOptions = array('autoincrement' => true);
- }
+ $columnOptions = $this->_handlePrimaryKey($schema, $options->nodeTable(), $options->nodeSequence() );
$nodeTable->addColumn('node_id', 'integer', $columnOptions);
$nodeTable->addColumn('workflow_id', 'integer');
$nodeTable->addColumn('node_class', 'string');
@@ -72,10 +67,7 @@ public function getWorkflowSchema(WorkflowOptions $options)
$nodeTable->addForeignKeyConstraint($options->workflowTable(), array('workflow_id'), array('workflow_id'), array('onDelete' => 'CASCADE'));
$connectionTable = $schema->createTable($options->nodeConnectionTable());
- $columnOptions = array();
- if ($this->conn->getDatabasePlatform()->prefersIdentityColumns()) {
- $columnOptions = array('autoincrement' => true);
- }
+ $columnOptions = $this->_handlePrimaryKey($schema, $options->nodeConnectionTable(), $options->nodeConnectionSequence() );
$connectionTable->addColumn('id', 'integer', $columnOptions);
$connectionTable->addColumn('incoming_node_id', 'integer');
$connectionTable->addColumn('outgoing_node_id', 'integer');
@@ -91,10 +83,7 @@ public function getWorkflowSchema(WorkflowOptions $options)
$variableHandlerTable->addForeignKeyconstraint($options->workflowTable(), array('workflow_id'), array('workflow_id'));
$executionTable = $schema->createTable($options->executionTable());
- $columnOptions = array();
- if ($this->conn->getDatabasePlatform()->prefersIdentityColumns()) {
- $columnOptions = array('autoincrement' => true);
- }
+ $columnOptions = $this->_handlePrimaryKey($schema, $options->executionTable(), $options->executionSequence() );
$executionTable->addColumn('execution_id', 'integer', $columnOptions);
$executionTable->addColumn('workflow_id', 'integer');
$executionTable->addColumn('execution_parent', 'integer', array('notnull' => false));
@@ -124,4 +113,17 @@ public function getWorkflowSchema(WorkflowOptions $options)
return $schema;
}
-}
+
+ protected function _handlePrimaryKey(Schema $schema, $tableName, $sequenceName = null)
+ {
+ $columnOptions = array();
+ if ($this->conn->getDatabasePlatform()->prefersIdentityColumns()) {
+ $columnOptions = array('autoincrement' => true);
+ } elseif ($this->conn->getDatabasePlatform( )->prefersSequences()) {
+ $sequence = $schema->createSequence($sequenceName);
+ // Doens't work because of the ordering used by Doctrine in dropping tables.
+ //$columnOptions = array( 'default' => "nextval('" . $sequenceName . "')" );
+ }
+ return $columnOptions;
+ }
+}
View
22 lib/DoctrineExtensions/Workflow/WorkflowOptions.php
@@ -60,16 +60,31 @@ public function workflowTable()
return $this->prefix . 'workflow';
}
+ public function workflowSequence( )
+ {
+ return $this->workflowTable() . '_workflow_id_seq';
+ }
+
public function nodeTable()
{
return $this->prefix . 'node';
}
+ public function nodeSequence( )
+ {
+ return $this->nodeTable() . '_node_id_seq';
+ }
+
public function nodeConnectionTable()
{
return $this->prefix . 'node_connection';
}
+ public function nodeConnectionSequence()
+ {
+ return $this->nodeConnectionTable() . '_id_seq';
+ }
+
public function variableHandlerTable()
{
return $this->prefix . 'variable_handler';
@@ -80,6 +95,11 @@ public function executionTable()
return $this->prefix . 'execution';
}
+ public function executionSequence()
+ {
+ return $this->executionTable() . '_execution_id_seq';
+ }
+
public function executionStateTable()
{
return $this->prefix . 'execution_state';
@@ -105,4 +125,4 @@ public function getSerializer()
{
return $this->serializer;
}
-}
+}
Something went wrong with that request. Please try again.