Skip to content

Commit

Permalink
Add database collation to diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
mneudert committed Sep 11, 2024
1 parent 776ff34 commit d36002d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
24 changes: 24 additions & 0 deletions plugins/Diagnostics/Diagnostic/DatabaseAbilitiesCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function execute()
$result = new DiagnosticResult($this->translator->translate('Installation_DatabaseAbilities'));

$result->addItem($this->checkUtf8mb4Charset());
$result->addItem($this->checkCollation());

if (Config::getInstance()->General['enable_load_data_infile']) {
$result->addItem($this->checkLoadDataInfile());
Expand Down Expand Up @@ -92,6 +93,29 @@ protected function checkUtf8mb4Charset()
);
}

protected function checkCollation(): DiagnosticResultItem
{
$dbSettings = new Db\Settings();
$collation = $dbSettings->getUsedCollation();

if ('' !== $collation) {
return new DiagnosticResultItem(DiagnosticResult::STATUS_OK, 'Connection collation');
}

$collationConnection = Db::get()->fetchOne('SELECT @@collation_connection');
$collationCharset = DbHelper::getDefaultCollationForCharset($dbSettings->getUsedCharset());

return new DiagnosticResultItem(
DiagnosticResult::STATUS_WARNING,
sprintf(
'Connection collation<br/><br/>%s<br/><br/>%s<br/>%s<br/>',
$this->translator->translate('Diagnostics_DatabaseCollationNotConfigured'),
$this->translator->translate('Diagnostics_DatabaseCollationConnection', [$collationConnection]),
$this->translator->translate('Diagnostics_DatabaseCollationCharset', [$collationCharset])
)
);
}

protected function checkLoadDataInfile()
{
$optionTable = Common::prefixTable('option');
Expand Down
3 changes: 2 additions & 1 deletion plugins/Diagnostics/Diagnostic/DatabaseInformational.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Piwik\Translation\Translator;

/**
* Informatation about the database.
* Information about the database.
*/
class DatabaseInformational implements Diagnostic
{
Expand All @@ -38,6 +38,7 @@ public function execute()
$dbConfig = Config::getInstance()->database;
$results[] = DiagnosticResult::informationalResult('DB Prefix', $dbConfig['tables_prefix']);
$results[] = DiagnosticResult::informationalResult('DB Charset', $dbConfig['charset']);
$results[] = DiagnosticResult::informationalResult('DB Collation', $dbConfig['collation']);
$results[] = DiagnosticResult::informationalResult('DB Adapter', $dbConfig['adapter']);
$results[] = DiagnosticResult::informationalResult('MySQL Version', $this->getServerVersion());
$results[] = DiagnosticResult::informationalResult('Num Tables', $this->getNumMatomoTables());
Expand Down
3 changes: 3 additions & 0 deletions plugins/Diagnostics/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"Sections": "Sections",
"BrowserAndAutoArchivingEnabledLabel": "Browser and Auto-archiving enabled",
"BrowserAndAutoArchivingEnabledComment": "It looks like both browser and auto archiving are enabled. Auto archiving last started %3$s ago. If %1$sauto archiving%2$s is enabled, you should disable browser archiving in \"General Settings\".",
"DatabaseCollationNotConfigured": "You database connection is configured without an explicit collation. Please update <code>[database] collation = ''</code> in the \"config/config.ini.php\" file with the collation to be used, to ensure all database features work as expected.",
"DatabaseCollationConnection": "Your currently used connection collation is: <code>%1$s</code>",
"DatabaseCollationCharset": "The default collation collation for your configured charset is: <code>%1$s</code>",
"DatabaseReaderConnection": "Database Reader Connection",
"DatabaseUtf8Requirement": "This is required to be able to store 4-byte UTF8 characters. Unless utf8mb4 is available special characters, such as emojis, less common characters of asian languages, various historic scripts or mathematical symbols will be replaced with %1$s. You can read more details about this topic in %2$sthis FAQ%3$s.",
"DatabaseUtf8mb4CharsetRecommended": "Your database doesn't support utf8mb4 charset yet.",
Expand Down

0 comments on commit d36002d

Please sign in to comment.