mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/16741] Split of callable into schema_perform_changes()
PHPBB3-16741
This commit is contained in:
parent
81cddb2bc6
commit
66ecc0c19c
1 changed files with 91 additions and 80 deletions
|
@ -184,85 +184,7 @@ class doctrine implements tools_interface
|
||||||
return $this->alter_schema(
|
return $this->alter_schema(
|
||||||
function (Schema $schema) use ($schema_changes): void
|
function (Schema $schema) use ($schema_changes): void
|
||||||
{
|
{
|
||||||
$mapping = [
|
$this->schema_perform_changes($schema, $schema_changes);
|
||||||
'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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -558,6 +480,95 @@ class doctrine implements tools_interface
|
||||||
call_user_func($callback, $table);
|
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.
|
* Update the schema representation with a new table.
|
||||||
* Returns null in case of errors
|
* Returns null in case of errors
|
||||||
|
|
Loading…
Add table
Reference in a new issue