public function getUnusedWorkflowIds() { $sql = 'SELECT w.workflow_id FROM ' . $this->options->workflowTable() . ' w ' . 'WHERE w.workflow_id NOT IN ( SELECT DISTINCT e.workflow_id FROM ' . $this->options->executionTable() . ') ' . ' AND w.workflow_outdated = 1'; $stmt = $this->conn->query(); $workflowIds = array(); while ($workflowId = $stmt->fetchColumn()) { $workflowIds[] = $workflowId; } return $workflowIds; }
protected function loadExecution($executionId) { if (!is_int($executionId)) { throw new \ezcWorkflowExecutionException("Execution-Id has to be an integer (strictly-typed)."); } $sql = 'SELECT * FROM ' . $this->options->executionTable() . ' WHERE execution_id = ?'; $stmt = $this->conn->prepare($sql); $stmt->bindParam(1, $executionId); $stmt->execute(); $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); if ($result === false || empty($result)) { throw new \ezcWorkflowExecutionException('Could not load execution state for ID ' . (int) $executionId); } $execution = array_change_key_case($result[0], \CASE_LOWER); $this->id = (int) $execution['execution_id']; $this->nextThreadId = $execution['execution_next_thread_id']; $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']); $sql = 'SELECT * FROM ' . $this->options->executionStateTable() . ' WHERE execution_id = ?'; $stmt = $this->conn->prepare($sql); $stmt->bindParam(1, $executionId); $stmt->execute(); $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); $active = array(); foreach ($result as $row) { $row = array_change_key_case($row, \CASE_LOWER); $active[$row['node_id']] = array('activated_from' => $serializer->unserialize($row['node_activated_from']), 'state' => $serializer->unserialize($row['node_state'], null), 'thread_id' => $row['node_thread_id']); } foreach ($this->workflow->nodes as $node) { $nodeId = $node->getId(); if (isset($active[$nodeId])) { $node->setActivationState(\ezcWorkflowNode::WAITING_FOR_EXECUTION); $node->setThreadId($active[$nodeId]['thread_id']); $node->setState($active[$nodeId]['state'], null); $node->setActivatedFrom($active[$nodeId]['activated_from']); $this->activate($node, false); } } $this->cancelled = false; $this->ended = false; $this->loaded = true; $this->resumed = false; $this->suspended = true; }
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; }