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

Public Member Functions

 setDeletedPrefixKey ($prefix)
 
 getDeletedPrefixKey ()
 
 getFieldDefinitions_fileContent ($fileContent)
 
 getCollationForCharset ($charset)
 
 getFieldDefinitions_database ()
 
 getDatabaseExtra ($FDsrc, $FDcomp, $onlyTableList= '', $ignoreNotNullWhenComparing=false)
 
 getUpdateSuggestions ($diffArr, $keyList= 'extra, diff')
 
 assembleFieldDefinition ($row)
 
 getStatementArray ($sqlcode, $removeNonSQL=false, $query_regex= '')
 
 getCreateTables ($statements, $insertCountFlag=false)
 
 getTableInsertStatements ($statements, $table)
 
 performUpdateQueries ($arr, $keyArr)
 
 getListOfTables ()
 

Public Attributes

const MYSQL_MAXIMUM_FIELD_WIDTH = 64
 

Protected Attributes

 $deletedPrefixKey = 'zzz_deleted_'
 
 $character_sets = []
 

Detailed Description

Verify TYPO3 DB table structure. Mainly used in install tool compare wizard and extension manager.

Definition at line 25 of file SqlSchemaMigrationService.php.

Member Function Documentation

assembleFieldDefinition (   $row)

Converts a result row with field information into the SQL field definition string

Parameters
array$rowMySQL result row
Returns
string Field definition

Definition at line 503 of file SqlSchemaMigrationService.php.

Referenced by SqlSchemaMigrationService\getFieldDefinitions_database().

getCollationForCharset (   $charset)

Look up the default collation for specified character set based on "SHOW CHARACTER SET" output

Parameters
string$charsetCharacter set
Returns
string Corresponding default collation

Definition at line 160 of file SqlSchemaMigrationService.php.

References GeneralUtility\makeInstance().

Referenced by SqlSchemaMigrationService\getFieldDefinitions_fileContent().

getCreateTables (   $statements,
  $insertCountFlag = false 
)

Returns tables to create and how many records in each

Parameters
array$statementsArray of SQL statements to analyse.
bool$insertCountFlagIf set, will count number of INSERT INTO statements following that table definition
Returns
array Array with table definitions in index 0 and count in index 1

Definition at line 575 of file SqlSchemaMigrationService.php.

getDatabaseExtra (   $FDsrc,
  $FDcomp,
  $onlyTableList = '',
  $ignoreNotNullWhenComparing = false 
)

Compares two arrays with field information and returns information about fields that are MISSING and fields that have CHANGED. FDsrc and FDcomp can be switched if you want the list of stuff to remove rather than update.

Parameters
array$FDsrcField definitions, source (from getFieldDefinitions_fileContent())
array$FDcompField definitions, comparison. (from getFieldDefinitions_database())
string$onlyTableListTable names (in list) which is the ONLY one observed.
bool$ignoreNotNullWhenComparingIf set, this function ignores NOT NULL statements of the SQL file field definition when comparing current field definition from database with field definition from SQL file. This way, NOT NULL statements will be executed when the field is initially created, but the SQL parser will never complain about missing NOT NULL statements afterwards.
Returns
array Returns an array with 1) all elements from $FDsrc that is not in $FDcomp (in key 'extra') and 2) all elements from $FDsrc that is different from the ones in $FDcomp

Definition at line 268 of file SqlSchemaMigrationService.php.

References GeneralUtility\inList().

getDeletedPrefixKey ( )

Get prefix of deleted tables

Returns
string

Definition at line 57 of file SqlSchemaMigrationService.php.

References SqlSchemaMigrationService\$deletedPrefixKey.

getFieldDefinitions_database ( )

Reads the field definitions for the current database

Returns
array Array with information about table.

Definition at line 183 of file SqlSchemaMigrationService.php.

References SqlSchemaMigrationService\assembleFieldDefinition(), and GeneralUtility\makeInstance().

getFieldDefinitions_fileContent (   $fileContent)

Reads the field definitions for the input SQL-file string

Parameters
string$fileContentShould be a string read from an SQL-file made with 'mysqldump [database_name] -d'
Returns
array Array with information about table.

Definition at line 68 of file SqlSchemaMigrationService.php.

References SqlSchemaMigrationService\getCollationForCharset(), and GeneralUtility\trimExplode().

getListOfTables ( )

Returns list of tables in the database

Returns
array List of tables.
See also
::admin_get_tables()

Definition at line 662 of file SqlSchemaMigrationService.php.

References GeneralUtility\makeInstance().

getStatementArray (   $sqlcode,
  $removeNonSQL = false,
  $query_regex = '' 
)

Returns an array where every entry is a single SQL-statement. Input must be formatted like an ordinary MySQL-dump files.

Parameters
string$sqlcodeThe SQL-file content. Provided that 1) every query in the input is ended with ';' and that a line in the file contains only one query or a part of a query.
bool$removeNonSQLIf set, non-SQL content (like comments and blank lines) is not included in the final output
string$query_regexRegex to filter SQL lines to include
Returns
array Array of SQL statements

Definition at line 536 of file SqlSchemaMigrationService.php.

getTableInsertStatements (   $statements,
  $table 
)

Extracts all insert statements from $statement array where content is inserted into $table

Parameters
array$statementsArray of SQL statements
string$tableTable name
Returns
array Array of INSERT INTO statements where table match $table

Definition at line 612 of file SqlSchemaMigrationService.php.

getUpdateSuggestions (   $diffArr,
  $keyList = 'extra,
diff'   
)

Returns an array with SQL-statements that is needed to update according to the diff-array

Parameters
array$diffArrArray with differences of current and needed DB settings. (from getDatabaseExtra())
string$keyListList of fields in diff array to take notice of.
Returns
array Array of SQL statements (organized in keys depending on type)

Definition at line 338 of file SqlSchemaMigrationService.php.

References SqlSchemaMigrationService\$deletedPrefixKey, and GeneralUtility\makeInstance().

performUpdateQueries (   $arr,
  $keyArr 
)

Performs the queries passed from the input array.

Parameters
array$arrArray of SQL queries to execute.
array$keyArrArray with keys that must match keys in $arr. Only where a key in this array is set and TRUE will the query be executed (meant to be passed from a form checkbox)
Returns
mixed Array with error message from database if any occurred. Otherwise TRUE if everything was executed successfully.

Definition at line 634 of file SqlSchemaMigrationService.php.

References GeneralUtility\makeInstance().

setDeletedPrefixKey (   $prefix)

Set prefix of deleted tables

Parameters
string$prefixPrefix string

Definition at line 47 of file SqlSchemaMigrationService.php.

Member Data Documentation

$character_sets = []
protected

Definition at line 40 of file SqlSchemaMigrationService.php.

$deletedPrefixKey = 'zzz_deleted_'
protected
const MYSQL_MAXIMUM_FIELD_WIDTH = 64

Maximum field width of MySQL

Definition at line 30 of file SqlSchemaMigrationService.php.