/**
  * Saves data to execution data handlers.
  */
 protected function saveToVariableHandlers()
 {
     foreach ($this->workflow->getVariableHandlers() as $variableName => $className) {
         if (isset($this->variables[$variableName])) {
             $object = $this->options->getWorkflowFactory()->createVariableHandler($className);
             $object->save($this, $variableName, $this->variables[$variableName]);
         }
     }
 }
 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;
 }
 /**
  * Delete a workflow by its ID
  *
  * @param int $workflowId
  * @return void
  */
 public function delete($workflowId)
 {
     $this->conn->beginTransaction();
     try {
         // delete only those two, the rest should be deleted automatically through cascading foreign keys
         $this->conn->delete($this->options->variableHandlerTable(), array('workflow_id' => $workflowId));
         $this->conn->delete($this->options->workflowTable(), array('workflow_id' => $workflowId));
         $this->conn->commit();
     } catch (\Exception $e) {
         $this->conn->rollback();
     }
 }
 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;
 }