mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-27 04:18:55 +00:00
Merge af93b1aee9
into 2fce8aeb3e
This commit is contained in:
commit
47d45c4138
1 changed files with 76 additions and 15 deletions
|
@ -378,6 +378,46 @@ class doctrine implements tools_interface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of the table index names and relevant data in format
|
||||||
|
* [
|
||||||
|
* [$index_name] = [
|
||||||
|
* 'columns' => (array) $index_columns,
|
||||||
|
* 'flags' => (array) $index_flags,
|
||||||
|
* 'options' => (array) $index_options,
|
||||||
|
* 'is_primary'=> (bool) $isPrimary,
|
||||||
|
* 'is_unique' => (bool) $isUnique,
|
||||||
|
* 'is_simple' => (bool) $isSimple,
|
||||||
|
* ]
|
||||||
|
*
|
||||||
|
* @param Schema $schema
|
||||||
|
* @param string $table_name
|
||||||
|
* @param string $column_name
|
||||||
|
* @param array $column_data
|
||||||
|
* @param bool $safe_check
|
||||||
|
*
|
||||||
|
* @throws SchemaException
|
||||||
|
*/
|
||||||
|
public function sql_get_table_index_data(string $table_name): array
|
||||||
|
{
|
||||||
|
$schema = $this->get_schema();
|
||||||
|
$table = $schema->getTable($table_name);
|
||||||
|
$indexes = [];
|
||||||
|
foreach ($table->getIndexes() as $index)
|
||||||
|
{
|
||||||
|
$indexes[$index->getName()] = [
|
||||||
|
'columns' => array_map('strtolower', $index->getUnquotedColumns()),
|
||||||
|
'flags' => $index->getFlags(),
|
||||||
|
'options' => $index->getOptions(),
|
||||||
|
'is_primary'=> $index->isPrimary(),
|
||||||
|
'is_unique' => $index->isUnique(),
|
||||||
|
'is_simple' => $index->isSimpleIndex(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $indexes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of indices for either unique and primary keys, or simple indices.
|
* Returns an array of indices for either unique and primary keys, or simple indices.
|
||||||
*
|
*
|
||||||
|
@ -629,25 +669,16 @@ class doctrine implements tools_interface
|
||||||
foreach ($table_data['KEYS'] as $key_name => $key_data)
|
foreach ($table_data['KEYS'] as $key_name => $key_data)
|
||||||
{
|
{
|
||||||
$columns = (is_array($key_data[1])) ? $key_data[1] : [$key_data[1]];
|
$columns = (is_array($key_data[1])) ? $key_data[1] : [$key_data[1]];
|
||||||
|
$options = [];
|
||||||
// Supports key columns defined with there length
|
$this->schema_get_index_key_data($columns, $options);
|
||||||
$columns = array_map(function (string $column)
|
|
||||||
{
|
|
||||||
if (strpos($column, ':') !== false)
|
|
||||||
{
|
|
||||||
$parts = explode(':', $column, 2);
|
|
||||||
return $parts[0];
|
|
||||||
}
|
|
||||||
return $column;
|
|
||||||
}, $columns);
|
|
||||||
|
|
||||||
if ($key_data[0] === 'UNIQUE')
|
if ($key_data[0] === 'UNIQUE')
|
||||||
{
|
{
|
||||||
$table->addUniqueIndex($columns, $key_name);
|
$table->addUniqueIndex($columns, $key_name, $options);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$table->addIndex($columns, $key_name);
|
$table->addIndex($columns, $key_name, [], $options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -830,7 +861,10 @@ class doctrine implements tools_interface
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$table->addIndex($columns, $index_name);
|
$options = [];
|
||||||
|
$this->schema_get_index_key_data($columns, $options);
|
||||||
|
|
||||||
|
$table->addIndex($columns, $index_name, [], $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -852,7 +886,10 @@ class doctrine implements tools_interface
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$table->addUniqueIndex($columns, $index_name);
|
$options = [];
|
||||||
|
$this->schema_get_index_key_data($columns, $options);
|
||||||
|
|
||||||
|
$table->addUniqueIndex($columns, $index_name, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -891,6 +928,30 @@ class doctrine implements tools_interface
|
||||||
$table->setPrimaryKey($columns);
|
$table->setPrimaryKey($columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if index data contains key length
|
||||||
|
* and put it into $options['lengths'] array.
|
||||||
|
* Handles key length in formats of 'keyname:123' or 'keyname(123)'
|
||||||
|
*
|
||||||
|
* @param array $columns
|
||||||
|
* @param array $options
|
||||||
|
*/
|
||||||
|
protected function schema_get_index_key_data(array &$columns, array &$options): void
|
||||||
|
{
|
||||||
|
if (!empty($columns))
|
||||||
|
{
|
||||||
|
$columns = array_map(function (string $column) use (&$options)
|
||||||
|
{
|
||||||
|
if (preg_match('/^([a-zA-Z0-9_]+)(?:(?:\:|\()([0-9]{1,3})\)?)?$/', $column, $parts))
|
||||||
|
{
|
||||||
|
$options['lengths'][] = $parts[2] ?? null;
|
||||||
|
return $parts[1];
|
||||||
|
}
|
||||||
|
return $column;
|
||||||
|
}, $columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recreate an index of a table
|
* Recreate an index of a table
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue