Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/private/Repair/Collation.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function run(IOutput $output): void {
} catch (DriverException $e) {
// Just log this
$this->logger->error($e->getMessage(), ['exception' => $e]);
$output->warning($e->getMessage());
if (!$this->ignoreFailures) {
throw $e;
}
Expand All @@ -64,6 +65,7 @@ public function run(IOutput $output): void {
} catch (DriverException $e) {
// Just log this
$this->logger->error($e->getMessage(), ['exception' => $e]);
$output->warning($e->getMessage());
if (!$this->ignoreFailures) {
throw $e;
}
Expand All @@ -81,12 +83,22 @@ protected function getAllNonUTF8BinTables(IDBConnection $connection): array {
$dbName = $this->config->getSystemValueString('dbname');
$characterSet = $this->config->getSystemValueBool('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8';

// Since MySQL 8.0.30, INFORMATION_SCHEMA reports the legacy 3-byte utf8
// charset/collation as "utf8mb3" instead of the "utf8" alias used to
// create it, so both names have to be accepted or already-correct
// tables get flagged as needing repair on every run.
// See https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb3.html
$acceptedCharsets = $characterSet === 'utf8' ? ['utf8', 'utf8mb3'] : [$characterSet];
$acceptedCollations = array_map(static fn (string $charset): string => $charset . '_bin', $acceptedCharsets);
$charsetList = "'" . implode("', '", $acceptedCharsets) . "'";
$collationList = "'" . implode("', '", $acceptedCollations) . "'";

// fetch tables by columns
$statement = $connection->executeQuery(
'SELECT DISTINCT(TABLE_NAME) AS `table`'
. ' FROM INFORMATION_SCHEMA . COLUMNS'
. ' WHERE TABLE_SCHEMA = ?'
. " AND (COLLATION_NAME <> '" . $characterSet . "_bin' OR CHARACTER_SET_NAME <> '" . $characterSet . "')"
. " AND (COLLATION_NAME NOT IN ($collationList) OR CHARACTER_SET_NAME NOT IN ($charsetList))"
. " AND TABLE_NAME LIKE '*PREFIX*%'",
[$dbName]
);
Expand All @@ -101,7 +113,7 @@ protected function getAllNonUTF8BinTables(IDBConnection $connection): array {
'SELECT DISTINCT(TABLE_NAME) AS `table`'
. ' FROM INFORMATION_SCHEMA . TABLES'
. ' WHERE TABLE_SCHEMA = ?'
. " AND TABLE_COLLATION <> '" . $characterSet . "_bin'"
. " AND TABLE_COLLATION NOT IN ($collationList)"
. " AND TABLE_NAME LIKE '*PREFIX*%'",
[$dbName]
);
Expand Down
Loading