protected function doStart($parentId) { $this->conn->beginTransaction(); $platform = $this->conn->getDatabasePlatform(); $variables = $this->variables; $executionNextPollDate = null; if (isset($variables['batchWaitInterval'])) { if (!$variables['batchWaitInterval'] instanceof \DateInterval) { throw new \ezcWorkflowExecutionException("Specified batch waiting interval has to be instance of DateInterval!"); } $executionNextPollDate = new \DateTime("now"); $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' => $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); 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 if (!$platform->prefersSequences()) { $this->id = (int) $this->conn->lastInsertId(); } }
public function getWorkflowSchema(WorkflowOptions $options) { $schema = new \Doctrine\DBAL\Schema\Schema(); $workflowTable = $schema->createTable($options->workflowTable()); $columnOptions = $this->_handlePrimaryKey($schema, $options->workflowTable(), $options->workflowSequence()); $workflowTable->addColumn('workflow_id', 'integer', $columnOptions); $workflowTable->addColumn('workflow_name', 'string'); $workflowTable->addColumn('workflow_version', 'integer'); $workflowTable->addColumn('workflow_outdated', 'integer'); $workflowTable->addColumn('workflow_created', 'datetime'); $workflowTable->setPrimaryKey(array('workflow_id')); $workflowTable->addUniqueIndex(array('workflow_name', 'workflow_version')); $nodeTable = $schema->createTable($options->nodeTable()); $columnOptions = $this->_handlePrimaryKey($schema, $options->nodeTable(), $options->nodeSequence()); $nodeTable->addColumn('node_id', 'integer', $columnOptions); $nodeTable->addColumn('workflow_id', 'integer'); $nodeTable->addColumn('node_class', 'string'); $nodeTable->addColumn('node_configuration', 'text', array('notnull' => false, "length" => null)); $nodeTable->setPrimaryKey(array('node_id')); $nodeTable->addIndex(array('workflow_id')); $nodeTable->addForeignKeyConstraint($options->workflowTable(), array('workflow_id'), array('workflow_id'), array('onDelete' => 'CASCADE')); $connectionTable = $schema->createTable($options->nodeConnectionTable()); $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'); $connectionTable->setPrimaryKey(array('id')); $connectionTable->addForeignKeyConstraint($options->nodeTable(), array('incoming_node_id'), array('node_id'), array('onDelete' => 'CASCADE')); $connectionTable->addForeignKeyConstraint($options->nodeTable(), array('outgoing_node_id'), array('node_id'), array('onDelete' => 'CASCADE')); $variableHandlerTable = $schema->createTable($options->variableHandlerTable()); $variableHandlerTable->addColumn('workflow_id', 'integer'); $variableHandlerTable->addColumn('variable', 'string'); $variableHandlerTable->addColumn('class', 'string'); $variableHandlerTable->setPrimaryKey(array('workflow_id', 'variable')); $variableHandlerTable->addForeignKeyconstraint($options->workflowTable(), array('workflow_id'), array('workflow_id')); $executionTable = $schema->createTable($options->executionTable()); $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)); $executionTable->addColumn('execution_started', 'datetime'); $executionTable->addColumn('execution_suspended', 'datetime', array('notnull' => false)); $executionTable->addColumn('execution_variables', 'text', array('notnull' => false, "length" => null)); $executionTable->addColumn('execution_waiting_for', 'text', array('notnull' => false, "length" => null)); $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->addIndex(array('execution_next_poll_date')); $executionTable->setPrimaryKey(array('execution_id')); $executionTable->addIndex(array('execution_parent')); $executionTable->addForeignKeyConstraint($options->workflowTable(), array('workflow_id'), array('workflow_id')); $executionTable->addForeignKeyConstraint($options->executionTable(), array('execution_parent'), array('execution_id')); $executionStateTable = $schema->createTable($options->executionStateTable()); $executionStateTable->addColumn('execution_id', 'integer'); $executionStateTable->addColumn('node_id', 'integer'); $executionStateTable->addColumn('node_state', 'text', array('notnull' => false, "length" => null)); $executionStateTable->addColumn('node_activated_from', 'text', array('notnull' => false, "length" => null)); $executionStateTable->addColumn('node_thread_id', 'integer'); $executionStateTable->setPrimaryKey(array('execution_id', 'node_id')); $executionStateTable->addForeignKeyConstraint($options->executionTable(), array('execution_id'), array('execution_id')); $executionStateTable->addForeignKeyConstraint($options->nodeTable(), array('node_id'), array('node_id')); return $schema; }