matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.68k stars 2.62k forks source link

Improve database collation detection #22594

Open mneudert opened 4 days ago

mneudert commented 4 days ago

Description:

The collation detection introduced in #22564 can create problems in some environments, most likely for MariaDB 11.4+.

In MariaDB 11.4+ the query SHOW COLLATION WHERE `Default` = "Yes" AND `Charset` = 'utf8mb4' does not return any result, and throwing an exception means a new installation is not possible. Showing the diagnostics page also crashes if no collation is configured.

When updating an existing Matomo installation, the update migration should detect a collation to prevent this problem. However, if there are already mixed tables (e.g. users table with general_ci and archive table with uca1400_ai_ci) this is not something we can be really sure of.

The check is changed to use SHOW CHARACTER SET instead. This should, at least for utf8mb4 character sets, always return a default we can use for installation/diagnostics. For utf8, or if there is no value found, it will now return an empty string. With the updated CREATE DATABASE statement, this should now allow installation for MariaDB 11.4+ again, and also for database setups that are not configured to handle utf8mb4.

Forcing utf8 charset detection during install

The configuration should be created as [database] charset = utf8 (missing from config.ini.php because this is the default from global.ini.php), and no collation.

Review