public function testSchemaCreate()
 {
     $conn = \DoctrineExtensions\Workflow\TestHelper::getConnection();
     $options = new WorkflowOptions('myprefix_');
     $builder = new SchemaBuilder($conn);
     $schema = $builder->getWorkflowSchema($options);
     $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\Schema', $schema);
     $this->assertFalse($schema->hasTable('workflow'));
     $this->assertTrue($schema->hasTable('myprefix_workflow'));
 }
 /**
  * Test the creation of a simple schema with one field.
  */
 public function testBuildSingleField()
 {
     $builder = new SchemaBuilder();
     $schema = $builder->createFromArray(array('sometext' => array('_type' => 'text', 'size' => 4)));
     $this->assertCount(1, $schema->getFields());
     $fields = $schema->getFields();
     $field = $fields[0];
     $this->assertInstanceOf('\\Binary\\Field\\FieldInterface', $field);
     $this->assertEquals('sometext', $field->getName());
 }
 /**
  * Create Schema for this test if not yet done
  *
  * @param WorkflowOptions $options
  */
 public static function createSchema(WorkflowOptions $options)
 {
     $conn = self::getConnection();
     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;
     }
     $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));
     }
 }
 /**
  * Import a schema using JSON
  *
  * @todo sanity checking of the input data should be added
  *
  * @param string $table
  * @param string $json
  * @param bool $islookup
  */
 public function __construct($table, $json, $islookup = false)
 {
     parent::__construct($table, array('islookup' => $islookup));
     // number of existing columns
     $existing = count($this->oldschema->getColumns());
     $input = json_decode($json, true);
     if ($input === null) {
         switch (json_last_error()) {
             case JSON_ERROR_NONE:
                 $error = 'No errors';
                 break;
             case JSON_ERROR_DEPTH:
                 $error = 'Maximum stack depth exceeded';
                 break;
             case JSON_ERROR_STATE_MISMATCH:
                 $error = 'Underflow or the modes mismatch';
                 break;
             case JSON_ERROR_CTRL_CHAR:
                 $error = 'Unexpected control character found';
                 break;
             case JSON_ERROR_SYNTAX:
                 $error = 'Syntax error, malformed JSON';
                 break;
             case JSON_ERROR_UTF8:
                 $error = 'Malformed UTF-8 characters, possibly incorrectly encoded';
                 break;
             default:
                 $error = 'Unknown error';
                 break;
         }
         throw new StructException('JSON couldn\'t be decoded: ' . $error);
     }
     $data = array('cols' => array(), 'new' => array());
     foreach ($input['columns'] as $column) {
         // config has to stay json
         $column['config'] = json_encode($column['config'], JSON_PRETTY_PRINT);
         if (!empty($column['colref']) && $column['colref'] <= $existing) {
             // update existing column
             $data['cols'][$column['colref']] = $column;
         } else {
             // add new column
             $data['new'][] = $column;
         }
     }
     $this->data = $data;
 }
 protected function execute($arguments = array(), $options = array())
 {
     if ($options['application'] == false) {
         throw new Exception('You must set the application name in order for the database connectoins to be properly initialized (They are on the application level)');
     }
     if ($options['connection'] == false) {
         throw new Exception('You must set the connection name!');
     }
     if ($options['table'] == false) {
         throw new Exception('You must set a table name!');
     }
     $databaseManager = new sfDatabaseManager($this->configuration);
     $this->logSection('doctrine', 'generating yaml schema from database');
     $config = $this->getCliConfig();
     $schemaPath = $config['yaml_schema_path'] . uFs::DS . 'schema.yml';
     $connections = array($options['connection'] => array($options['table']));
     $builderOptions = array();
     return SchemaBuilder::getInstance()->update($schemaPath, $connections, $builderOptions);
 }
 /**
  * @return MetaConfiguration
  **/
 public function buildSchema()
 {
     $out = $this->getOutput();
     $out->newLine()->infoLine('Building DB schema:');
     $schema = SchemaBuilder::getHead();
     $tables = array();
     foreach ($this->classes as $class) {
         if (!$class->getParent() && !count($class->getProperties()) || !$class->getPattern()->tableExists()) {
             continue;
         }
         foreach ($class->getAllProperties() as $property) {
             $tables[$class->getTableName()][$property->getColumnName()] = $property;
         }
     }
     foreach ($tables as $name => $propertyList) {
         if ($propertyList) {
             $schema .= SchemaBuilder::buildTable($name, $propertyList);
         }
     }
     foreach ($this->classes as $class) {
         if (!$class->getPattern()->tableExists()) {
             continue;
         }
         $schema .= SchemaBuilder::buildRelations($class);
     }
     $schema .= '?>';
     BasePattern::dumpFile(ONPHP_META_AUTO_DIR . 'schema.php', Format::indentize($schema));
     return $this;
 }
 protected function buildSchema($parsed)
 {
     $builder = new SchemaBuilder();
     return $builder->build($parsed);
 }
Beispiel #8
0
 static function appCreateEntities($prefijo)
 {
     $result = array();
     $prefijo = strtolower($prefijo);
     self::getConection();
     $sb = new SchemaBuilder(self::$conectionDB);
     // Crear el modelo, el controlador, config y los templates para todas las tablas
     $tables = $sb->getTableNames();
     foreach ($tables as $key => $tableName) {
         $tableName = strtolower($tableName);
         $resultado = self::appCreateEntity($tableName, $prefijo);
         foreach ($resultado as $key => $value) {
             array_push($result, $value);
         }
     }
     return $result;
 }