mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-02 12:34:59 +02:00
[ticket/16741] Split of callable into schema_perform_changes()
PHPBB3-16741
This commit is contained in:
parent
81cddb2bc6
commit
66ecc0c19c
@ -182,87 +182,9 @@ class doctrine implements tools_interface
|
||||
}
|
||||
|
||||
return $this->alter_schema(
|
||||
function (Schema $schema) use($schema_changes): void
|
||||
function (Schema $schema) use ($schema_changes): void
|
||||
{
|
||||
$mapping = [
|
||||
'drop_tables' => [
|
||||
'method' => 'schema_drop_table',
|
||||
'use_key' => false,
|
||||
],
|
||||
'add_tables' => [
|
||||
'method' => 'schema_create_table',
|
||||
'use_key' => true,
|
||||
],
|
||||
'change_columns' => [
|
||||
'method' => 'schema_column_change_add',
|
||||
'use_key' => true,
|
||||
'per_table' => true,
|
||||
],
|
||||
'add_columns' => [
|
||||
'method' => 'schema_column_add',
|
||||
'use_key' => true,
|
||||
'per_table' => true,
|
||||
],
|
||||
'drop_columns' => [
|
||||
'method' => 'schema_column_remove',
|
||||
'use_key' => false,
|
||||
'per_table' => true,
|
||||
],
|
||||
'drop_keys' => [
|
||||
'method' => 'schema_index_drop',
|
||||
'use_key' => false,
|
||||
'per_table' => true,
|
||||
],
|
||||
'add_primary_keys' => [
|
||||
'method' => 'schema_create_primary_key',
|
||||
'use_key' => true,
|
||||
],
|
||||
'add_unique_index' => [
|
||||
'method' => 'schema_create_unique_index',
|
||||
'use_key' => true,
|
||||
'per_table' => true,
|
||||
],
|
||||
'add_index' => [
|
||||
'method' => 'schema_create_index',
|
||||
'use_key' => true,
|
||||
'per_table' => true,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($mapping as $action => $params)
|
||||
{
|
||||
if (array_key_exists($action, $schema_changes))
|
||||
{
|
||||
foreach ($schema_changes[$action] as $table_name => $table_data)
|
||||
{
|
||||
if (array_key_exists('per_table', $params) && $params['per_table'])
|
||||
{
|
||||
foreach ($table_data as $key => $data)
|
||||
{
|
||||
if ($params['use_key'] == false)
|
||||
{
|
||||
$this->{$params['method']}($schema, $table_name, $data, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->{$params['method']}($schema, $table_name, $key, $data, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($params['use_key'] == false)
|
||||
{
|
||||
$this->{$params['method']}($schema, $table_data, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->{$params['method']}($schema, $table_name, $table_data, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->schema_perform_changes($schema, $schema_changes);
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -558,6 +480,95 @@ class doctrine implements tools_interface
|
||||
call_user_func($callback, $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform schema changes
|
||||
*
|
||||
* @param Schema $schema
|
||||
* @param array $schema_changes
|
||||
*/
|
||||
protected function schema_perform_changes(Schema $schema, array $schema_changes): void
|
||||
{
|
||||
$mapping = [
|
||||
'drop_tables' => [
|
||||
'method' => 'schema_drop_table',
|
||||
'use_key' => false,
|
||||
],
|
||||
'add_tables' => [
|
||||
'method' => 'schema_create_table',
|
||||
'use_key' => true,
|
||||
],
|
||||
'change_columns' => [
|
||||
'method' => 'schema_column_change_add',
|
||||
'use_key' => true,
|
||||
'per_table' => true,
|
||||
],
|
||||
'add_columns' => [
|
||||
'method' => 'schema_column_add',
|
||||
'use_key' => true,
|
||||
'per_table' => true,
|
||||
],
|
||||
'drop_columns' => [
|
||||
'method' => 'schema_column_remove',
|
||||
'use_key' => false,
|
||||
'per_table' => true,
|
||||
],
|
||||
'drop_keys' => [
|
||||
'method' => 'schema_index_drop',
|
||||
'use_key' => false,
|
||||
'per_table' => true,
|
||||
],
|
||||
'add_primary_keys' => [
|
||||
'method' => 'schema_create_primary_key',
|
||||
'use_key' => true,
|
||||
],
|
||||
'add_unique_index' => [
|
||||
'method' => 'schema_create_unique_index',
|
||||
'use_key' => true,
|
||||
'per_table' => true,
|
||||
],
|
||||
'add_index' => [
|
||||
'method' => 'schema_create_index',
|
||||
'use_key' => true,
|
||||
'per_table' => true,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($mapping as $action => $params)
|
||||
{
|
||||
if (array_key_exists($action, $schema_changes))
|
||||
{
|
||||
foreach ($schema_changes[$action] as $table_name => $table_data)
|
||||
{
|
||||
if (array_key_exists('per_table', $params) && $params['per_table'])
|
||||
{
|
||||
foreach ($table_data as $key => $data)
|
||||
{
|
||||
if ($params['use_key'] == false)
|
||||
{
|
||||
$this->{$params['method']}($schema, $table_name, $data, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->{$params['method']}($schema, $table_name, $key, $data, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($params['use_key'] == false)
|
||||
{
|
||||
$this->{$params['method']}($schema, $table_data, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->{$params['method']}($schema, $table_name, $table_data, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the schema representation with a new table.
|
||||
* Returns null in case of errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user