예제 #1
0
 /**
  * @return array
  */
 public function common()
 {
     $origin = [];
     foreach ($this->origin->getColumns() as $column) {
         $origin[] = $column->getName();
     }
     $destination = [];
     foreach ($this->destination->getColumns() as $column) {
         $destination[] = $column->getName();
     }
     $intersection = array_intersect($origin, $destination);
     sort($intersection);
     return $intersection;
 }
예제 #2
0
파일: TableTest.php 프로젝트: seytar/psx
 public function testTable()
 {
     $table = new Table($this->connection, 'foo_table', array('bar' => TableInterface::TYPE_INT), array());
     $this->assertEquals('foo_table', $table->getName());
     $this->assertEquals(array('bar' => TableInterface::TYPE_INT), $table->getColumns());
     $this->assertEquals(array(), $table->getConnections());
     $table->addConnection('bar', 'bar_table');
     $this->assertEquals(array('bar' => 'bar_table'), $table->getConnections());
 }
 protected function addPopulateFromVersion(&$script)
 {
     $ARclassName = $this->getActiveRecordClassName();
     $versionTable = $this->behavior->getVersionTable();
     $versionColumnName = $versionTable->getColumn($this->behavior->getParameter('version_column'))->getPhpName();
     $versionARClassname = $this->builder->getNewStubObjectBuilder($versionTable)->getClassname();
     $tablePKs = $this->table->getPrimaryKey();
     $primaryKeyName = $tablePKs[0]->getPhpName();
     $script .= "\n/**\n * Sets the properties of the curent object to the value they had at a specific version\n *\n * @param   {$versionARClassname} \$version The version object to use\n * @param   PropelPDO \$con the connection to use\n * @param   array \$loadedObjects objects thats been loaded in a chain of populateFromVersion calls on referrer or fk objects.\n *\n * @return  {$ARclassName} The current object (for fluent API support)\n */\npublic function populateFromVersion(\$version, \$con = null, &\$loadedObjects = array())\n{\n";
     $script .= "\n    \$loadedObjects['{$ARclassName}'][\$version->get{$primaryKeyName}()][\$version->get{$versionColumnName}()] = \$this;";
     foreach ($this->table->getColumns() as $col) {
         $script .= "\n    \$this->set" . $col->getPhpName() . "(\$version->get" . $col->getPhpName() . "());";
     }
     foreach ($this->behavior->getVersionableFks() as $fk) {
         $foreignTable = $fk->getForeignTable();
         $foreignVersionTable = $fk->getForeignTable()->getBehavior($this->behavior->getName())->getVersionTable();
         $relatedClassname = $this->builder->getNewStubObjectBuilder($foreignTable)->getClassname();
         $relatedVersionQueryBuilder = $this->builder->getNewStubQueryBuilder($foreignVersionTable);
         $this->builder->declareClassFromBuilder($relatedVersionQueryBuilder);
         $relatedVersionQueryClassname = $relatedVersionQueryBuilder->getClassname();
         $fkColumnName = $fk->getLocalColumnName();
         $fkColumnPhpName = $fk->getLocalColumn()->getPhpName();
         $fkVersionColumnPhpName = $versionTable->getColumn($fkColumnName . '_version')->getPhpName();
         $fkPhpname = $this->builder->getFKPhpNameAffix($fk, $plural = false);
         // FIXME: breaks lazy-loading
         $script .= "\n    if (\$fkValue = \$version->get{$fkColumnPhpName}()) {\n        if (isset(\$loadedObjects['{$relatedClassname}']) && isset(\$loadedObjects['{$relatedClassname}'][\$fkValue]) && isset(\$loadedObjects['{$relatedClassname}'][\$fkValue][\$version->get{$fkVersionColumnPhpName}()])) {\n            \$related = \$loadedObjects['{$relatedClassname}'][\$fkValue][\$version->get{$fkVersionColumnPhpName}()];\n        } else {\n            \$related = new {$relatedClassname}();\n            \$relatedVersion = {$relatedVersionQueryClassname}::create()\n                ->filterBy{$fk->getForeignColumn()->getPhpName()}(\$fkValue)\n                ->filterByVersion(\$version->get{$fkVersionColumnPhpName}())\n                ->findOne(\$con);\n            \$related->populateFromVersion(\$relatedVersion, \$con, \$loadedObjects);\n            \$related->setNew(false);\n        }\n        \$this->set{$fkPhpname}(\$related);\n    }";
     }
     foreach ($this->behavior->getVersionableReferrers() as $fk) {
         $foreignTable = $fk->getTable();
         $foreignBehavior = $foreignTable->getBehavior($this->behavior->getName());
         $foreignVersionTable = $foreignBehavior->getVersionTable();
         $fkColumn = $foreignVersionTable->getFirstPrimaryKeyColumn();
         $fkVersionColumn = $foreignVersionTable->getColumn($this->behavior->getParameter('version_column'));
         $relatedClassname = $this->builder->getNewStubObjectBuilder($foreignTable)->getClassname();
         $relatedVersionQueryBuilder = $this->builder->getNewStubQueryBuilder($foreignVersionTable);
         $this->builder->declareClassFromBuilder($relatedVersionQueryBuilder);
         $relatedVersionQueryClassname = $relatedVersionQueryBuilder->getClassname();
         $relatedVersionPeerBuilder = $this->builder->getNewStubPeerBuilder($foreignVersionTable);
         $relatedVersionPeerClassname = $relatedVersionPeerBuilder->getClassname();
         if ($fk->isLocalPrimaryKey()) {
             $fkPhpName = $this->builder->getRefFKPhpNameAffix($fk, $plural = false);
             $fkColumnId = $this->behavior->getReferrerIdsColumn($fk);
             $fkColumnVersion = $this->behavior->getReferrerVersionsColumn($fk);
             $fkColumnVersionPhpName = $fkColumnVersion->getPhpName();
             $this->builder->declareClassFromBuilder($relatedVersionPeerBuilder);
             $script .= "\n    if (\$fkValue = \$version->get{$fkColumnId->getPhpName()}()) {\n        if (isset(\$loadedObjects['{$relatedClassname}']) && isset(\$loadedObjects['{$relatedClassname}'][\$fkValue]) && isset(\$loadedObjects['{$relatedClassname}'][\$fkValue][\$version->get{$fkColumnVersionPhpName}()])) {\n            \$related = \$loadedObjects['{$relatedClassname}'][\$fkValue][\$version->get{$fkColumnVersionPhpName}()];\n        } else {\n            \$related = new {$relatedClassname}();\n            \$relatedVersion = {$relatedVersionQueryClassname}::create()\n                ->filterBy{$fk->getLocalColumn()->getPhpName()}(\$fkValue)\n                ->filterByVersion(\$version->get{$fkColumnVersionPhpName}())\n                ->findOne(\$con);\n            \$related->populateFromVersion(\$relatedVersion, \$con, \$loadedObjects);\n            \$related->setNew(false);\n        }\n        \$this->set{$fkPhpName}(\$related);\n    }";
         } else {
             $fkPhpNames = $this->builder->getRefFKPhpNameAffix($fk, $plural = true);
             $fkPhpName = $this->builder->getRefFKPhpNameAffix($fk, $plural = false);
             $fkColumnIds = $this->behavior->getReferrerIdsColumn($fk);
             $fkColumnVersions = $this->behavior->getReferrerVersionsColumn($fk);
             $this->builder->declareClassFromBuilder($relatedVersionPeerBuilder);
             $script .= "\n    if (\$fkValues = \$version->get{$fkColumnIds->getPhpName()}()) {\n        \$this->clear{$fkPhpNames}();\n        \$fkVersions = \$version->get{$fkColumnVersions->getPhpName()}();\n        \$query = {$relatedVersionQueryClassname}::create();\n        foreach (\$fkValues as \$key => \$value) {\n            \$c1 = \$query->getNewCriterion({$this->builder->getColumnConstant($fkColumn, $relatedVersionPeerClassname)}, \$value);\n            \$c2 = \$query->getNewCriterion({$this->builder->getColumnConstant($fkVersionColumn, $relatedVersionPeerClassname)}, \$fkVersions[\$key]);\n            \$c1->addAnd(\$c2);\n            \$query->addOr(\$c1);\n        }\n        foreach (\$query->find(\$con) as \$relatedVersion) {\n            if (isset(\$loadedObjects['{$relatedClassname}']) && isset(\$loadedObjects['{$relatedClassname}'][\$relatedVersion->get{$fkColumn->getPhpName()}()]) && isset(\$loadedObjects['{$relatedClassname}'][\$relatedVersion->get{$fkColumn->getPhpName()}()][\$relatedVersion->get{$fkVersionColumn->getPhpName()}()])) {\n                \$related = \$loadedObjects['{$relatedClassname}'][\$relatedVersion->get{$fkColumn->getPhpName()}()][\$relatedVersion->get{$fkVersionColumn->getPhpName()}()];\n            } else {\n                \$related = new {$relatedClassname}();\n                \$related->populateFromVersion(\$relatedVersion, \$con, \$loadedObjects);\n                \$related->setNew(false);\n            }\n            \$this->add{$fkPhpName}(\$related);\n        }\n\n        \$this->resetPartial{$fkPhpNames}(false);\n    }";
         }
     }
     $script .= "\n\n    return \$this;\n}\n";
 }
예제 #4
0
 public function __construct(Table $table, $recordIndex, $rawData = false)
 {
     $this->table = $table;
     $this->recordIndex = $recordIndex;
     $this->choppedData = array();
     if ($rawData && strlen($rawData) > 0) {
         $this->inserted = false;
         $this->deleted = ord($rawData[0]) != '32';
         foreach ($table->getColumns() as $column) {
             $this->choppedData[$column->getName()] = substr($rawData, $column->getBytePos(), $column->getDataLength());
         }
     } else {
         $this->inserted = true;
         $this->deleted = false;
         foreach ($table->getColumns() as $column) {
             $this->choppedData[$column->getName()] = str_pad('', $column->getDataLength(), chr(0));
         }
     }
 }
예제 #5
0
 protected function validateTableColumns(Table $table)
 {
     if (!$table->hasPrimaryKey() && !$table->isSkipSql()) {
         $this->errors[] = sprintf('Table "%s" does not have a primary key defined. Propel requires all tables to have a primary key.', $table->getName());
     }
     $phpNames = array();
     foreach ($table->getColumns() as $column) {
         if (in_array($column->getPhpName(), $phpNames)) {
             $this->errors[] = sprintf('Column "%s" declares a phpName already used in table "%s"', $column->getName(), $table->getName());
         }
         $phpNames[] = $column->getPhpName();
     }
 }
예제 #6
0
 public function getAddTableDDL(Table $table)
 {
     $tableDescription = $table->hasDescription() ? $this->getCommentLineDDL($table->getDescription()) : '';
     $lines = array();
     foreach ($table->getColumns() as $column) {
         $lines[] = $this->getColumnDDL($column);
     }
     if ($table->hasPrimaryKey() && count($table->getPrimaryKey()) > 1) {
         $lines[] = $this->getPrimaryKeyDDL($table);
     }
     foreach ($table->getUnices() as $unique) {
         $lines[] = $this->getUniqueDDL($unique);
     }
     $sep = ",\n\t";
     $pattern = "\n%sCREATE TABLE %s\n(\n\t%s\n);\n";
     return sprintf($pattern, $tableDescription, $this->quoteIdentifier($table->getName()), implode($sep, $lines));
 }
예제 #7
0
파일: Table.php 프로젝트: natronite/caribou
 /**
  * @param Table $old
  * @param Table $new
  * @return bool|string
  */
 public static function computeAlter(Table $old, Table $new)
 {
     $oldColumnNames = array_keys($old->getColumns());
     $newColumnNames = array_keys($new->getColumns());
     $alterLines = [];
     // Check for changed columns
     $possiblyChangedColumnNames = array_intersect($oldColumnNames, $newColumnNames);
     foreach ($possiblyChangedColumnNames as $possiblyChangedColumnName) {
         $oldColumn = $old->getColumn($possiblyChangedColumnName);
         $newColumn = $new->getColumn($possiblyChangedColumnName);
         if ($oldColumn && $newColumn) {
             $alter = Column::computeAlter($oldColumn, $newColumn);
             if ($alter) {
                 $alterLines[] = $alter;
             }
         }
     }
     // check if columns have been added
     $addedColumnNames = array_diff($newColumnNames, $oldColumnNames);
     foreach ($addedColumnNames as $added) {
         $column = $new->getColumn($added);
         $query = "ADD COLUMN " . $column;
         if ($column->isFirst()) {
             $query .= " FIRST";
         } elseif ($column->getAfter() !== false) {
             $query .= " AFTER `" . $column->getAfter() . "`";
         }
         $alterLines[] = $query;
     }
     // check if columns have been removed
     $removedColumnNames = array_diff($oldColumnNames, $newColumnNames);
     foreach ($removedColumnNames as $removedColumnName) {
         $alterLines[] = "DROP COLUMN `" . $removedColumnName . "`";
     }
     if (!empty($alterLines)) {
         return "ALTER TABLE `" . $new->getName() . "`\n\t" . implode(",\n\t", $alterLines);
     }
     return false;
 }
예제 #8
0
 public function getAddTableDDL(Table $table)
 {
     $lines = array();
     foreach ($table->getColumns() as $column) {
         $lines[] = $this->getColumnDDL($column);
     }
     if ($table->hasPrimaryKey()) {
         $lines[] = $this->getPrimaryKeyDDL($table);
     }
     foreach ($table->getUnices() as $unique) {
         $lines[] = $this->getUniqueDDL($unique);
     }
     foreach ($table->getIndices() as $index) {
         $lines[] = $this->getIndexDDL($index);
     }
     foreach ($table->getForeignKeys() as $foreignKey) {
         if ($foreignKey->isSkipSql()) {
             continue;
         }
         $lines[] = str_replace("\n\t", "\n\t\t", $this->getForeignKeyDDL($foreignKey));
     }
     $vendorSpecific = $table->getVendorInfoForType('mysql');
     if ($vendorSpecific->hasParameter('Type')) {
         $mysqlTableType = $vendorSpecific->getParameter('Type');
     } elseif ($vendorSpecific->hasParameter('Engine')) {
         $mysqlTableType = $vendorSpecific->getParameter('Engine');
     } else {
         $mysqlTableType = $this->getDefaultTableEngine();
     }
     $tableOptions = $this->getTableOptions($table);
     if ($table->getDescription()) {
         $tableOptions[] = 'COMMENT=' . $this->quote($table->getDescription());
     }
     $tableOptions = $tableOptions ? ' ' . implode(' ', $tableOptions) : '';
     $sep = ",\n\t";
     $pattern = "\nCREATE TABLE %s\n(\n\t%s\n) %s=%s%s;\n";
     return sprintf($pattern, $this->quoteIdentifier($table->getName()), implode($sep, $lines), $this->getTableEngineKeyword(), $mysqlTableType, $tableOptions);
 }
예제 #9
0
 /**
  * Checks whether the supplied table has a primary string defined.
  *
  * @param  Table $table
  *
  * @return boolean
  */
 protected function hasPrimaryString(Table $table)
 {
     foreach ($table->getColumns() as $column) {
         if ($column->isPrimaryString()) {
             return true;
         }
     }
     return false;
 }
예제 #10
0
$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;
    }
    // JSON OUTPUT
    $response = array('customized' => false, 'draw' => $_POST['draw'], 'data' => $data, 'recordsFiltered' => count($profiles), 'recordsTotal' => count($profiles));
    echo json_encode($response);
} else {
    $ajax = false;
    require_once 'views/users_views.php';
    require_once 'require/function_search.php';
    require_once 'require/tables/TableRenderer.php';
    // HTML OUTPUT
    show_users_left_menu('ms_profiles');
    echo '<div class="right-content">';
예제 #11
0
 /**
  * Build SQL column list
  * @param Table $table
  * @return string
  */
 protected function buildColumnList(Table $table)
 {
     $columns = '';
     foreach ($table->getColumns() as $column) {
         $columns .= ",\n\t{$column->getSQLExpression()}";
     }
     return substr($columns, 3);
     // remove first ', '
 }
 protected function getAddColumnsComments(Table $table)
 {
     $ret = '';
     foreach ($table->getColumns() as $column) {
         $ret .= $this->getAddColumnComment($column);
     }
     return $ret;
 }
예제 #13
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()));
 }
예제 #14
0
 public function getAddTableDDL(Table $table)
 {
     $tableDescription = $table->hasDescription() ? $this->getCommentLineDDL($table->getDescription()) : '';
     $lines = array();
     foreach ($table->getColumns() as $column) {
         $lines[] = $this->getColumnDDL($column);
     }
     foreach ($table->getUnices() as $unique) {
         $lines[] = $this->getUniqueDDL($unique);
     }
     $sep = ",\r\n    ";
     $pattern = "\r\n%sCREATE TABLE %s\r\n(\r\n    %s\r\n)%s;\r\n";
     $ret = sprintf($pattern, $tableDescription, $this->quoteIdentifier($table->getName()), implode($sep, $lines), $this->generateBlockStorage($table));
     $ret .= $this->getAddPrimaryKeyDDL($table);
     $ret .= $this->getAddSequencesDDL($table);
     return $ret;
 }
예제 #15
0
파일: Table.php 프로젝트: vakata/database
 /**
  * Create a relation where each record has many linked records in another table but using a liking table
  * @param  Table   $toTable       the related table definition
  * @param  Table   $pivot         the pivot table definition
  * @param  string|null       $name          the name of the relation (defaults to the related table name)
  * @param  string|array|null $toTableColumn the local columns pointing to the pivot table
  * @param  string|array|null $localColumn   the pivot columns pointing to the related table PK
  * @return self
  */
 public function manyToMany(Table $toTable, Table $pivot, $name = null, $toTableColumn = null, $localColumn = null) : Table
 {
     $pivotColumns = $pivot->getColumns();
     $keymap = [];
     if (!isset($toTableColumn)) {
         $toTableColumn = [];
     }
     if (!is_array($toTableColumn)) {
         $toTableColumn = [$toTableColumn];
     }
     foreach ($this->getPrimaryKey() as $k => $pkField) {
         $key = null;
         if (isset($toTableColumn[$pkField])) {
             $key = $toTableColumn[$pkField];
         } elseif (isset($toTableColumn[$k])) {
             $key = $toTableColumn[$k];
         } else {
             $key = $this->getName() . '_' . $pkField;
         }
         if (!in_array($key, $pivotColumns)) {
             throw new DatabaseException('Missing foreign key mapping');
         }
         $keymap[$pkField] = $key;
     }
     $pivotKeymap = [];
     if (!isset($localColumn)) {
         $localColumn = [];
     }
     if (!is_array($localColumn)) {
         $localColumn = [$localColumn];
     }
     foreach ($toTable->getPrimaryKey() as $k => $pkField) {
         $key = null;
         if (isset($localColumn[$pkField])) {
             $key = $localColumn[$pkField];
         } elseif (isset($localColumn[$k])) {
             $key = $localColumn[$k];
         } else {
             $key = $toTable->getName() . '_' . $pkField;
         }
         if (!in_array($key, $pivotColumns)) {
             throw new DatabaseException('Missing foreign key mapping');
         }
         $pivotKeymap[$key] = $pkField;
     }
     if (!isset($name)) {
         $name = $toTable->getName() . '_' . implode('_', array_keys($keymap));
     }
     $this->relations[$name] = ['name' => $name, 'table' => $toTable, 'keymap' => $keymap, 'many' => true, 'pivot' => $pivot, 'pivot_keymap' => $pivotKeymap, 'sql' => null, 'par' => []];
     return $this;
 }
예제 #16
0
 /**
  * Get the column offsets of the primary key(s) for specified table.
  *
  * @param      Table $tbl
  * @return     array int[] The column offsets of the primary key(s).
  */
 protected function getPrimaryKeyColOffsets(Table $tbl)
 {
     $offsets = array();
     $idx = 0;
     foreach ($tbl->getColumns() as $col) {
         if ($col->isPrimaryKey()) {
             $offsets[] = $idx;
         }
         $idx++;
     }
     return $offsets;
 }
예제 #17
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;
    }
예제 #18
0
 /**
  * Perform upgrade for a table, by comparing one table to an old version
  * of the same table
  *
  * @param Table $old_table
  */
 public function upgrade(Table $old_table)
 {
     $old_columns = $old_table->getColumns();
     $new_columns = $this->getColumns();
     $added_columns = \array_diff_key($new_columns, $old_columns);
     $altered_columns = Tools::array_diff_recursive($old_columns, $new_columns);
     $dropped_columns = \array_keys(array_diff_key($old_columns, $new_columns));
     $sqls = array();
     foreach ($added_columns as $details) {
         $sqls[] = $this->_getAddColumnSQL($details);
     }
     if (count($sqls)) {
         foreach ($sqls as $sqlStmt) {
             if ($sqlStmt) {
                 Statement::getPreparedStatement($sqlStmt)->performQuery();
             }
         }
     }
     $this->_migrateData($old_table);
     $sqls = array();
     foreach ($altered_columns as $column => $details) {
         if (in_array($column, $dropped_columns)) {
             continue;
         }
         $sqls[] = $this->_getAlterColumnSQL($new_columns[$column]);
         $altersql = $this->_getAlterColumnDefaultSQL($new_columns[$column]);
         if ($altersql) {
             $sqls[] = $altersql;
         }
     }
     foreach ($dropped_columns as $details) {
         $sqls[] = $this->_getDropColumnSQL($details);
     }
     if (count($sqls)) {
         foreach ($sqls as $sqlStmt) {
             if ($sqlStmt) {
                 Statement::getPreparedStatement($sqlStmt)->performQuery();
             }
         }
     }
 }
예제 #19
0
 /**
  * Finds the supplied translation table's culture column.
  *
  * @return Column
  *
  * @throws InvalidArgumentException If there is not a column marked as "isCulture"
  */
 protected function getCultureColumn(Table $table)
 {
     foreach ($table->getColumns() as $column) {
         if ('true' == $column->getAttribute('isCulture')) {
             return $column;
         }
     }
     throw new InvalidArgumentException(sprintf('The table "%s" does not have a column marked with the "isCulture" attribute.', $table->getName()));
 }
예제 #20
0
 /**
  * Returns the difference between the tables $table1 and $table2.
  *
  * If there are no differences this method returns the boolean false.
  *
  * @param Table $table1
  * @param Table $table2
  *
  * @return bool|TableDiff
  */
 public function diffTable(Table $table1, Table $table2)
 {
     $changes = 0;
     $tableDifferences = new TableDiff($table1->getName());
     $table1Columns = $table1->getColumns();
     $table2Columns = $table2->getColumns();
     /* See if all the fields in table 1 exist in table 2 */
     foreach ($table2Columns as $columnName => $column) {
         if (!$table1->hasColumn($columnName)) {
             $tableDifferences->addedColumns[$columnName] = $column;
             $changes++;
         }
     }
     /* See if there are any removed fields in table 2 */
     foreach ($table1Columns as $columnName => $column) {
         if (!$table2->hasColumn($columnName)) {
             $tableDifferences->removedColumns[$columnName] = $column;
             $changes++;
         }
     }
     foreach ($table1Columns as $columnName => $column) {
         if ($table2->hasColumn($columnName)) {
             $changedProperties = $this->diffColumn($column, $table2->getColumn($columnName));
             if (count($changedProperties)) {
                 $columnDiff = new ColumnDiff($column->getName(), $table2->getColumn($columnName), $changedProperties);
                 $tableDifferences->changedColumns[$column->getName()] = $columnDiff;
                 $changes++;
             }
         }
     }
     $this->detectColumnRenamings($tableDifferences);
     $table1Indexes = $table1->getIndexes();
     $table2Indexes = $table2->getIndexes();
     foreach ($table2Indexes as $index2Name => $index2Definition) {
         foreach ($table1Indexes as $index1Name => $index1Definition) {
             if ($this->diffIndex($index1Definition, $index2Definition) === false) {
                 unset($table1Indexes[$index1Name]);
                 unset($table2Indexes[$index2Name]);
             } else {
                 if ($index1Name == $index2Name) {
                     $tableDifferences->changedIndexes[$index2Name] = $table2Indexes[$index2Name];
                     unset($table1Indexes[$index1Name]);
                     unset($table2Indexes[$index2Name]);
                     $changes++;
                 }
             }
         }
     }
     foreach ($table1Indexes as $index1Name => $index1Definition) {
         $tableDifferences->removedIndexes[$index1Name] = $index1Definition;
         $changes++;
     }
     foreach ($table2Indexes as $index2Name => $index2Definition) {
         $tableDifferences->addedIndexes[$index2Name] = $index2Definition;
         $changes++;
     }
     $fromFkeys = $table1->getForeignKeys();
     $toFkeys = $table2->getForeignKeys();
     foreach ($fromFkeys as $key1 => $constraint1) {
         foreach ($toFkeys as $key2 => $constraint2) {
             if ($this->diffForeignKey($constraint1, $constraint2) === false) {
                 unset($fromFkeys[$key1]);
                 unset($toFkeys[$key2]);
             } else {
                 if (strtolower($constraint1->getName()) == strtolower($constraint2->getName())) {
                     $tableDifferences->changedForeignKeys[] = $constraint2;
                     $changes++;
                     unset($fromFkeys[$key1]);
                     unset($toFkeys[$key2]);
                 }
             }
         }
     }
     foreach ($fromFkeys as $key1 => $constraint1) {
         $tableDifferences->removedForeignKeys[] = $constraint1;
         $changes++;
     }
     foreach ($toFkeys as $key2 => $constraint2) {
         $tableDifferences->addedForeignKeys[] = $constraint2;
         $changes++;
     }
     return $changes ? $tableDifferences : false;
 }
 private function addFields(\Table $table, $formTypeContent)
 {
     $buildCode = '';
     foreach ($table->getColumns() as $column) {
         if (!$column->isPrimaryKey()) {
             $buildCode .= sprintf("\n        \$builder->add('%s');", lcfirst($column->getPhpName()));
         }
     }
     return str_replace('##BUILD_CODE##', $buildCode, $formTypeContent);
 }