TYPO3  7.6
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
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 Member Functions

 isDbalEnabled ()
 
 getDatabaseConnection ()
 

Protected Attributes

 $deletedPrefixKey = 'zzz_deleted_'
 
 $character_sets = array()
 

Detailed Description

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

Definition at line 21 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 509 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 156 of file SqlSchemaMigrationService.php.

References SqlSchemaMigrationService\getDatabaseConnection().

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 581 of file SqlSchemaMigrationService.php.

References elseif.

getDatabaseConnection ( )
protected
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 255 of file SqlSchemaMigrationService.php.

References SqlSchemaMigrationService\getDatabaseConnection(), GeneralUtility\inList(), and SqlSchemaMigrationService\isDbalEnabled().

getDeletedPrefixKey ( )

Get prefix of deleted tables

Returns
string

Definition at line 53 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 180 of file SqlSchemaMigrationService.php.

References SqlSchemaMigrationService\assembleFieldDefinition(), elseif, and SqlSchemaMigrationService\getDatabaseConnection().

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 64 of file SqlSchemaMigrationService.php.

References SqlSchemaMigrationService\getCollationForCharset(), and SqlSchemaMigrationService\getDatabaseConnection().

getListOfTables ( )

Returns list of tables in the database

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

Definition at line 669 of file SqlSchemaMigrationService.php.

References SqlSchemaMigrationService\getDatabaseConnection().

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 542 of file SqlSchemaMigrationService.php.

References elseif.

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 618 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 345 of file SqlSchemaMigrationService.php.

References SqlSchemaMigrationService\$deletedPrefixKey, elseif, SqlSchemaMigrationService\getDatabaseConnection(), and SqlSchemaMigrationService\isDbalEnabled().

isDbalEnabled ( )
protected

Checks if DBAL is enabled for the database connection

Returns
bool

Definition at line 684 of file SqlSchemaMigrationService.php.

Referenced by SqlSchemaMigrationService\getDatabaseExtra(), and SqlSchemaMigrationService\getUpdateSuggestions().

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 640 of file SqlSchemaMigrationService.php.

References elseif, and SqlSchemaMigrationService\getDatabaseConnection().

setDeletedPrefixKey (   $prefix)

Set prefix of deleted tables

Parameters
string$prefixPrefix string

Definition at line 43 of file SqlSchemaMigrationService.php.

Member Data Documentation

$character_sets = array()
protected

Definition at line 36 of file SqlSchemaMigrationService.php.

$deletedPrefixKey = 'zzz_deleted_'
protected
const MYSQL_MAXIMUM_FIELD_WIDTH = 64

Maximum field width of MySQL

Definition at line 26 of file SqlSchemaMigrationService.php.