N°1001 setup : database/tables/columns charset and collation conversion

* check DB charset/collation and do conversion if needed
* same for existing tables
* add both info in fields signatures, so that conversions will be trigerred if needed

SVN:trunk[5444]
This commit is contained in:
Pierre Goiffon
2018-03-16 09:59:25 +00:00
parent b219161011
commit e7b94d3132
3 changed files with 142 additions and 67 deletions

View File

@@ -111,15 +111,6 @@ define('LINKSET_EDITMODE_ADDREMOVE', 4); // The "linked" objects can be added/re
*/
abstract class AttributeDefinition
{
/**
* SQL charset & collation declaration for text columns
*
* @see https://dev.mysql.com/doc/refman/5.7/en/charset-column.html
* @since 2.5 #1001 switch to utf8mb4
*/
const SQL_TEXT_COLUMNS_CHARSET = ' CHARACTER SET '.DEFAULT_CHARACTER_SET.' COLLATE '.DEFAULT_COLLATION;
public function GetType()
{
return Dict::S('Core:'.get_class($this));
@@ -1503,7 +1494,7 @@ class AttributeDBFieldVoid extends AttributeDefinition
protected function GetSQLCol($bFullSpec = false)
{
return 'VARCHAR(255)'
.self::SQL_TEXT_COLUMNS_CHARSET
.CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION
.($bFullSpec ? $this->GetSQLColSpec() : '');
}
protected function GetSQLColSpec()
@@ -2118,7 +2109,7 @@ class AttributeString extends AttributeDBField
protected function GetSQLCol($bFullSpec = false)
{
return 'VARCHAR(255)'
.self::SQL_TEXT_COLUMNS_CHARSET
.CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION
.($bFullSpec ? $this->GetSQLColSpec() : '');
}
@@ -2510,7 +2501,7 @@ class AttributePassword extends AttributeString
protected function GetSQLCol($bFullSpec = false)
{
return "VARCHAR(64)"
.self::SQL_TEXT_COLUMNS_CHARSET
.CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION
.($bFullSpec ? $this->GetSQLColSpec() : '');
}
@@ -2641,7 +2632,7 @@ class AttributeText extends AttributeString
protected function GetSQLCol($bFullSpec = false)
{
return "TEXT".self::SQL_TEXT_COLUMNS_CHARSET;
return "TEXT".CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION;
}
public function GetSQLColumns($bFullSpec = false)
@@ -2651,7 +2642,7 @@ class AttributeText extends AttributeString
if ($this->GetOptional('format', null) != null )
{
// Add the extra column only if the property 'format' is specified for the attribute
$aColumns[$this->Get('sql').'_format'] = "ENUM('text','html')".self::SQL_TEXT_COLUMNS_CHARSET;
$aColumns[$this->Get('sql').'_format'] = "ENUM('text','html')".CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION;
if ($bFullSpec)
{
$aColumns[$this->Get('sql').'_format'].= " DEFAULT 'text'"; // default 'text' is for migrating old records
@@ -2975,7 +2966,7 @@ class AttributeLongText extends AttributeText
{
protected function GetSQLCol($bFullSpec = false)
{
return "LONGTEXT".self::SQL_TEXT_COLUMNS_CHARSET;
return "LONGTEXT".CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION;
}
public function GetMaxSize()
@@ -3155,7 +3146,7 @@ class AttributeCaseLog extends AttributeLongText
{
$aColumns = array();
$aColumns[$this->GetCode()] = 'LONGTEXT' // 2^32 (4 Gb)
.self::SQL_TEXT_COLUMNS_CHARSET;
.CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION;
$aColumns[$this->GetCode().'_index'] = 'BLOB';
return $aColumns;
}
@@ -3499,13 +3490,13 @@ class AttributeEnum extends AttributeString
// make sure that this string will match the field type returned by the DB
// (used to perform a comparison between the current DB format and the data model)
return "ENUM(".implode(",", $aValues).")"
.self::SQL_TEXT_COLUMNS_CHARSET
.CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION
.($bFullSpec ? $this->GetSQLColSpec() : '');
}
else
{
return "VARCHAR(255)"
.self::SQL_TEXT_COLUMNS_CHARSET
.CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION
.($bFullSpec ? " DEFAULT ''" : ""); // ENUM() is not an allowed syntax!
}
}
@@ -5238,7 +5229,7 @@ class AttributeURL extends AttributeString
protected function GetSQLCol($bFullSpec = false)
{
return "VARCHAR(2048)"
.self::SQL_TEXT_COLUMNS_CHARSET
.CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION
.($bFullSpec ? $this->GetSQLColSpec() : '');
}
@@ -5413,8 +5404,8 @@ class AttributeBlob extends AttributeDefinition
{
$aColumns = array();
$aColumns[$this->GetCode().'_data'] = 'LONGBLOB'; // 2^32 (4 Gb)
$aColumns[$this->GetCode().'_mimetype'] = 'VARCHAR(255)'.self::SQL_TEXT_COLUMNS_CHARSET;
$aColumns[$this->GetCode().'_filename'] = 'VARCHAR(255)'.self::SQL_TEXT_COLUMNS_CHARSET;
$aColumns[$this->GetCode().'_mimetype'] = 'VARCHAR(255)'.CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION;
$aColumns[$this->GetCode().'_filename'] = 'VARCHAR(255)'.CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION;
return $aColumns;
}
@@ -6551,7 +6542,7 @@ class AttributeOneWayPassword extends AttributeDefinition
public function GetImportColumns()
{
$aColumns = array();
$aColumns[$this->GetCode()] = 'TINYTEXT'.self::SQL_TEXT_COLUMNS_CHARSET;
$aColumns[$this->GetCode()] = 'TINYTEXT'.CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION;
return $aColumns;
}
@@ -6622,7 +6613,7 @@ class AttributeTable extends AttributeDBField
protected function GetSQLCol($bFullSpec = false)
{
return "LONGTEXT".self::SQL_TEXT_COLUMNS_CHARSET;
return "LONGTEXT".CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION;
}
public function GetMaxSize()
@@ -7025,7 +7016,7 @@ class AttributeRedundancySettings extends AttributeDBField
protected function GetSQLCol($bFullSpec = false)
{
return "VARCHAR(20)"
.self::SQL_TEXT_COLUMNS_CHARSET
.CMDBSource::SQL_STRING_COLUMNS_CHARSET_DEFINITION
.($bFullSpec ? $this->GetSQLColSpec() : '');
}