Skip to content

Commit

Permalink
Update database collection config if auto-detectable
Browse files Browse the repository at this point in the history
  • Loading branch information
mneudert committed Sep 11, 2024
1 parent e7f5bc4 commit 776ff34
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
57 changes: 57 additions & 0 deletions core/Updates/5.2.0-b2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Updates;

use Piwik\Common;
use Piwik\Config;
use Piwik\Db;
use Piwik\Updater;
use Piwik\Updates;

class Updates_5_2_0_b2 extends Updates
{
public function doUpdate(Updater $updater)
{
$config = Config::getInstance();
$dbConfig = $config->database;

if (!empty($dbConfig['collation'])) {
// config already set, nothing to do
return;
}

if (!is_writable(Config::getLocalConfigPath())) {
// rely on the system check if config is not writable
return;
}

try {
$db = Db::get();
$userTable = Common::prefixTable('user');
$userTableStatus = $db->fetchRow('SHOW TABLE STATUS WHERE Name = ?', [$userTable]);
$connectionCollation = $db->fetchOne('SELECT @@collation_connection');

if (
empty($userTableStatus['Collation'])
|| empty($connectionCollation)
|| $userTableStatus['Collation'] !== $connectionCollation
) {
// skip config update if user table and connection have different collations
return;
}

$dbConfig['collation'] = $connectionCollation;
$config->database = $dbConfig;
$config->forceSave();
} catch (\Exception $e) {
// rely on the system check if detection failed
}
}
}
2 changes: 1 addition & 1 deletion core/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class Version
* The current Matomo version.
* @var string
*/
public const VERSION = '5.2.0-b1';
public const VERSION = '5.2.0-b2';

public const MAJOR_VERSION = 5;

Expand Down

0 comments on commit 776ff34

Please sign in to comment.