[DATABASE] Make sure the session always uses UTF-8 and UTC

This commit is contained in:
Alexei Sorokin 2020-09-12 15:40:39 +03:00
parent 54484e56e7
commit b04469a252
2 changed files with 14 additions and 6 deletions

View File

@ -894,11 +894,14 @@ class Memcached_DataObject extends Safe_DataObject
$result = parent::_connect();
if ($result && !$exists) {
// Needed to make timestamp values usefully comparable.
// Required to make timestamp values usefully comparable.
// And set the character set to UTF-8.
if (common_config('db', 'type') !== 'mysql') {
parent::_query("SET TIME ZONE INTERVAL '+00:00' HOUR TO MINUTE");
parent::_query("SET NAMES 'UTF8'");
} else {
parent::_query("SET time_zone = '+0:00'");
parent::_query("SET NAMES 'utf8mb4'");
}
}

View File

@ -306,6 +306,8 @@ abstract class Installer
switch ($this->dbtype) {
case 'pgsql':
// ensure the timezone is UTC
$conn->query("SET TIME ZONE INTERVAL '+00:00' HOUR TO MINUTE");
// ensure the database encoding is UTF8
$conn->query("SET NAMES 'UTF8'");
$server_encoding = $conn->getRow('SHOW server_encoding')[0];
@ -318,6 +320,8 @@ abstract class Installer
}
break;
case 'mysql':
// ensure the timezone is UTC
$conn->query("SET time_zone = '+0:00'");
// ensure the database encoding is utf8mb4
$conn->query("SET NAMES 'utf8mb4'");
$server_encoding = $conn->getRow("SHOW VARIABLES LIKE 'character_set_server'")[1];
@ -340,10 +344,11 @@ abstract class Installer
return false;
}
foreach (['sms_carrier' => 'SMS carrier',
foreach ([
'sms_carrier' => 'SMS carrier',
'notice_source' => 'notice source',
'foreign_services' => 'foreign service']
as $scr => $name) {
'foreign_services' => 'foreign service',
] as $scr => $name) {
$this->updateStatus(sprintf("Adding %s data to database...", $name));
$res = $this->runDbScript($scr . '.sql', $conn);
if ($res === false) {