diff --git a/lib/DoctrineExtensions/Workflow/DefinitionStorage.php b/lib/DoctrineExtensions/Workflow/DefinitionStorage.php index 5ff9d67..f377966 100644 --- a/lib/DoctrineExtensions/Workflow/DefinitionStorage.php +++ b/lib/DoctrineExtensions/Workflow/DefinitionStorage.php @@ -133,17 +133,12 @@ protected function loadWorkflow($workflowId, $workflowName, $workflowVersion) foreach ( $result as $node ) { $node = array_change_key_case($node, \CASE_LOWER); - $configuration = \ezcWorkflowDatabaseUtil::unserialize( - $node['node_configuration'], null - ); + $configuration = $this->options->getSerializer()->unserialize($node['node_configuration'], null); if ( is_null( $configuration ) ) { $configuration = \ezcWorkflowUtil::getDefaultConfiguration( $node['node_class'] ); } - /*$nodes[$node['node_id']] = new $node['node_class']( - $configuration - );*/ $nodes[$node['node_id']] = $this->options->getNodeFactory()->createNode($node['node_class'], $configuration); if ($nodes[$node['node_id']] instanceof \ezcWorkflowNodeFinally && @@ -264,7 +259,7 @@ public function save( \ezcWorkflow $workflow ) $this->conn->insert($this->options->nodeTable(), array( 'workflow_id' => (int)$workflow->id, 'node_class' => get_class($node), - 'node_configuration' => \ezcWorkflowDatabaseUtil::serialize( $node->getConfiguration() ), + 'node_configuration' => $this->options->getSerializer()->serialize( $node->getConfiguration() ), )); $nodeId = $this->conn->lastInsertId(); diff --git a/lib/DoctrineExtensions/Workflow/DoctrineExecution.php b/lib/DoctrineExtensions/Workflow/DoctrineExecution.php index 7904589..eed66bd 100644 --- a/lib/DoctrineExtensions/Workflow/DoctrineExecution.php +++ b/lib/DoctrineExtensions/Workflow/DoctrineExecution.php @@ -50,15 +50,6 @@ protected function doStart($parentId) $platform = $this->conn->getDatabasePlatform(); $variables = $this->variables; - $executionEntityName = null; - $executionEntityId = null; - - if (isset($variables['entityName'])) { - $executionEntityName = $variables['entityName']; - } - if (isset($variables['entityId'])) { - $executionEntityId = $variables['entityId']; - } $executionNextPollDate = null; if (isset($variables['batchWaitInterval'])) { @@ -67,22 +58,22 @@ protected function doStart($parentId) } $executionNextPollDate = new \DateTime("now"); - $executionNextPollDate->add($variables['waitInterval']); + $executionNextPollDate->add($variables['batchWaitInterval']); $executionNextPollDate = $executionNextPollDate->format($platform->getDateTimeFormatString()); } + $serializer = $this->options->getSerializer(); + $now = new \DateTime("now"); $data = array( - 'workflow_id' => (int)$this->workflow->id, - 'execution_parent' => $parentId, - 'execution_started' => $now->format($platform->getDateTimeFormatString()), - 'execution_variables' => \ezcWorkflowDatabaseUtil::serialize($variables), - 'execution_waiting_for' => \ezcWorkflowDatabaseUtil::serialize($this->waitingFor), - 'execution_threads' => \ezcWorkflowDatabaseUtil::serialize($this->threads), - 'execution_next_thread_id' => (int)$this->nextThreadId, - 'execution_entity_name' => $executionEntityName, - 'execution_entity_id' => $executionEntityId, - 'execution_next_poll_date' => $executionNextPollDate, + 'workflow_id' => (int)$this->workflow->id, + 'execution_parent' => $parentId, + 'execution_started' => $now->format($platform->getDateTimeFormatString()), + 'execution_variables' => $serializer->serialize($variables), + 'execution_waiting_for' => $serializer->serialize($this->waitingFor), + 'execution_threads' => $serializer->serialize($this->threads), + 'execution_next_thread_id' => (int)$this->nextThreadId, + 'execution_next_poll_date' => $executionNextPollDate, ); $this->conn->insert($this->options->executionTable(), $data); @@ -149,14 +140,16 @@ protected function doSuspend() $executionNextPollDate = $executionNextPollDate->format($platform->getDateTimeFormatString()); } + $serializer = $this->options->getSerializer(); + $now = new \DateTime("now"); $data = array( - 'execution_suspended' => $now->format($platform->getDateTimeFormatString()), - 'execution_variables' => \ezcWorkflowDatabaseUtil::serialize($variables), - 'execution_waiting_for' => \ezcWorkflowDatabaseUtil::serialize($this->waitingFor), - 'execution_threads' => \ezcWorkflowDatabaseUtil::serialize($this->threads), - 'execution_next_thread_id' => (int)$this->nextThreadId, - 'execution_next_poll_date' => $executionNextPollDate, + 'execution_suspended' => $now->format($platform->getDateTimeFormatString()), + 'execution_variables' => $serializer->serialize($variables), + 'execution_waiting_for' => $serializer->serialize($this->waitingFor), + 'execution_threads' => $serializer->serialize($this->threads), + 'execution_next_thread_id' => (int)$this->nextThreadId, + 'execution_next_poll_date' => $executionNextPollDate, ); $this->cleanUpExecutionStateTable(); @@ -164,11 +157,11 @@ protected function doSuspend() foreach ($this->activatedNodes AS $node) { $data = array( - 'execution_id' => (int)$this->id, - 'node_id' => (int)$node->getId(), - 'node_state' => \ezcWorkflowDatabaseUtil::serialize( $node->getState() ), - 'node_activated_from' => \ezcWorkflowDatabaseUtil::serialize( $node->getActivatedFrom() ), - 'node_thread_id' => $node->getThreadId(), + 'execution_id' => (int)$this->id, + 'node_id' => (int)$node->getId(), + 'node_state' => $serializer->serialize( $node->getState() ), + 'node_activated_from' => $serializer->serialize( $node->getActivatedFrom() ), + 'node_thread_id' => $node->getThreadId(), ); $this->conn->insert($this->options->executionStateTable(), $data); } @@ -198,9 +191,11 @@ protected function loadExecution($executionId) $this->id = (int)$execution['execution_id']; $this->nextThreadId = $execution['execution_next_thread_id']; - $this->variables = \ezcWorkflowDatabaseUtil::unserialize($execution['execution_variables']); - $this->waitingFor = \ezcWorkflowDatabaseUtil::unserialize($execution['execution_waiting_for']); - $this->threads = \ezcWorkflowDatabaseUtil::unserialize($execution['execution_threads']); + $serializer = $this->options->getSerializer(); + + $this->variables = $serializer->unserialize($execution['execution_variables']); + $this->waitingFor = $serializer->unserialize($execution['execution_waiting_for']); + $this->threads = $serializer->unserialize($execution['execution_threads']); $this->workflow = $this->definitionStorage->loadById($execution['workflow_id']); @@ -216,9 +211,9 @@ protected function loadExecution($executionId) $row = array_change_key_case($row, \CASE_LOWER); $active[$row['node_id']] = array( - 'activated_from' => \ezcWorkflowDatabaseUtil::unserialize($row['node_activated_from']), - 'state' => \ezcWorkflowDatabaseUtil::unserialize($row['node_state'], null), - 'thread_id' => $row['node_thread_id'], + 'activated_from' => $serializer->unserialize($row['node_activated_from']), + 'state' => $serializer->unserialize($row['node_state'], null), + 'thread_id' => $row['node_thread_id'], ); } diff --git a/lib/DoctrineExtensions/Workflow/SchemaBuilder.php b/lib/DoctrineExtensions/Workflow/SchemaBuilder.php index 0c891b4..7e1ee5d 100644 --- a/lib/DoctrineExtensions/Workflow/SchemaBuilder.php +++ b/lib/DoctrineExtensions/Workflow/SchemaBuilder.php @@ -100,8 +100,6 @@ public function getWorkflowSchema(WorkflowOptions $options) $executionTable->addColumn('execution_threads', 'text', array('notnull' => false, "length" => null)); $executionTable->addColumn('execution_next_thread_id', 'integer'); $executionTable->addColumn('execution_next_poll_date', 'datetime', array('notnull' => false)); - $executionTable->addColumn('execution_entity_name', 'string', array('notnull' => false)); - $executionTable->addColumn('execution_entity_id', 'integer', array('notnull' => false)); $executionTable->setPrimaryKey(array('execution_id')); $executionTable->addIndex(array('execution_parent')); diff --git a/lib/DoctrineExtensions/Workflow/Util/Serialize/JsonSerializer.php b/lib/DoctrineExtensions/Workflow/Util/Serialize/JsonSerializer.php deleted file mode 100644 index 5d7c89a..0000000 --- a/lib/DoctrineExtensions/Workflow/Util/Serialize/JsonSerializer.php +++ /dev/null @@ -1,33 +0,0 @@ -conn = \DoctrineExtensions\Workflow\TestHelper::getConnection(); - $this->options = new WorkflowOptions('test_'); + $this->options = new WorkflowOptions('test_', null, null, $this->createSerializer()); TestHelper::createSchema($this->options); } diff --git a/tests/DoctrineExtensions/Workflow/DoctrineExecutionTest.php b/tests/DoctrineExtensions/Workflow/DoctrineExecutionTest.php index 37af423..23c086b 100644 --- a/tests/DoctrineExtensions/Workflow/DoctrineExecutionTest.php +++ b/tests/DoctrineExtensions/Workflow/DoctrineExecutionTest.php @@ -26,10 +26,18 @@ class DoctrineExecutionTest extends \PHPUnit_Framework_TestCase */ private $storage; + public function createSerializer() + { + if (isset($GLOBALS['DOCTRINE_WORKFLOW_SERIALIZER_IMPL'])) { + return new $GLOBALS['DOCTRINE_WORKFLOW_SERIALIZER_IMPL'](); + } + return null; + } + public function setUp() { $this->conn = \DoctrineExtensions\Workflow\TestHelper::getConnection(); - $this->options = new WorkflowOptions('test_'); + $this->options = new WorkflowOptions('test_', null, null, $this->createSerializer()); TestHelper::createSchema($this->options); $this->storage = new DefinitionStorage($this->conn, $this->options); } diff --git a/tests/DoctrineExtensions/Workflow/TestHelper.php b/tests/DoctrineExtensions/Workflow/TestHelper.php index 0eb8d6c..0d56258 100644 --- a/tests/DoctrineExtensions/Workflow/TestHelper.php +++ b/tests/DoctrineExtensions/Workflow/TestHelper.php @@ -16,15 +16,30 @@ static public function createSchema(WorkflowOptions $options) { $conn = self::getConnection(); - $schemaBuilder = new SchemaBuilder($conn); - try { - $schemaBuilder->dropWorkflowSchema($options); - } catch(\PDOException $e) { - + if (!isset(self::$schema[$options->getTablePrefix()])) { + $schemaBuilder = new SchemaBuilder($conn); + try { + $schemaBuilder->dropWorkflowSchema($options); + } catch(\PDOException $e) { + + } + $schemaBuilder->createWorkflowSchema($options); + + self::$schema[$options->getTablePrefix()] = true; } - $schemaBuilder->createWorkflowSchema($options); - self::$schema[$options->getTablePrefix()] = true; + $platform = $conn->getDatabasePlatform(); + $tables = array( + $options->executionStateTable(), + $options->executionTable(), + $options->variableHandlerTable(), + $options->nodeConnectionTable(), + $options->nodeTable(), + $options->workflowTable(), + ); + foreach ($tables AS $table) { + $conn->executeUpdate($platform->getTruncateTableSQL($table)); + } } static public function getConnection() diff --git a/tests/DoctrineExtensions/Workflow/Util/SerializerTest.php b/tests/DoctrineExtensions/Workflow/Util/SerializerTest.php index 4fe4d5d..bbee9d6 100644 --- a/tests/DoctrineExtensions/Workflow/Util/SerializerTest.php +++ b/tests/DoctrineExtensions/Workflow/Util/SerializerTest.php @@ -17,6 +17,8 @@ public static function dataSerialize() array(array('foo' => 'bar'), array('foo' => 'bar'), array()), array(array('foo' => 'bar'), array('foo' => 'bar'), null), array(array('c' => "\xc9\x80"), array('c' => "\xc9\x80"), null), + // empty object instances exist in ezcWorkflow!! + array(array('c' => new \stdClass()), array('c' => new \stdClass()), null), ); } @@ -41,13 +43,4 @@ public function testWbbxSerializer($value, $expectedValue, $defaultValue) $z = new WddxSerializer(); $this->assertEquals($expectedValue, $z->unserialize($z->serialize($value), $defaultValue)); } - - /** - * @dataProvider dataSerialize - */ - public function testJsonSerializer($value, $expectedValue, $defaultValue) - { - $z = new JsonSerializer(); - $this->assertEquals($expectedValue, $z->unserialize($z->serialize($value), $defaultValue)); - } } diff --git a/tests/phpunit.dist.xml b/tests/phpunit.dist.xml index bec3d8f..e5c1723 100644 --- a/tests/phpunit.dist.xml +++ b/tests/phpunit.dist.xml @@ -1,6 +1,7 @@ +