TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ConnectionMigrator Class Reference

Public Member Functions

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

Static Public Member Functions

static create (string $connectionName, array $tables)
 

Protected Member Functions

 getNewTableUpdateSuggestions (SchemaDiff $schemaDiff)
 
 getNewFieldUpdateSuggestions (SchemaDiff $schemaDiff)
 
 getChangedTableOptions (SchemaDiff $schemaDiff)
 
 getChangedFieldUpdateSuggestions (SchemaDiff $schemaDiff)
 
 getUnusedTableUpdateSuggestions (SchemaDiff $schemaDiff)
 
 getUnusedFieldUpdateSuggestions (SchemaDiff $schemaDiff)
 
 getDropFieldUpdateSuggestions (SchemaDiff $schemaDiff)
 
 getDropTableUpdateSuggestions (SchemaDiff $schemaDiff)
 
 migrateUnprefixedRemovedTablesToRenames (SchemaDiff $schemaDiff)
 
 migrateUnprefixedRemovedFieldsToRenames (SchemaDiff $schemaDiff)
 
 getTableRecordCount (string $tableName)
 
 getConnectionNameForTable (string $tableName)
 
 calculateUpdateSuggestionsHashes (array $statements)
 
 removeUnrelatedTables (array $tableDiffs, array $validTableNames)
 
 transformTablesForDatabasePlatform (array $tables, Connection $connection)
 
 getTableOptions (array $tableNames)
 

Protected Attributes

 $deletedPrefix = 'zzz_deleted_'
 
 $maxTableNameLength = 64
 
 $connection
 
 $connectionName
 
 $tables
 

Detailed Description

Handling schema migrations per connection.

Definition at line 37 of file ConnectionMigrator.php.

Constructor & Destructor Documentation

__construct ( string  $connectionName,
array  $tables 
)
Parameters
string$connectionName
Table[]$tables

Definition at line 68 of file ConnectionMigrator.php.

References ConnectionMigrator\$connectionName, ConnectionMigrator\$tables, and GeneralUtility\makeInstance().

Member Function Documentation

calculateUpdateSuggestionsHashes ( array  $statements)
protected

Replace the array keys with a md5 sum of the actual SQL statement

Parameters
string[]$statements
Returns
string[]

Definition at line 986 of file ConnectionMigrator.php.

Referenced by ConnectionMigrator\getDropFieldUpdateSuggestions(), ConnectionMigrator\getNewFieldUpdateSuggestions(), ConnectionMigrator\getNewTableUpdateSuggestions(), and ConnectionMigrator\getUnusedFieldUpdateSuggestions().

static create ( string  $connectionName,
array  $tables 
)
static
Parameters
string$connectionName
Table[]$tables
Returns
ConnectionMigrator

Definition at line 81 of file ConnectionMigrator.php.

References GeneralUtility\makeInstance().

Referenced by SchemaMigrator\getSchemaDiffs(), SchemaMigrator\getUpdateSuggestions(), and SchemaMigrator\install().

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
Doctrine
InvalidArgumentException

Definition at line 472 of file ConnectionMigrator.php.

References GeneralUtility\makeInstance().

Referenced by ConnectionMigrator\getUpdateSuggestions().

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
Doctrine
InvalidArgumentException

Definition at line 422 of file ConnectionMigrator.php.

References GeneralUtility\makeInstance().

Referenced by ConnectionMigrator\getUpdateSuggestions().

getConnectionNameForTable ( string  $tableName)
protected

Determine the connection name for a table

Parameters
string$tableName
Returns
string
Exceptions
InvalidArgumentException

Definition at line 967 of file ConnectionMigrator.php.

References $GLOBALS, ConnectionPool\DEFAULT_CONNECTION_NAME, and GeneralUtility\makeInstance().

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
Doctrine
InvalidArgumentException

Definition at line 739 of file ConnectionMigrator.php.

References ConnectionMigrator\calculateUpdateSuggestionsHashes(), and GeneralUtility\makeInstance().

Referenced by ConnectionMigrator\getUpdateSuggestions().

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
Doctrine
InvalidArgumentException

Definition at line 826 of file ConnectionMigrator.php.

References ConnectionMigrator\getTableRecordCount(), and GeneralUtility\makeInstance().

Referenced by ConnectionMigrator\getUpdateSuggestions().

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
Doctrine
InvalidArgumentException

Definition at line 337 of file ConnectionMigrator.php.

References ConnectionMigrator\calculateUpdateSuggestionsHashes(), and GeneralUtility\makeInstance().

Referenced by ConnectionMigrator\getUpdateSuggestions().

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
InvalidArgumentException

Definition at line 312 of file ConnectionMigrator.php.

References ConnectionMigrator\calculateUpdateSuggestionsHashes(), and GeneralUtility\makeInstance().

Referenced by ConnectionMigrator\getUpdateSuggestions().

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 96 of file ConnectionMigrator.php.

getTableOptions ( array  $tableNames)
protected

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

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

Definition at line 1090 of file ConnectionMigrator.php.

getTableRecordCount ( string  $tableName)
protected

Return the amount of records in the given table.

Parameters
string$tableName
Returns
int
Exceptions
InvalidArgumentException

Definition at line 953 of file ConnectionMigrator.php.

References GeneralUtility\makeInstance().

Referenced by ConnectionMigrator\getDropTableUpdateSuggestions(), and ConnectionMigrator\getUnusedTableUpdateSuggestions().

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
Doctrine
InvalidArgumentException

Definition at line 683 of file ConnectionMigrator.php.

References ConnectionMigrator\calculateUpdateSuggestionsHashes(), and GeneralUtility\makeInstance().

Referenced by ConnectionMigrator\getUpdateSuggestions().

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
Doctrine
InvalidArgumentException

Definition at line 641 of file ConnectionMigrator.php.

References ConnectionMigrator\$deletedPrefix, ConnectionMigrator\getTableRecordCount(), and GeneralUtility\makeInstance().

Referenced by ConnectionMigrator\getUpdateSuggestions().

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 139 of file ConnectionMigrator.php.

References GeneralUtility\makeInstance().

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
Exceptions
InvalidArgumentException

Definition at line 907 of file ConnectionMigrator.php.

References ConnectionMigrator\$deletedPrefix, and GeneralUtility\makeInstance().

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
Exceptions
InvalidArgumentException

Definition at line 865 of file ConnectionMigrator.php.

References ConnectionMigrator\$deletedPrefix, ConnectionMigrator\$maxTableNameLength, and GeneralUtility\makeInstance().

removeUnrelatedTables ( array  $tableDiffs,
array  $validTableNames 
)
protected

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

Parameters
TableDiff[]|Table[]$tableDiffs
string[]$validTableNames
Returns
TableDiff[]
Exceptions
InvalidArgumentException

Definition at line 999 of file ConnectionMigrator.php.

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
InvalidArgumentException

Definition at line 1032 of file ConnectionMigrator.php.

References ConnectionMigrator\$tables, GeneralUtility\makeInstance(), and Connection\quoteIdentifier().

Member Data Documentation

$connection
protected

Definition at line 52 of file ConnectionMigrator.php.

$connectionName
protected

Definition at line 57 of file ConnectionMigrator.php.

Referenced by ConnectionMigrator\__construct().

$maxTableNameLength = 64
protected