Commit 7b53b5e8 authored by Eugene Pisarchik's avatar Eugene Pisarchik

reverted public api changes and removed not necessary public methods

parent e5c2695d
......@@ -742,7 +742,7 @@ class MySqlPlatform extends AbstractPlatform
foreach ($diff->changedIndexes as $changedIndex) {
// Changed primary key
if ($changedIndex->isPrimary() && $diff->fromTable instanceof Table) {
foreach ($diff->fromTable->getPrimaryKeyColumnNames() as $columnName) {
foreach ($diff->fromTable->getPrimaryKeyColumns() as $columnName) {
$column = $diff->fromTable->getColumn($columnName);
// Check if an autoincrement column was dropped from the primary key.
......
......@@ -621,58 +621,38 @@ class Table extends AbstractAsset
*/
public function getColumns()
{
return array_merge($this->getPrimaryKeyColumns(), $this->getForeignKeyColumns(), $this->_columns);
}
$primaryKeyColumns = [];
if ($this->hasPrimaryKey()) {
$primaryKeyColumns = $this->filterColumns($this->getPrimaryKey()->getColumns());
}
/**
* Returns primary key columns
* @return Column[]
*/
public function getPrimaryKeyColumns()
{
$primaryKeyColumnNames = $this->getPrimaryKeyColumnNames();
return array_filter($this->_columns, function ($key) use ($primaryKeyColumnNames) {
return in_array($key, $primaryKeyColumnNames);
}, ARRAY_FILTER_USE_KEY);
return array_merge($primaryKeyColumns, $this->getForeignKeyColumns(), $this->_columns);
}
/**
* Returns foreign key columns
* @return Column[]
*/
public function getForeignKeyColumns()
private function getForeignKeyColumns()
{
$foreignKeyColumnNames = $this->getForeignKeyColumnNames();
return array_filter($this->_columns, function ($key) use ($foreignKeyColumnNames) {
return in_array($key, $foreignKeyColumnNames);
}, ARRAY_FILTER_USE_KEY);
}
/**
* Returns primary key column names
* @return array
*/
public function getPrimaryKeyColumnNames()
{
$primaryKeyColumnNames = [];
if ($this->hasPrimaryKey()) {
$primaryKeyColumnNames = $this->getPrimaryKey()->getColumns();
$foreignKeyColumns = [];
foreach ($this->getForeignKeys() as $foreignKey) {
/* @var $foreignKey ForeignKeyConstraint */
$foreignKeyColumns = array_merge($foreignKeyColumns, $foreignKey->getColumns());
}
return $primaryKeyColumnNames;
return $this->filterColumns($foreignKeyColumns);
}
/**
* Returns foreign key column names
* @return array
* Returns only columns that have specified names
* @param array $columnNames
* @return Column[]
*/
public function getForeignKeyColumnNames()
private function filterColumns(array $columnNames)
{
$foreignKeyColumnNames = [];
foreach ($this->getForeignKeys() as $foreignKey) {
/* @var $foreignKey ForeignKeyConstraint */
$foreignKeyColumnNames = array_merge($foreignKeyColumnNames, $foreignKey->getColumns());
}
return $foreignKeyColumnNames;
return array_filter($this->_columns, function ($columnName) use ($columnNames) {
return in_array($columnName, $columnNames, true);
}, ARRAY_FILTER_USE_KEY);
}
/**
......@@ -722,6 +702,21 @@ class Table extends AbstractAsset
return $this->getIndex($this->_primaryKeyName);
}
/**
* Returns the primary key columns.
*
* @return array
*
* @throws DBALException
*/
public function getPrimaryKeyColumns()
{
if ( ! $this->hasPrimaryKey()) {
throw new DBALException("Table " . $this->getName() . " has no primary key.");
}
return $this->getPrimaryKey()->getColumns();
}
/**
* Returns whether this table has a primary key.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment