Exemplo n.º 1
0
 protected function setUp()
 {
     $this->target = new Table('tableName');
     $this->target->addColumn(new Column(array('name' => 'id', 'dataType' => 'bigint(100)', 'primary' => true, 'autoIncrement' => true, 'notNull' => true, 'default' => null)));
     $this->target->addColumn(new Column(array('name' => 'col1', 'dataType' => 'VARCHAR(255)', 'primary' => false, 'autoIncrement' => false, 'notNull' => true, 'default' => null)));
     $this->target->addColumn(new Column(array('name' => 'col2', 'dataType' => 'double', 'primary' => false, 'autoIncrement' => false, 'notNull' => false, 'default' => null)));
 }
Exemplo n.º 2
0
 /**
  * @param string $columnName
  * @param string $typeName
  * @param array $options
  *
  * @return Column
  */
 public function addColumn($columnName, $typeName, array $options = array())
 {
     if ($this->connection->getDatabasePlatform()->getName() === 'sqlite' && in_array($typeName, ['string', 'text'])) {
         $options['customSchemaOptions']['collation'] = 'NOCASE';
     }
     return $this->table->addColumn($columnName, $typeName, $options);
 }
 protected function createTaggingTable()
 {
     $table = $this->getTable();
     $database = $table->getDatabase();
     $pks = $this->getTable()->getPrimaryKey();
     if (count($pks) > 1) {
         throw new EngineException('The Taggable behavior does not support tables with composite primary keys');
     }
     $taggingTableName = $this->getTaggingTableName();
     if ($database->hasTable($taggingTableName)) {
         $this->taggingTable = $database->getTable($taggingTableName);
     } else {
         $this->taggingTable = $database->addTable(array('name' => $taggingTableName, 'phpName' => $this->replaceTokens($this->getParameter('tagging_table_phpname')), 'package' => $table->getPackage(), 'schema' => $table->getSchema(), 'namespace' => '\\' . $table->getNamespace()));
         // every behavior adding a table should re-execute database behaviors
         // see bug 2188 http://www.propelorm.org/changeset/2188
         foreach ($database->getBehaviors() as $behavior) {
             $behavior->modifyDatabase();
         }
     }
     if ($this->taggingTable->hasColumn('tag_id')) {
         $tagFkColumn = $this->taggingTable->getColumn('tag_id');
     } else {
         $tagFkColumn = $this->taggingTable->addColumn(array('name' => 'tag_id', 'type' => PropelTypes::INTEGER, 'primaryKey' => 'true'));
     }
     if ($this->taggingTable->hasColumn($table->getName() . '_id')) {
         $objFkColumn = $this->taggingTable->getColumn($table->getName() . '_id');
     } else {
         $objFkColumn = $this->taggingTable->addColumn(array('name' => $table->getName() . '_id', 'type' => PropelTypes::INTEGER, 'primaryKey' => 'true'));
     }
     $this->taggingTable->setIsCrossRef(true);
     $fkTag = new ForeignKey();
     $fkTag->setForeignTableCommonName($this->tagTable->getCommonName());
     $fkTag->setForeignSchemaName($this->tagTable->getSchema());
     $fkTag->setOnDelete(ForeignKey::CASCADE);
     $fkTag->setOnUpdate(ForeignKey::CASCADE);
     $tagColumn = $this->tagTable->getColumn('id');
     $fkTag->addReference($tagFkColumn->getName(), $tagColumn->getName());
     $this->taggingTable->addForeignKey($fkTag);
     $fkObj = new ForeignKey();
     $fkObj->setForeignTableCommonName($this->getTable()->getCommonName());
     $fkObj->setForeignSchemaName($this->getTable()->getSchema());
     $fkObj->setOnDelete(ForeignKey::CASCADE);
     $fkObj->setOnUpdate(ForeignKey::CASCADE);
     foreach ($pks as $column) {
         $fkObj->addReference($objFkColumn->getName(), $column->getName());
     }
     $this->taggingTable->addForeignKey($fkObj);
 }
Exemplo n.º 4
0
 private function addToTable($tableName, Column $column)
 {
     foreach ($this->tables as $table) {
         if ($table->name == $tableName) {
             $table->addColumn($column);
             return;
         }
     }
     $table = new Table($tableName);
     $table->addColumn($column);
     $this->tables[] = $table;
 }
 public function testCompareSeveralRenamedSameColumns()
 {
     $t1 = new Table();
     $c1 = new Column('col1');
     $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c1->getDomain()->replaceSize(255);
     $t1->addColumn($c1);
     $c2 = new Column('col2');
     $c2->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c2->getDomain()->replaceSize(255);
     $t1->addColumn($c2);
     $c3 = new Column('col3');
     $c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c3->getDomain()->replaceSize(255);
     $t1->addColumn($c3);
     $t2 = new Table();
     $c4 = new Column('col4');
     $c4->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c4->getDomain()->replaceSize(255);
     $t2->addColumn($c4);
     $c5 = new Column('col5');
     $c5->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c5->getDomain()->replaceSize(255);
     $t2->addColumn($c5);
     $c6 = new Column('col3');
     $c6->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c6->getDomain()->replaceSize(255);
     $t2->addColumn($c6);
     // col1 and col2 were renamed
     $tc = new PropelTableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareColumns();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(2, $nbDiffs);
     $this->assertEquals(array(array($c1, $c4), array($c2, $c5)), $tableDiff->getRenamedColumns());
     $this->assertEquals(array(), $tableDiff->getAddedColumns());
     $this->assertEquals(array(), $tableDiff->getRemovedColumns());
     $this->assertEquals(array(), $tableDiff->getModifiedColumns());
 }
 /**
  * {@inheritDoc}
  */
 public function convertColumnDescription(Table $table, $row)
 {
     $field = $this->_convertColumn($row['type'], $row['char_length'], $row['precision'], $row['scale']);
     if (!empty($row['default'])) {
         $row['default'] = trim($row['default'], '()');
     }
     if (!empty($row['autoincrement'])) {
         $field['autoIncrement'] = true;
     }
     if ($field['type'] === 'boolean') {
         $row['default'] = (int) $row['default'];
     }
     $field += ['null' => $row['null'] === '1' ? true : false, 'default' => $row['default']];
     $table->addColumn($row['name'], $field);
 }
Exemplo n.º 7
0
 public function testRemoveColumnFixesPositions()
 {
     $table = new Table();
     $col1 = new Column('Foo1');
     $table->addColumn($col1);
     $col2 = new Column('Foo2');
     $table->addColumn($col2);
     $col3 = new Column('Foo3');
     $table->addColumn($col3);
     $this->assertEquals(1, $col1->getPosition());
     $this->assertEquals(2, $col2->getPosition());
     $this->assertEquals(3, $col3->getPosition());
     $this->assertEquals(array(0, 1, 2), array_keys($table->getColumns()));
     $table->removeColumn($col2);
     $this->assertEquals(1, $col1->getPosition());
     $this->assertEquals(2, $col3->getPosition());
     $this->assertEquals(array(0, 1), array_keys($table->getColumns()));
 }
 public function testGetPrimaryKeyDDLCompositeKey()
 {
     $table = new Table('foo');
     $column1 = new Column('bar1');
     $column1->setPrimaryKey(true);
     $table->addColumn($column1);
     $column2 = new Column('bar2');
     $column2->setPrimaryKey(true);
     $table->addColumn($column2);
     $expected = 'PRIMARY KEY ([bar1],[bar2])';
     $this->assertEquals($expected, $this->getPlatform()->getPrimaryKeyDDL($table));
 }
    public function testGetModifyColumnDDLWithChangedTypeAndDefault()
    {
        $t1 = new Table('foo');
        $c1 = new Column('bar');
        $c1->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
        $c1->getDomain()->replaceSize(2);
        $t1->addColumn($c1);
        $t2 = new Table('foo');
        $c2 = new Column('bar');
        $c2->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
        $c2->getDomain()->replaceSize(3);
        $c2->getDomain()->setDefaultValue(new ColumnDefaultValue(-100, ColumnDefaultValue::TYPE_VALUE));
        $t2->addColumn($c2);
        $columnDiff = PropelColumnComparator::computeDiff($c1, $c2);
        $expected = <<<END

ALTER TABLE foo ALTER COLUMN bar TYPE DOUBLE PRECISION;

ALTER TABLE foo ALTER COLUMN bar SET DEFAULT -100;

END;
        $this->assertEquals($expected, $this->getPlatform()->getModifyColumnDDL($columnDiff));
    }
Exemplo n.º 10
0
 public function getScheme()
 {
     $this->open();
     $rs = $this->connection->query('SHOW TABLES');
     $tables = array();
     while ($table = $rs->fetch_array()) {
         $rs2 = $this->connection->query("SHOW COLUMNS FROM {$table['0']}");
         $scheme = new Table($table[0]);
         while ($column = $rs2->fetch_object()) {
             $scheme->addColumn(new Column(array('name' => $column->Field, 'dataType' => $column->Type, 'primary' => $column->Key === "PRI", 'autoIncrement' => $column->Extra === "auto_increment", 'notNull' => $column->Null === 'NO', 'default' => $column->Default)));
         }
         $tables[] = $scheme;
     }
     return $tables;
 }
 public function testCompareSeveralColumnDifferences()
 {
     $t1 = new Table();
     $c1 = new Column('col1');
     $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c1->getDomain()->replaceSize(255);
     $c1->setNotNull(false);
     $t1->addColumn($c1);
     $c2 = new Column('col2');
     $c2->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $c2->setNotNull(true);
     $t1->addColumn($c2);
     $c3 = new Column('col3');
     $c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c3->getDomain()->replaceSize(255);
     $t1->addColumn($c3);
     $t2 = new Table();
     $c4 = new Column('col1');
     $c4->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $c4->getDomain()->replaceScale(2);
     $c4->getDomain()->replaceSize(3);
     $c4->setNotNull(true);
     $c4->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
     $t2->addColumn($c4);
     $c5 = new Column('col22');
     $c5->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $c5->setNotNull(true);
     $t2->addColumn($c5);
     $c6 = new Column('col4');
     $c6->getDomain()->copy($this->platform->getDomainForType('LONGVARCHAR'));
     $c6->getDomain()->setDefaultValue(new ColumnDefaultValue('123', ColumnDefaultValue::TYPE_VALUE));
     $t2->addColumn($c6);
     // col1 was modified, col2 was renamed, col3 was removed, col4 was added
     $tc = new PropelTableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareColumns();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(4, $nbDiffs);
     $this->assertEquals(array(array($c2, $c5)), $tableDiff->getRenamedColumns());
     $this->assertEquals(array('col4' => $c6), $tableDiff->getAddedColumns());
     $this->assertEquals(array('col3' => $c3), $tableDiff->getRemovedColumns());
     $columnDiff = PropelColumnComparator::computeDiff($c1, $c4);
     $this->assertEquals(array('col1' => $columnDiff), $tableDiff->getModifiedColumns());
 }
Exemplo n.º 12
0
 public function testColumnIsFKAndPK()
 {
     $column = new Column();
     $column->setName('id');
     $column->setPrimaryKey(true);
     $column->setAutoIncrement(true);
     $column->setType('integer');
     $table = new Table();
     $table->setCommonName('table_one');
     $table->addColumn($column);
     $db = new Database();
     $db->setName('MultipleTables');
     $db->addTable($table);
     $column = new Column();
     $column->setName('id');
     $column->setPrimaryKey(true);
     $column->setAutoIncrement(true);
     $column->setType('integer');
     $c2 = new Column();
     $c2->setPrimaryKey(true);
     $c2->setName('foreign_id');
     $c2->setType('integer');
     $table = new Table();
     $table->setCommonName('table_two');
     $table->addColumn($column);
     $table->addColumn($c2);
     $fk = new ForeignKey();
     $fk->setName('FK_1');
     $fk->addReference('foreign_id', 'id');
     $fk->setForeignTableCommonName('table_one');
     $table->addForeignKey($fk);
     $db->addTable($table);
     $expected = implode("\n", array('digraph G {', 'nodetable_one [label="{<table>table_one|<cols>id (integer) [PK]\\l}", shape=record];', 'nodetable_two [label="{<table>table_two|<cols>id (integer) [PK]\\lforeign_id (integer) [FK] [PK]\\l}", shape=record];', 'nodetable_two:cols -> nodetable_one:table [label="foreign_id=id"];', '}', ''));
     $this->assertEquals($expected, PropelDotGenerator::create($db));
 }
 public function testCompareModifiedIndices()
 {
     $t1 = new Table();
     $c1 = new Column('Foo');
     $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c1->getDomain()->replaceSize(255);
     $c1->setNotNull(false);
     $t1->addColumn($c1);
     $i1 = new Index('Foo_Index');
     $i1->addColumn($c1);
     $t1->addIndex($i1);
     $t2 = new Table();
     $c2 = new Column('Foo');
     $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $c2->getDomain()->replaceScale(2);
     $c2->getDomain()->replaceSize(3);
     $c2->setNotNull(true);
     $c2->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
     $t2->addColumn($c2);
     $i2 = new Unique('Foo_Index');
     $i2->addColumn($c2);
     $t2->addIndex($i2);
     $tc = new PropelTableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareIndices();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(1, $nbDiffs);
     $this->assertEquals(1, count($tableDiff->getModifiedIndices()));
     $this->assertEquals(array('Foo_Index' => array($i1, $i2)), $tableDiff->getModifiedIndices());
 }
 public function testGetIndexDDLFulltext()
 {
     $table = new Table('foo');
     $column1 = new Column('bar1');
     $column1->getDomain()->copy($this->getPlatform()->getDomainForType('LONGVARCHAR'));
     $table->addColumn($column1);
     $index = new Index('bar_index');
     $index->addColumn($column1);
     $vendor = new VendorInfo('mysql');
     $vendor->setParameter('Index_type', 'FULLTEXT');
     $index->addVendorInfo($vendor);
     $table->addIndex($index);
     $expected = 'FULLTEXT INDEX `bar_index` (`bar1`)';
     $this->assertEquals($expected, $this->getPLatform()->getIndexDDL($index));
 }
Exemplo n.º 15
0
 /**
  * Creates a column definition as required by the DBAL from an ORM field mapping definition.
  *
  * @param ClassMetadata $class The class that owns the field mapping.
  * @param array $mapping The field mapping.
  * @param Table $table
  * @return array The portable column definition as required by the DBAL.
  */
 private function _gatherColumn($class, array $mapping, $table)
 {
     $columnName = $class->getQuotedColumnName($mapping['fieldName'], $this->_platform);
     $columnType = $mapping['type'];
     $options = array();
     $options['length'] = isset($mapping['length']) ? $mapping['length'] : null;
     $options['notnull'] = isset($mapping['nullable']) ? !$mapping['nullable'] : true;
     $options['platformOptions'] = array();
     $options['platformOptions']['version'] = $class->isVersioned && $class->versionField == $mapping['fieldName'] ? true : false;
     if (strtolower($columnType) == 'string' && $options['length'] === null) {
         $options['length'] = 255;
     }
     if (isset($mapping['precision'])) {
         $options['precision'] = $mapping['precision'];
     }
     if (isset($mapping['scale'])) {
         $options['scale'] = $mapping['scale'];
     }
     if (isset($mapping['default'])) {
         $options['default'] = $mapping['default'];
     }
     if (isset($mapping['columnDefinition'])) {
         $options['columnDefinition'] = $mapping['columnDefinition'];
     }
     if ($class->isIdGeneratorIdentity() && $class->getIdentifierFieldNames() == array($mapping['fieldName'])) {
         $options['autoincrement'] = true;
     }
     if ($table->hasColumn($columnName)) {
         // required in some inheritance scenarios
         $table->changeColumn($columnName, $options);
     } else {
         $table->addColumn($columnName, $columnType, $options);
     }
     $isUnique = isset($mapping['unique']) ? $mapping['unique'] : false;
     if ($isUnique) {
         $table->addUniqueIndex(array($columnName));
     }
 }
Exemplo n.º 16
0
    /**
     * Get table columns
     * @param Table $table
     * @return TableColumn[]
     */
    function dbGetTableColumns(Table $table)
    {
        $columns = $table->getColumns();
        if (empty($columns)) {
            $input = new InputForSelect();
            $input->className = TableColumn::class;
            $input->sql = <<<SQL
SELECT *
FROM information_schema.columns c
WHERE c.table_schema = ?
  AND c.table_name   = ?
-- AND c.table_catalog = '[dbname]'
ORDER BY c.ordinal_position;
SQL;
            $input->parameters = [$table->getSchemaName(), $table->getName()];
            $output = $this->dbSelect($input);
            $columns = $output->rows;
            $table->resetColumns();
            foreach ($columns as $column) {
                $table->addColumn($column);
            }
        }
        return $columns;
    }
Exemplo n.º 17
0
        echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['mydate']) . "{$fspane}&nbsp;</td>\n";
        echo "<td class=\"listr\">{$fspans}{$data['peerstate']}{$fspane}&nbsp;</td>\n";
        echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['peerdate']) . "{$fspane}&nbsp;</td>\n";
        echo "<td class=\"list\" valign=\"middle\" width=\"17\">&nbsp;</td>\n";
        echo "<td class=\"list\" valign=\"middle\" width=\"17\">&nbsp;</td>\n";
        echo "</tr>\n";
    }
    ?>
</table>

<?php 
    /* only print pool status when we have one */
}
$table = new Table();
// assemble columns
$table->addColumn("IP address", "ip");
$table->addColumn("MAC address", "mac");
$table->addColumn("Hostname", "hostname");
$table->addColumn("Start", "start");
$table->addColumn("End", "end");
$table->addColumn("Online", "online");
$table->addColumn("Lease Type", "act", "listhdr");
// populate table data
$table->setData($leases);
?>

<p>

<table class="sortable" id="sortabletable" name="sortabletable" width="100%" border="0" cellpadding="0" cellspacing="0">
<?php 
echo $table->getColumnHTML();
 public function providerForTestGetModifyColumnRemoveDefaultValueDDL()
 {
     $t1 = new Table('test');
     $c1 = new Column();
     $c1->setName('test');
     $c1->getDomain()->setType('INTEGER');
     $c1->setDefaultValue(0);
     $t1->addColumn($c1);
     $t2 = new Table('test');
     $c2 = new Column();
     $c2->setName('test');
     $c2->getDomain()->setType('INTEGER');
     $t2->addColumn($c2);
     return array(array(PropelColumnComparator::computeDiff($c1, $c2)));
 }
Exemplo n.º 19
0
 protected function loadData($data)
 {
     $dataObj = new Data($this, (int) $data['id'], (string) $data['name']);
     $dataObj->setLabel((string) $data['label']);
     $dataObj->setType((string) $data['type']);
     $dataObj->setUnparsedMin((string) $data['min']);
     $dataObj->setUnparsedMax((string) $data['max']);
     $dataObj->setUnparsedDefault((string) $data['default']);
     $dataObj->setUnit((string) $data['unit']);
     $dataObj->setRound(isset($data['round']) ? (int) $data['round'] : 2);
     $dataObj->setContent((string) $data['content']);
     $dataObj->setSource((string) $data['source']);
     $dataObj->setUnparsedIndex((string) $data['index']);
     $dataObj->setMemorize((string) $data['memorize'] == '1');
     if ($data->Choices) {
         foreach ($data->Choices->children() as $child) {
             if ($child->getName() == "ChoiceGroup") {
                 $choicegroup = $child;
                 $choiceGroupObj = new ChoiceGroup((string) $choicegroup['label']);
                 foreach ($choicegroup->Choice as $choice) {
                     $choiceObj = new Choice($dataObj, (string) $choice['id'], (string) $choice['value'], (string) $choice['label']);
                     $choiceGroupObj->addChoice($choiceObj);
                 }
                 if ($choicegroup->Source) {
                     $source = $choicegroup->Source;
                     $choiceSourceObj = new ChoiceSource($dataObj, (int) $source['id'], (string) $source['valueColumn'], (string) $source['labelColumn']);
                     $choiceSourceObj->setIdColumn((string) $source['idColumn']);
                     $choiceGroupObj->setChoiceSource($choiceSourceObj);
                 }
                 $dataObj->addChoice($choiceGroupObj);
             } elseif ($child->getName() == "Choice") {
                 $choice = $child;
                 $choiceObj = new Choice($dataObj, (string) $choice['id'], (string) $choice['value'], (string) $choice['label']);
                 $dataObj->addChoice($choiceObj);
             } elseif ($child->getName() == "Source") {
                 $source = $child;
                 $choiceSourceObj = new ChoiceSource($dataObj, (int) $source['id'], (string) $source['valueColumn'], (string) $source['labelColumn']);
                 $choiceSourceObj->setIdColumn((string) $source['idColumn']);
                 $dataObj->setChoiceSource($choiceSourceObj);
                 break;
                 // only one source
             }
         }
     }
     if ($data->Table) {
         $table = $data->Table;
         $tableObj = new Table($dataObj, (string) $table['id']);
         $tableObj->setName((string) $table['name']);
         $tableObj->setLabel((string) $table['label']);
         $tableObj->setDescription((string) $table->Description);
         foreach ($table->Column as $column) {
             $columnObj = new Column($tableObj, (int) $column['id'], (string) $column['name'], (string) $column['type']);
             $columnObj->setLabel((string) $column['label']);
             $tableObj->addColumn($columnObj);
         }
         $dataObj->setTable($tableObj);
     }
     $dataObj->setDescription((string) $data->Description);
     return $dataObj;
 }
Exemplo n.º 20
0
 public function testHasPlatform()
 {
     $column = new Column();
     $this->assertFalse($column->hasPlatform());
     $table = new Table();
     $table->addColumn($column);
     $this->assertFalse($column->hasPlatform());
     $database = new Database();
     $database->addTable($table);
     $this->assertFalse($column->hasPlatform());
     $platform = new DefaultPlatform();
     $database->setPlatform($platform);
     $this->assertTrue($column->hasPlatform());
 }
Exemplo n.º 21
0
 public function providerForTestGetForeignKeysDDL()
 {
     $table1 = new Table('foo');
     $column1 = new Column('bar_id');
     $column1->getDomain()->copy(new Domain('FOOTYPE'));
     $table1->addColumn($column1);
     $table2 = new Table('bar');
     $column2 = new Column('id');
     $column2->getDomain()->copy(new Domain('BARTYPE'));
     $table2->addColumn($column2);
     $fk = new ForeignKey('foo_bar_FK');
     $fk->setForeignTableCommonName('bar');
     $fk->addReference($column1, $column2);
     $fk->setOnDelete('CASCADE');
     $table1->addForeignKey($fk);
     $column3 = new Column('baz_id');
     $column3->getDomain()->copy(new Domain('BAZTYPE'));
     $table1->addColumn($column3);
     $table3 = new Table('baz');
     $column4 = new Column('id');
     $column4->getDomain()->copy(new Domain('BAZTYPE'));
     $table3->addColumn($column4);
     $fk = new ForeignKey('foo_baz_FK');
     $fk->setForeignTableCommonName('baz');
     $fk->addReference($column3, $column4);
     $fk->setOnDelete('SETNULL');
     $table1->addForeignKey($fk);
     return array(array($table1));
 }
Exemplo n.º 22
0
require_once 'require/tables/CheckboxColumn.php';
require_once 'require/tables/ActionsColumn.php';
require_once 'require/tables/LinkColumn.php';
require_once MAIN_SECTIONS_DIR . 'ms_users/lib/profile_functions.php';
global $l;
// Remove a profile ?
if ($protectedGet['action'] == 'delete') {
    remove_profile($protectedGet['profile_id']);
}
// SETUP
$form_name = 'ms_profiles';
$profiles = get_profiles();
$detail_url = 'index.php?' . PAG_INDEX . '=' . $pages_refs['ms_profile_details'] . '&profile_id=';
$delete_url = 'index.php?' . PAG_INDEX . '=' . $pages_refs['ms_profiles'] . '&action=delete&profile_id=';
$table = new Table($form_name);
$table->addColumn(new CheckboxColumn('name'));
$table->addColumn(new LinkColumn('name', $l->g(1402), $detail_url, array('required' => true, 'idProperty' => 'name')));
$table->addColumn(new LinkColumn('label_translated', $l->g(1411), $detail_url, array('required' => true, 'idProperty' => 'name')));
$table->addColumn(new ActionsColumn(array($detail_url => 'glyphicon glyphicon-edit', $delete_url => 'glyphicon glyphicon-remove'), 'name'));
if (AJAX) {
    $ajax = true;
    parse_str($protectedPost['ocs']['0'], $params);
    $protectedPost += $params;
    $data = array();
    foreach ($profiles as $profile) {
        $profileData = array();
        foreach ($table->getColumns() as $name => $col) {
            $profileData[$name] = $col->format($profile);
        }
        $data[] = $profileData;
    }
Exemplo n.º 23
0
 public function providerForTestGetModifyColumnsDDL()
 {
     $t1 = new Table('foo');
     $c1 = new Column('bar1');
     $c1->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
     $c1->getDomain()->replaceSize(2);
     $t1->addColumn($c1);
     $c2 = new Column('bar2');
     $c2->getDomain()->setType('INTEGER');
     $c2->getDomain()->setSqlType('INTEGER');
     $t1->addColumn($c2);
     $t2 = new Table('foo');
     $c3 = new Column('bar1');
     $c3->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
     $c3->getDomain()->replaceSize(3);
     $t2->addColumn($c3);
     $c4 = new Column('bar2');
     $c4->getDomain()->setType('INTEGER');
     $c4->getDomain()->setSqlType('INTEGER');
     $c4->setNotNull(true);
     $t2->addColumn($c4);
     return array(array(array(PropelColumnComparator::computeDiff($c1, $c3), PropelColumnComparator::computeDiff($c2, $c4))));
 }
Exemplo n.º 24
0
 public function testCommaInEnumValueSet()
 {
     $column = new Column();
     $table = new Table();
     $database = new Database();
     $platform = new DefaultPlatform();
     $table->addColumn($column);
     $database->addTable($table);
     $database->setPlatform($platform);
     $column->loadFromXML(array('type' => PropelTypes::ENUM, 'valueSet' => 'Foo, Bar, "Foo, Bar"'));
     $valueSet = $column->getValueSet();
     $this->assertCount(3, $valueSet);
     $this->assertEquals('Foo', $valueSet[0]);
     $this->assertEquals('Bar', $valueSet[1]);
     $this->assertEquals('Foo, Bar', $valueSet[2]);
 }
 public function testValidateReturnsFalseWhenTwoColumnssHaveSamePhpName()
 {
     $column1 = new Column('foo');
     $column2 = new Column('bar');
     $column2->setPhpName('Foo');
     $table = new Table('foo_table');
     $table->addColumn($column1);
     $table->addColumn($column2);
     $appData = $this->getAppDataForTable($table);
     $validator = new PropelSchemaValidator($appData);
     $this->assertFalse($validator->validate());
     $this->assertContains('Column "bar" declares a phpName already used in table "foo_table"', $validator->getErrors());
 }
 public function testCompareSeveralRenamedSameTables()
 {
     $d1 = new Database();
     $t1 = new Table('table1');
     $c1 = new Column('col1');
     $c1->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $t1->addColumn($c1);
     $d1->addTable($t1);
     $t2 = new Table('table2');
     $c2 = new Column('col1');
     $c2->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $t2->addColumn($c2);
     $d1->addTable($t2);
     $t3 = new Table('table3');
     $c3 = new Column('col1');
     $c3->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $t3->addColumn($c3);
     $d1->addTable($t3);
     $d2 = new Database();
     $t4 = new Table('table4');
     $c4 = new Column('col1');
     $c4->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $t4->addColumn($c4);
     $d2->addTable($t4);
     $t5 = new Table('table5');
     $c5 = new Column('col1');
     $c5->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $t5->addColumn($c5);
     $d2->addTable($t5);
     $t6 = new Table('table3');
     $c6 = new Column('col1');
     $c6->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $t6->addColumn($c6);
     $d2->addTable($t6);
     $dc = new PropelDatabaseComparator();
     $dc->setFromDatabase($d1);
     $dc->setToDatabase($d2);
     $nbDiffs = $dc->compareTables();
     $databaseDiff = $dc->getDatabaseDiff();
     $this->assertEquals(2, $nbDiffs);
     $this->assertEquals(2, count($databaseDiff->getRenamedTables()));
     $this->assertEquals(array('table1' => 'table4', 'table2' => 'table5'), $databaseDiff->getRenamedTables());
     $this->assertEquals(array(), $databaseDiff->getAddedTables());
     $this->assertEquals(array(), $databaseDiff->getRemovedTables());
 }
 public function testCompareSeveralTableDifferences()
 {
     $d1 = new Database();
     $t1 = new Table('Foo_Table');
     $c1 = new Column('Foo');
     $c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $c1->getDomain()->replaceScale(2);
     $c1->getDomain()->replaceSize(3);
     $c1->setNotNull(true);
     $c1->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
     $t1->addColumn($c1);
     $d1->addTable($t1);
     $t2 = new Table('Bar');
     $c2 = new Column('Bar_Column');
     $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $t2->addColumn($c2);
     $d1->addTable($t2);
     $t11 = new Table('Baz');
     $d1->addTable($t11);
     $d2 = new Database();
     $t3 = new Table('Foo_Table');
     $c3 = new Column('Foo1');
     $c3->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $c3->getDomain()->replaceScale(2);
     $c3->getDomain()->replaceSize(3);
     $c3->setNotNull(true);
     $c3->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
     $t3->addColumn($c3);
     $d2->addTable($t3);
     $t4 = new Table('Bar2');
     $c4 = new Column('Bar_Column');
     $c4->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $t4->addColumn($c4);
     $d2->addTable($t4);
     $t5 = new Table('Biz');
     $c5 = new Column('Biz_Column');
     $c5->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $t5->addColumn($c5);
     $d2->addTable($t5);
     // Foo_Table was modified, Bar was renamed, Baz was removed, Biz was added
     $dc = new PropelDatabaseComparator();
     $dc->setFromDatabase($d1);
     $dc->setToDatabase($d2);
     $nbDiffs = $dc->compareTables();
     $databaseDiff = $dc->getDatabaseDiff();
     $this->assertEquals(4, $nbDiffs);
     $this->assertEquals(array('Bar' => 'Bar2'), $databaseDiff->getRenamedTables());
     $this->assertEquals(array('Biz' => $t5), $databaseDiff->getAddedTables());
     $this->assertEquals(array('Baz' => $t11), $databaseDiff->getRemovedTables());
     $tableDiff = PropelTableComparator::computeDiff($t1, $t3);
     $this->assertEquals(array('Foo_Table' => $tableDiff), $databaseDiff->getModifiedTables());
 }
Exemplo n.º 28
0
 /**
  * Creates a column definition as required by the DBAL from an ORM field mapping definition.
  *
  * @param ClassMetadata $class The class that owns the field mapping.
  * @param array $mapping The field mapping.
  * @param Table $table
  * @return array The portable column definition as required by the DBAL.
  */
 private function _gatherColumn($class, array $mapping, $table)
 {
     $columnName = $this->quoteStrategy->getColumnName($mapping['fieldName'], $class, $this->platform);
     $columnType = $mapping['type'];
     $options = array();
     $options['length'] = isset($mapping['length']) ? $mapping['length'] : null;
     $options['notnull'] = isset($mapping['nullable']) ? !$mapping['nullable'] : true;
     if ($class->isInheritanceTypeSingleTable() && count($class->parentClasses) > 0) {
         $options['notnull'] = false;
     }
     $options['platformOptions'] = array();
     $options['platformOptions']['version'] = $class->isVersioned && $class->versionField == $mapping['fieldName'] ? true : false;
     if (strtolower($columnType) == 'string' && $options['length'] === null) {
         $options['length'] = 255;
     }
     if (isset($mapping['precision'])) {
         $options['precision'] = $mapping['precision'];
     }
     if (isset($mapping['scale'])) {
         $options['scale'] = $mapping['scale'];
     }
     if (isset($mapping['default'])) {
         $options['default'] = $mapping['default'];
     }
     if (isset($mapping['columnDefinition'])) {
         $options['columnDefinition'] = $mapping['columnDefinition'];
     }
     if (isset($mapping['options'])) {
         $knownOptions = array('comment', 'unsigned', 'fixed', 'default');
         foreach ($knownOptions as $knownOption) {
             if (isset($mapping['options'][$knownOption])) {
                 $options[$knownOption] = $mapping['options'][$knownOption];
                 unset($mapping['options'][$knownOption]);
             }
         }
         $options['customSchemaOptions'] = $mapping['options'];
     }
     if ($class->isIdGeneratorIdentity() && $class->getIdentifierFieldNames() == array($mapping['fieldName'])) {
         $options['autoincrement'] = true;
     }
     if ($class->isInheritanceTypeJoined() && $class->name != $class->rootEntityName) {
         $options['autoincrement'] = false;
     }
     if ($table->hasColumn($columnName)) {
         // required in some inheritance scenarios
         $table->changeColumn($columnName, $options);
     } else {
         $table->addColumn($columnName, $columnType, $options);
     }
     $isUnique = isset($mapping['unique']) ? $mapping['unique'] : false;
     if ($isUnique) {
         $table->addUniqueIndex(array($columnName));
     }
 }
Exemplo n.º 29
0
 public function getTablesFromZendDb($db)
 {
     $table_list = $db->listTables();
     foreach ($table_list as $table_name) {
         $table = new Table($table_name);
         $this->_tables[$table_name] = $table;
         $column_list = $db->describeTable($table_name);
         foreach ($column_list as $column_name => $attributes) {
             if ($attributes['PRIMARY']) {
                 $table->setPrimaryKey($column_name);
             }
             $table->addColumn(new Column($column_name));
         }
     }
     return $this;
 }