‪TYPO3CMS  10.4
TYPO3\CMS\Core\Database\Schema\ConnectionMigrator Class Reference

Public Member Functions

 __construct (string $connectionName, array $tables)
 
SchemaDiff getSchemaDiff ()
 
array getUpdateSuggestions (bool $remove=false)
 
array install (bool $createOnly=false)
 

Static Public Member Functions

static ConnectionMigrator create (string $connectionName, array $tables)
 

Protected Member Functions

Doctrine DBAL Schema SchemaDiff buildSchemaDiff (bool $renameUnused=true)
 
Doctrine DBAL Schema Schema buildExpectedSchemaDefinitions (string $connectionName)
 
array getNewTableUpdateSuggestions (SchemaDiff $schemaDiff)
 
array getNewFieldUpdateSuggestions (SchemaDiff $schemaDiff)
 
array getChangedTableOptions (SchemaDiff $schemaDiff)
 
array getChangedFieldUpdateSuggestions (SchemaDiff $schemaDiff)
 
array getUnusedTableUpdateSuggestions (SchemaDiff $schemaDiff)
 
array getUnusedFieldUpdateSuggestions (SchemaDiff $schemaDiff)
 
array getDropFieldUpdateSuggestions (SchemaDiff $schemaDiff)
 
array getDropTableUpdateSuggestions (SchemaDiff $schemaDiff)
 
Doctrine DBAL Schema SchemaDiff migrateUnprefixedRemovedTablesToRenames (SchemaDiff $schemaDiff)
 
Doctrine DBAL Schema SchemaDiff migrateUnprefixedRemovedFieldsToRenames (SchemaDiff $schemaDiff)
 
SchemaDiff migrateColumnRenamesToDistinctActions (SchemaDiff $schemaDiff)
 
int getTableRecordCount (string $tableName)
 
string getConnectionNameForTable (string $tableName)
 
string[] calculateUpdateSuggestionsHashes (array $statements)
 
Doctrine DBAL Schema TableDiff[] removeUnrelatedTables (array $tableDiffs, array $validTableNames)
 
Table[] transformTablesForDatabasePlatform (array $tables, Connection $connection)
 
array[] getTableOptions (array $tableNames)
 
Doctrine DBAL Schema Table buildQuotedTable (Table $table)
 
Doctrine DBAL Schema Column buildQuotedColumn (Column $column)
 
Doctrine DBAL Schema Index buildQuotedIndex (Index $index)
 
Doctrine DBAL Schema ForeignKeyConstraint buildQuotedForeignKey (ForeignKeyConstraint $index)
 
 getDatabasePlatform (string $tableName)
 

Protected Attributes

string $deletedPrefix = 'zzz_deleted_'
 
Connection $connection
 
string $connectionName
 
Table[] $tables
 

Detailed Description

Handling schema migrations per connection.

Definition at line 43 of file ConnectionMigrator.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::__construct ( string  $connectionName,
array  $tables 
)
Parameters
string$connectionName
Table[]$tables

Definition at line 65 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\$connectionName, and TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\$tables.

Member Function Documentation

◆ buildExpectedSchemaDefinitions()

Doctrine DBAL Schema Schema TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::buildExpectedSchemaDefinitions ( string  $connectionName)
protected

Build the expected schema definitions from raw SQL statements.

Parameters
string$connectionName
Returns
‪\Doctrine\DBAL\Schema\Schema
Exceptions

Definition at line 278 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\$connectionName, TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getConnectionNameForTable(), and TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\transformTablesForDatabasePlatform().

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildSchemaDiff().

◆ buildQuotedColumn()

Doctrine DBAL Schema Column TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::buildQuotedColumn ( Column  $column)
protected

Helper function to build a column object that has the _quoted attribute set so that the SchemaManager will use quoted identifiers when creating the final SQL statements. This is needed as Doctrine doesn't provide a method to set the flag after the object has been instantiated and there's no possibility to hook into the createSchema() method early enough to influence the original column object.

Parameters
\Doctrine\DBAL\Schema\Column$column
Returns
‪\Doctrine\DBAL\Schema\Column

Definition at line 1276 of file ConnectionMigrator.php.

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getChangedFieldUpdateSuggestions().

◆ buildQuotedForeignKey()

Doctrine DBAL Schema ForeignKeyConstraint TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::buildQuotedForeignKey ( ForeignKeyConstraint  $index)
protected

Helper function to build a foreign key constraint object that has the _quoted attribute set so that the SchemaManager will use quoted identifiers when creating the final SQL statements. This is needed as Doctrine doesn't provide a method to set the flag after the object has been instantiated and there's no possibility to hook into the createSchema() method early enough to influence the original column object.

Parameters
\Doctrine\DBAL\Schema\ForeignKeyConstraint$index
Returns
‪\Doctrine\DBAL\Schema\ForeignKeyConstraint

Definition at line 1321 of file ConnectionMigrator.php.

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getChangedFieldUpdateSuggestions(), TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getDropFieldUpdateSuggestions(), and TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getNewFieldUpdateSuggestions().

◆ buildQuotedIndex()

Doctrine DBAL Schema Index TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::buildQuotedIndex ( Index  $index)
protected

Helper function to build an index object that has the _quoted attribute set so that the SchemaManager will use quoted identifiers when creating the final SQL statements. This is needed as Doctrine doesn't provide a method to set the flag after the object has been instantiated and there's no possibility to hook into the createSchema() method early enough to influence the original column object.

Parameters
\Doctrine\DBAL\Schema\Index$index
Returns
‪\Doctrine\DBAL\Schema\Index

Definition at line 1297 of file ConnectionMigrator.php.

◆ buildQuotedTable()

Doctrine DBAL Schema Table TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::buildQuotedTable ( Table  $table)
protected

Helper function to build a table object that has the _quoted attribute set so that the SchemaManager will use quoted identifiers when creating the final SQL statements. This is needed as Doctrine doesn't provide a method to set the flag after the object has been instantiated and there's no possibility to hook into the createSchema() method early enough to influence the original table object.

Parameters
\Doctrine\DBAL\Schema\Table$table
Returns
‪\Doctrine\DBAL\Schema\Table

Definition at line 1252 of file ConnectionMigrator.php.

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getChangedFieldUpdateSuggestions(), TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getDropFieldUpdateSuggestions(), TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getDropTableUpdateSuggestions(), and TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getNewFieldUpdateSuggestions().

◆ buildSchemaDiff()

◆ calculateUpdateSuggestionsHashes()

string [] TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::calculateUpdateSuggestionsHashes ( array  $statements)
protected

◆ create()

static ConnectionMigrator TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::create ( string  $connectionName,
array  $tables 
)
static

◆ getChangedFieldUpdateSuggestions()

array TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::getChangedFieldUpdateSuggestions ( SchemaDiff  $schemaDiff)
protected

Extract update suggestions (SQL statements) for changed fields from the complete schema diff.

Parameters
\Doctrine\DBAL\Schema\SchemaDiff$schemaDiff
Returns
‪array
Exceptions

Definition at line 491 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildQuotedColumn(), TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildQuotedForeignKey(), and TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildQuotedTable().

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getUpdateSuggestions().

◆ getChangedTableOptions()

array TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::getChangedTableOptions ( SchemaDiff  $schemaDiff)
protected

Extract update suggestions (SQL statements) for changed options (like ENGINE) from the complete schema diff.

Parameters
\Doctrine\DBAL\Schema\SchemaDiff$schemaDiff
Returns
‪array
Exceptions

Definition at line 441 of file ConnectionMigrator.php.

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getUpdateSuggestions().

◆ getConnectionNameForTable()

string TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::getConnectionNameForTable ( string  $tableName)
protected

Determine the connection name for a table

Parameters
string$tableName
Returns
‪string
Exceptions

Definition at line 1065 of file ConnectionMigrator.php.

References $GLOBALS, and TYPO3\CMS\Core\Database\ConnectionPool\DEFAULT_CONNECTION_NAME.

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildExpectedSchemaDefinitions().

◆ getDatabasePlatform()

TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::getDatabasePlatform ( string  $tableName)
protected

◆ getDropFieldUpdateSuggestions()

array TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::getDropFieldUpdateSuggestions ( SchemaDiff  $schemaDiff)
protected

Extract update suggestions (SQL statements) for fields that can be removed from the complete schema diff. Fields that can be removed have been prefixed in a previous run of the schema migration.

Parameters
\Doctrine\DBAL\Schema\SchemaDiff$schemaDiff
Returns
‪array
Exceptions

Definition at line 773 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildQuotedForeignKey(), TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildQuotedTable(), TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\calculateUpdateSuggestionsHashes(), and TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getDatabasePlatform().

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getUpdateSuggestions().

◆ getDropTableUpdateSuggestions()

array TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::getDropTableUpdateSuggestions ( SchemaDiff  $schemaDiff)
protected

Extract update suggestions (SQL statements) for tables that can be removed from the complete schema diff. Tables that can be removed have been prefixed in a previous run of the schema migration.

Parameters
\Doctrine\DBAL\Schema\SchemaDiff$schemaDiff
Returns
‪array
Exceptions

Definition at line 879 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildQuotedTable(), and TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getTableRecordCount().

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getUpdateSuggestions().

◆ getNewFieldUpdateSuggestions()

array TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::getNewFieldUpdateSuggestions ( SchemaDiff  $schemaDiff)
protected

Extract the update suggestions (SQL statements) for newly added fields from the complete schema diff.

Parameters
\Doctrine\DBAL\Schema\SchemaDiff$schemaDiff
Returns
‪array
Exceptions

Definition at line 354 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildQuotedForeignKey(), TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildQuotedTable(), and TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\calculateUpdateSuggestionsHashes().

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getUpdateSuggestions().

◆ getNewTableUpdateSuggestions()

array TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::getNewTableUpdateSuggestions ( SchemaDiff  $schemaDiff)
protected

Extract the update suggestions (SQL statements) for newly added tables from the complete schema diff.

Parameters
\Doctrine\DBAL\Schema\SchemaDiff$schemaDiff
Returns
‪array
Exceptions

Definition at line 329 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\calculateUpdateSuggestionsHashes().

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getUpdateSuggestions().

◆ getSchemaDiff()

SchemaDiff TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::getSchemaDiff ( )

Return the raw Doctrine SchemaDiff object for the current connection. This diff contains all changes without any pre-processing.

Returns
‪SchemaDiff

Definition at line 93 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildSchemaDiff().

◆ getTableOptions()

array [] TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::getTableOptions ( array  $tableNames)
protected

Get COLLATION, ROW_FORMAT, COMMENT and ENGINE table options on MySQL connections.

Parameters
string[]$tableNames
Returns
‪array[]
Exceptions

Definition at line 1191 of file ConnectionMigrator.php.

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildSchemaDiff().

◆ getTableRecordCount()

int TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::getTableRecordCount ( string  $tableName)
protected

Return the amount of records in the given table.

Parameters
string$tableName
Returns
‪int
Exceptions

Definition at line 1051 of file ConnectionMigrator.php.

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getDropTableUpdateSuggestions(), and TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getUnusedTableUpdateSuggestions().

◆ getUnusedFieldUpdateSuggestions()

array TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::getUnusedFieldUpdateSuggestions ( SchemaDiff  $schemaDiff)
protected

Extract update suggestions (SQL statements) for fields that are no longer present in the expected schema from the schema diff. In this case the update suggestions are renames of the fields with a prefix to mark them for deletion in a second sweep.

Parameters
\Doctrine\DBAL\Schema\SchemaDiff$schemaDiff
Returns
‪array
Exceptions

Definition at line 707 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\calculateUpdateSuggestionsHashes(), and TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getDatabasePlatform().

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getUpdateSuggestions().

◆ getUnusedTableUpdateSuggestions()

array TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::getUnusedTableUpdateSuggestions ( SchemaDiff  $schemaDiff)
protected

Extract update suggestions (SQL statements) for tables that are no longer present in the expected schema from the schema diff. In this case the update suggestions are renames of the tables with a prefix to mark them for deletion in a second sweep.

Parameters
\Doctrine\DBAL\Schema\SchemaDiff$schemaDiff
Returns
‪array
Exceptions

Definition at line 665 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getTableRecordCount().

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\getUpdateSuggestions().

◆ getUpdateSuggestions()

◆ install()

array TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::install ( bool  $createOnly = false)

Perform add/change/create operations on tables and fields in an optimized, non-interactive, mode using the original doctrine SchemaManager ->toSaveSql() method.

Parameters
bool$createOnly
Returns
‪array

Definition at line 135 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildSchemaDiff().

◆ migrateColumnRenamesToDistinctActions()

SchemaDiff TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::migrateColumnRenamesToDistinctActions ( SchemaDiff  $schemaDiff)
protected

Revert the automatic rename optimization that Doctrine performs when it detects a column being added and a column being dropped that only differ by name.

Parameters
\Doctrine\DBAL\Schema\SchemaDiff$schemaDiff
Returns
‪SchemaDiff
Exceptions

Definition at line 1012 of file ConnectionMigrator.php.

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildSchemaDiff().

◆ migrateUnprefixedRemovedFieldsToRenames()

Doctrine DBAL Schema SchemaDiff TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::migrateUnprefixedRemovedFieldsToRenames ( SchemaDiff  $schemaDiff)
protected

Scan the list of changed tables for fields that are going to be dropped. If the name of the field does not start with the deleted prefix mark the column for a rename instead of a drop operation.

Parameters
\Doctrine\DBAL\Schema\SchemaDiff$schemaDiff
Returns
‪\Doctrine\DBAL\Schema\SchemaDiff
Exceptions

Definition at line 959 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Platform\PlatformInformation\getMaxIdentifierLength().

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildSchemaDiff().

◆ migrateUnprefixedRemovedTablesToRenames()

Doctrine DBAL Schema SchemaDiff TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::migrateUnprefixedRemovedTablesToRenames ( SchemaDiff  $schemaDiff)
protected

Move tables to be removed that are not prefixed with the deleted prefix to the list of changed tables and set a new prefixed name. Without this help the Doctrine SchemaDiff has no idea if a table has been renamed and performs a drop of the old table and creates a new table, which leads to all data in the old table being lost.

Parameters
\Doctrine\DBAL\Schema\SchemaDiff$schemaDiff
Returns
‪\Doctrine\DBAL\Schema\SchemaDiff
Exceptions

Definition at line 918 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Platform\PlatformInformation\getMaxIdentifierLength().

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildSchemaDiff().

◆ removeUnrelatedTables()

Doctrine DBAL Schema TableDiff [] TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::removeUnrelatedTables ( array  $tableDiffs,
array  $validTableNames 
)
protected

Helper for buildSchemaDiff to filter an array of TableDiffs against a list of valid table names.

Parameters
\Doctrine\DBAL\Schema\TableDiff[] | Table[]$tableDiffs
string[]$validTableNames
Returns
‪\Doctrine\DBAL\Schema\TableDiff[]
Exceptions

Definition at line 1097 of file ConnectionMigrator.php.

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildSchemaDiff().

◆ transformTablesForDatabasePlatform()

Table [] TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::transformTablesForDatabasePlatform ( array  $tables,
Connection  $connection 
)
protected

Transform the table information to conform to specific requirements of different database platforms like removing the index substring length for Non-MySQL Platforms.

Parameters
Table[]$tables
\TYPO3\CMS\Core\Database\Connection$connection
Returns
‪Table[]
Exceptions

Definition at line 1130 of file ConnectionMigrator.php.

References TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\$connection, TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\$tables, and TYPO3\CMS\Core\Database\Connection\quoteIdentifier().

Referenced by TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\buildExpectedSchemaDefinitions().

Member Data Documentation

◆ $connection

Connection TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::$connection
protected

◆ $connectionName

◆ $deletedPrefix

string TYPO3\CMS\Core\Database\Schema\ConnectionMigrator::$deletedPrefix = 'zzz_deleted_'
protected

Prefix of deleted tables

Definition at line 47 of file ConnectionMigrator.php.

◆ $tables