Prevent user from being able to override the collate / charset table creation options.

Bad things would probably happen if they changed it to something that isn't some kind of unicode encoding.

Signed-off-by: Yip Rui Fung <rf@yrf.me>
This commit is contained in:
Yip Rui Fung 2021-02-04 19:59:45 +08:00
parent af92e6f7eb
commit 076e09b195
2 changed files with 27 additions and 13 deletions

View File

@ -1513,18 +1513,17 @@ $CONFIG = [
'mysql.utf8mb4' => false,
/**
* This configuration parameter can be used to override the default options used for table creation.
* This parameter will take precedence over mysql.utf8mb4 if that is set to true.
* This configuration parameter can be used to add or change the default options used for table creation.
* For changing charset / collation see mysql.utf8mb4
*
* An example use for this parameter is where MariaDB page compression is enabled by default as the
* COMPRESSED row format is not allowed there, and thus table creation will fail.
* This option can then be used to override this and change/remove the row_format option.
* This option can then be used to override this and change the row_format option.
*
*/
'dbdefaulttableoptions' => [
'collate' => 'utf8mb4_bin',
'charset' => 'utf8mb4',
'row_format' => 'compressed'
'row_format' => 'dynamic',
'page_compressed' => '1'
],
/**

View File

@ -216,19 +216,34 @@ class ConnectionFactory {
}
// set default table creation options
$connectionParams['defaultTableOptions'] = $this->config->getValue('dbdefaulttableoptions', [
'collate' => 'utf8_bin'
]);
$defaultTableOptions = [
'collate' => 'utf8_bin',
'tablePrefix' => $connectionParams['tablePrefix']
];
if ($this->config->getValue('mysql.utf8mb4', false) && is_null($this->config->getValue('dbdefaulttableoptions'))) {
$connectionParams['defaultTableOptions'] = [
if ($this->config->getValue('mysql.utf8mb4', false)) {
$defaultTableOptions = [
'collate' => 'utf8mb4_bin',
'charset' => 'utf8mb4',
'row_format' => 'compressed'
'row_format' => 'compressed',
'tablePrefix' => $connectionParams['tablePrefix']
];
}
$connectionParams['defaultTableOptions']['tablePrefix'] = $connectionParams['tablePrefix'];
$configTableOptions = $this->config->getValue('dbdefaulttableoptions', []);
// prevent user from overriding collation / charset and tablePrefix here (previous behavior.)
if (array_key_exists('collate', $configTableOptions)) {
unset($configTableOptions['collate']);
}
if (array_key_exists('charset', $configTableOptions)) {
unset($configTableOptions['charset']);
}
if (array_key_exists('tablePrefix', $configTableOptions)) {
unset($configTableOptions['tablePrefix']);
}
$connectionParams['defaultTableOptions'] = array_merge($defaultTableOptions, $configTableOptions);
return $connectionParams;
}