‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Database\Schema\SchemaMigrator Class Reference

Public Member Functions

 __construct (private readonly ConnectionPool $connectionPool, private readonly Parser $parser, private readonly DefaultTcaSchema $defaultTcaSchema,)
 
array< string, getUpdateSuggestions(array $statements, bool $remove=false):array { $tables=$this-> parseCreateTableStatements ($statements)
 
array< string, getSchemaDiffs(array $statements):array { $tables=$this-> parseCreateTableStatements ($statements)
 
 migrate (array $statements, array $selectedStatements)
 
array< string, install(array $statements, bool $createOnly=false):array { $tables=$this-> parseCreateTableStatements ($statements)
 
 importStaticData (array $statements, bool $truncate=false)
 

Public Attributes

 $updateSuggestions = []
 
foreach($this->connectionPool->getConnectionNames() as $connectionName) return $updateSuggestions
 
 $schemaDiffs = []
 
foreach($this->connectionPool->getConnectionNames() as $connectionName) return $schemaDiffs
 
 $result = []
 
return $result
 
if(!array_key_exists($tableName, $return)) $currentTableDefinition = $return[$tableName]
 
 $return [$tableName]
 
return $return
 

Protected Member Functions

Table[] parseCreateTableStatements (array $statements)
 
string[] getPrioritizedFieldNames (string $tableName)
 

Private Member Functions

array< non-empty-string, mergeTableDefinitions(array $tables):array { $return=[];foreach( $tables as $table) { $tableName=$this-> trimIdentifierQuotes ($table->getName())
 
 trimIdentifierQuotes (string $identifier)
 

Detailed Description

Helper methods to handle SQL files and transform them into individual statements for further processing.

not part of public core API.

Definition at line 35 of file SchemaMigrator.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::__construct ( private readonly ConnectionPool  $connectionPool,
private readonly Parser  $parser,
private readonly DefaultTcaSchema  $defaultTcaSchema 
)

Definition at line 37 of file SchemaMigrator.php.

Member Function Documentation

◆ getPrioritizedFieldNames()

string [] TYPO3\CMS\Core\Database\Schema\SchemaMigrator::getPrioritizedFieldNames ( string  $tableName)
protected

Have fields triggered by 'ctrl' settings first in the list. This is done for cosmetic reasons to improve readability of db schema when opening tables in a database browser.

Returns
‪string[]

Definition at line 290 of file SchemaMigrator.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Core\Database\Schema\SchemaMigrator\parseCreateTableStatements().

◆ importStaticData()

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::importStaticData ( array  $statements,
bool  $truncate = false 
)

Import static data (INSERT statements)

Definition at line 163 of file SchemaMigrator.php.

References TYPO3\CMS\Core\Database\Schema\SchemaMigrator\$result.

◆ migrate()

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::migrate ( array  $statements,
array  $selectedStatements 
)

This method executes statements from the update suggestions, or a subset of them filtered by the statements hashes, one by one.

Parameters
string[]$statements‪The CREATE TABLE statements
string[]$selectedStatements‪The hashes of the update suggestions to execute
Exceptions
DBALException
SchemaException

Definition at line 103 of file SchemaMigrator.php.

References TYPO3\CMS\Core\Database\Schema\SchemaMigrator\$result, TYPO3\CMS\Core\Database\Schema\SchemaMigrator\$updateSuggestions, and TYPO3\CMS\Core\Core\Bootstrap\createCache().

◆ parseCreateTableStatements() [1/4]

array<string, getUpdateSuggestions(array $statements, bool $remove = false): array { $tables = $this-> TYPO3\CMS\Core\Database\Schema\SchemaMigrator::parseCreateTableStatements (   $statements)

Compare current and expected schema definitions and provide updates suggestions in the form of SQL statements.

Parameters
string[]$statements‪The CREATE TABLE statements
bool$remove‪TRUE for RENAME/DROP table and column suggestions, FALSE for ADD/CHANGE suggestions
Returns
‪array<string, array> SQL statements to migrate the database to the expected schema, indexed by performed operation
Exceptions
DBALException
SchemaException

◆ parseCreateTableStatements() [2/4]

array<string, getSchemaDiffs(array $statements): array { $tables = $this-> TYPO3\CMS\Core\Database\Schema\SchemaMigrator::parseCreateTableStatements (   $statements)

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

Returns
‪array<string, SchemaDiff>
Exceptions
DBALException
SchemaException

◆ parseCreateTableStatements() [3/4]

array<string, install(array $statements, bool $createOnly = false): array { $tables = $this-> TYPO3\CMS\Core\Database\Schema\SchemaMigrator::parseCreateTableStatements (   $statements)

Perform add/change/create operations on tables and fields in an optimized, non-interactive, mode.

Parameters
string[]$statements‪The CREATE TABLE statements
bool$createOnly‪Only perform changes that add fields or create tables
Returns
‪array<string, string> Error messages for statements that occurred during the installation procedure.
Exceptions
DBALException
SchemaException

◆ parseCreateTableStatements() [4/4]

Table [] TYPO3\CMS\Core\Database\Schema\SchemaMigrator::parseCreateTableStatements ( array  $statements)
protected

Parse CREATE TABLE statements into Doctrine Table objects.

Parameters
string[]$statements‪The SQL CREATE TABLE statements
Returns
‪Table[]
Exceptions
SchemaException

Definition at line 211 of file SchemaMigrator.php.

References $GLOBALS, and TYPO3\CMS\Core\Database\Schema\SchemaMigrator\getPrioritizedFieldNames().

◆ trimIdentifierQuotes() [1/2]

array<non-empty-string, mergeTableDefinitions(array $tables): array { $return = []; foreach ($tables as $table) { $tableName = $this-> TYPO3\CMS\Core\Database\Schema\SchemaMigrator::trimIdentifierQuotes (   $table->())
private

To give extensions the ability to extend or modify the database schema for core or other extension tables, a collection of DDL statement parts are parsed into partial table classes. This method merges the table definition parts to end up with a single table representation to ease further handling.

Parameters
Table[]$tables
Returns
‪array<non-empty-string, Table>

◆ trimIdentifierQuotes() [2/2]

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::trimIdentifierQuotes ( string  $identifier)
private

Trim all possible identifier quotes from identifier. This method has been cloned from Doctrine DBAL.

See also
‪\Doctrine\DBAL\Schema\AbstractAsset::trimQuotes()

Definition at line 399 of file SchemaMigrator.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

Member Data Documentation

◆ $currentTableDefinition

if (!array_key_exists( $tableName, $return)) TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$currentTableDefinition = $return[$tableName]

Definition at line 380 of file SchemaMigrator.php.

◆ $result [1/2]

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$result = []

◆ $result [2/2]

return TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$result

Definition at line 157 of file SchemaMigrator.php.

◆ $return [1/2]

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$return[ $tableName]
Initial value:
= new Table(
$tableName,
array_merge(‪$currentTableDefinition->getColumns(), $table->getColumns()),
array_merge(‪$currentTableDefinition->getIndexes(), $table->getIndexes()),
[],
array_merge(‪$currentTableDefinition->getForeignKeys(), $table->getForeignKeys()),
array_merge(‪$currentTableDefinition->getOptions(), $table->getOptions())
)

Definition at line 381 of file SchemaMigrator.php.

◆ $return [2/2]

return TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$return

Definition at line 391 of file SchemaMigrator.php.

◆ $schemaDiffs [1/2]

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$schemaDiffs = []

Definition at line 82 of file SchemaMigrator.php.

◆ $schemaDiffs [2/2]

foreach ( $this->connectionPool->getConnectionNames() as $connectionName) return TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$schemaDiffs

Definition at line 88 of file SchemaMigrator.php.

◆ $updateSuggestions [1/2]

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$updateSuggestions = []

◆ $updateSuggestions [2/2]

foreach ( $this->connectionPool->getConnectionNames() as $connectionName) return TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$updateSuggestions

Definition at line 65 of file SchemaMigrator.php.

‪TYPO3\CMS\Core\Database\Schema\SchemaMigrator\$currentTableDefinition
‪if(!array_key_exists($tableName, $return)) $currentTableDefinition
Definition: SchemaMigrator.php:380