PHP Class MetaModels\Helper\TableManipulation

Show file Open project: metamodels/core Class Usage Examples

Protected Properties

Property Type Description
$reservedWords string[] List of reserved MySQL identifiers.
$systemColumns string[] When you alter this, ensure to also change @link{TableManipulation::STATEMENT_CREATE_TABLE} above.

Public Methods

Method Description
addIndex ( string $strTableName, string $strIndexType, string $strColName ) : void Add a index to given tablename for specified columnname
checkColumnDoesNotExist ( string $strTableName, string $strColName, boolean $blnAllowSystemCol = false ) : void Checks whether the given column does not exist.
checkColumnExists ( string $strTableName, string $strColName, boolean $blnAllowSystemCol = false ) : void Checks whether the given table exists.
checkColumnName ( string $strColName, boolean $blnAllowSystemCol = false ) : void Checks whether the column with the given name is not a MetaModel system column and is a valid column name.
checkTableDoesNotExist ( string $strTableName ) : void Ensures that the given table does not exist.
checkTableExists ( string $strTableName ) : void Checks whether the given table exists.
checkTablename ( string $strTableName ) : void Checks whether the given table name is valid.
createColumn ( string $strTableName, string $strColumnName, string $strType, boolean $blnAllowSystemCol = false ) : void Add a column to a table.
createTable ( string $strTableName ) : void Creates a table with the given name.
deleteTable ( string $strTableName ) : void Deletes the table with the given name.
dropColumn ( string $strTableName, string $strColumnName, boolean $blnAllowSystemCol = false ) : void Delete a column from a table.
isReservedWord ( string $word ) : boolean Test if the given word is a reserved MySQL word.
isSystemColumn ( string $strColName ) : boolean Checks whether the column with the given name is a MetaModel system column.
isValidColumnName ( string $strColName ) : boolean Checks whether the column with the given name is a MetaModel system column.
isValidMySQLIdentifier ( string $strName ) : boolean Ensure that an identifier is valid in MySQL context.
isValidTablename ( string $strTableName ) : boolean Checks whether the given table name is valid.
renameColumn ( string $strTableName, string $strColumnName, string $strNewColumnName, string $strNewType, boolean $blnAllowSystemCol = false ) : void Rename a column and/or change it's type in a table.
renameTable ( string $strTableName, string $strNewTableName ) : void Renames a table with the given name to the given new name.
setVariantSupport ( string $strTableName, boolean $blnVariantSupport ) : void Enables or disables Variant support on a certain MetaModel table.

Protected Methods

Method Description
getDB ( ) : Database Returns the Contao database instance to use.

Method Details

addIndex() public static method

Add a index to given tablename for specified columnname
public static addIndex ( string $strTableName, string $strIndexType, string $strColName ) : void
$strTableName string The table name.
$strIndexType string The index type.
$strColName string The column name to add a index.
return void

checkColumnDoesNotExist() public static method

Checks whether the given column does not exist.
public static checkColumnDoesNotExist ( string $strTableName, string $strColName, boolean $blnAllowSystemCol = false ) : void
$strTableName string The table name to check.
$strColName string The column name to check.
$blnAllowSystemCol boolean If this is set to true, no system column name checking will be applied.
return void

checkColumnExists() public static method

Checks whether the given table exists.
public static checkColumnExists ( string $strTableName, string $strColName, boolean $blnAllowSystemCol = false ) : void
$strTableName string The table name to check.
$strColName string The column name to check.
$blnAllowSystemCol boolean If this is set to true, no system column name checking will be applied.
return void

checkColumnName() public static method

If there is any problem, an Exception is raised, stating the nature of the error in the Exception message.
public static checkColumnName ( string $strColName, boolean $blnAllowSystemCol = false ) : void
$strColName string The name of the column.
$blnAllowSystemCol boolean If this is set to true, no system column name checking will be applied.
return void

checkTableDoesNotExist() public static method

Ensures that the given table does not exist.
public static checkTableDoesNotExist ( string $strTableName ) : void
$strTableName string The table name to check.
return void

checkTableExists() public static method

Checks whether the given table exists.
public static checkTableExists ( string $strTableName ) : void
$strTableName string The table name to check.
return void

checkTablename() public static method

Checks whether the given table name is valid.
public static checkTablename ( string $strTableName ) : void
$strTableName string The table name to check.
return void

createColumn() public static method

Throws Exception if the table does not exist, the column name is invalid or the column already exists.
public static createColumn ( string $strTableName, string $strColumnName, string $strType, boolean $blnAllowSystemCol = false ) : void
$strTableName string The name of the table to add the column to.
$strColumnName string The name of the new column.
$strType string The SQL type notation of the new column.
$blnAllowSystemCol boolean If this is set to true, no system column name checking will be applied.
return void

createTable() public static method

Creates a table with the given name.
public static createTable ( string $strTableName ) : void
$strTableName string The name of the new table to create.
return void

deleteTable() public static method

Deletes the table with the given name.
public static deleteTable ( string $strTableName ) : void
$strTableName string The name of the new table to delete.
return void

dropColumn() public static method

Throws Exception if the table does not exist, the column name is invalid or the column does not exist.
public static dropColumn ( string $strTableName, string $strColumnName, boolean $blnAllowSystemCol = false ) : void
$strTableName string The name of the table the column is in.
$strColumnName string The name of the column to drop.
$blnAllowSystemCol boolean If this is set to true, no system column name checking will be applied.
return void

getDB() protected static method

Returns the Contao database instance to use.
protected static getDB ( ) : Database
return Database the database instance.

isReservedWord() public static method

Test if the given word is a reserved MySQL word.
public static isReservedWord ( string $word ) : boolean
$word string The word to test.
return boolean

isSystemColumn() public static method

Checks whether the column with the given name is a MetaModel system column.
public static isSystemColumn ( string $strColName ) : boolean
$strColName string The name of the column.
return boolean true if the column is a system column, false otherwise.

isValidColumnName() public static method

Checks whether the column with the given name is a MetaModel system column.
public static isValidColumnName ( string $strColName ) : boolean
$strColName string The name of the column.
return boolean true if the column is a system column, false otherwise.

isValidMySQLIdentifier() public static method

Ensure that an identifier is valid in MySQL context.
public static isValidMySQLIdentifier ( string $strName ) : boolean
$strName string The identifier to check.
return boolean

isValidTablename() public static method

Checks whether the given table name is valid.
public static isValidTablename ( string $strTableName ) : boolean
$strTableName string The table name to check.
return boolean true if the table name is valid, false otherwise.

renameColumn() public static method

Throws Exception if the table does not exist, the column name is invalid or the column already exists.
public static renameColumn ( string $strTableName, string $strColumnName, string $strNewColumnName, string $strNewType, boolean $blnAllowSystemCol = false ) : void
$strTableName string The name of the table the column is in.
$strColumnName string The current name of the column to be renamed.
$strNewColumnName string The new name for the column.
$strNewType string The new SQL type notation of the column.
$blnAllowSystemCol boolean If this is set to true, no system column name checking will be applied.
return void

renameTable() public static method

Renames a table with the given name to the given new name.
public static renameTable ( string $strTableName, string $strNewTableName ) : void
$strTableName string The name of the table to rename.
$strNewTableName string The name to which the table shall be renamed to.
return void

setVariantSupport() public static method

Enables or disables Variant support on a certain MetaModel table.
public static setVariantSupport ( string $strTableName, boolean $blnVariantSupport ) : void
$strTableName string The table name of the MetaModel.
$blnVariantSupport boolean Flag if the support shall be turned on or off.
return void

Property Details

$reservedWords protected static property

List of reserved MySQL identifiers.
protected static string[] $reservedWords
return string[]

$systemColumns protected static property

When you alter this, ensure to also change @link{TableManipulation::STATEMENT_CREATE_TABLE} above.
protected static string[] $systemColumns
return string[]