1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

When "utf8mb4" is available, use it as the default client charset when invoking standalone "mysql" commands

Summary:
Fixes T13390. We have some old code which doesn't dynamically select between "utf8mb4" and "utf8". This can lead to dumping utf8mb4 data over a utf8 connection in `bin/storage dump`, which possibly corrupts some emoji/whales.

Instead, prefer "utf8mb4" if it's available.

Test Plan: Ran `bin/storage dump` and `bin/storage shell`, saw sub-commands select utf8mb4 as the client charset.

Maniphest Tasks: T13390

Differential Revision: https://secure.phabricator.com/D20742
This commit is contained in:
epriestley 2019-08-27 15:27:25 -07:00
parent 97a4a59cf2
commit 7198bd7db7
3 changed files with 13 additions and 3 deletions

View file

@ -298,6 +298,14 @@ final class PhabricatorStorageManagementAPI extends Phobject {
return self::isCharacterSetAvailableOnConnection($character_set, $conn);
}
public function getClientCharset() {
if ($this->isCharacterSetAvailable('utf8mb4')) {
return 'utf8mb4';
} else {
return 'utf8';
}
}
public static function isCharacterSetAvailableOnConnection(
$character_set,
AphrontDatabaseConnection $conn) {

View file

@ -179,7 +179,9 @@ final class PhabricatorStorageManagementDumpWorkflow
$argv = array();
$argv[] = '--hex-blob';
$argv[] = '--single-transaction';
$argv[] = '--default-character-set=utf8';
$argv[] = '--default-character-set';
$argv[] = $api->getClientCharset();
if ($args->getArg('for-replica')) {
$argv[] = '--master-data';

View file

@ -31,8 +31,8 @@ final class PhabricatorStorageManagementShellWorkflow
}
return phutil_passthru(
'mysql --protocol=TCP --default-character-set=utf8mb4 '.
'-u %s %C -h %s %C',
'mysql --protocol=TCP --default-character-set %R -u %s %C -h %s %C',
$api->getClientCharset(),
$api->getUser(),
$flag_password,
$host,