Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(DB): added charset to DB Params #6153

Closed
wants to merge 1 commit into from

Conversation

degoya
Copy link

@degoya degoya commented Jan 15, 2024

Fix Database Problem with Emojis like 🦉📌

Kirby was not able to display or save Emojis like 🦉📌 to the Database. The reason was the wrong charset, the problem is that the charset is'nt loaded to params from the config.

Fixes

loading charset from config to DB params

@distantnative distantnative added this to the 4.1.0 milestone Jan 15, 2024
@distantnative distantnative requested a review from a team January 15, 2024 15:07
@afbora afbora changed the base branch from main to develop-minor January 16, 2024 08:54
@afbora
Copy link
Member

afbora commented Jan 16, 2024

I like the new charset config. We have also one more charset config that for setting via params.

https://github.com/degoya/kirby/blob/db-fix/src/Database/Database.php#L569

But I can't decide which one we should to use utf8 or utf8mb4. utf8mb4 charset is supported for all mysql versions? We should update both usage to utf8 or utf8mb4.

@degoya
Copy link
Author

degoya commented Jan 16, 2024

I like the new charset config. We have also one more charset config that for setting via params.

https://github.com/degoya/kirby/blob/db-fix/src/Database/Database.php#L569

But I can't decide which one we should to use utf8 or utf8mb4. utf8mb4 charset is supported for all mysql versions? We should update both usage to utf8 or utf8mb4.

i would prefer utf8mb4 it is supported by MySQL 8.0. 28 and later, this is also the default for Word Press and other DB based CMS today. this should only noted in the docs and you are still able to use utf8 as a setting for a fallback. but in modern times this should not be needed IMHO.

@bastianallgeier
Copy link
Member

@afbora I think you found the correct line to set this. If we set it there, the additional definition in the DB class could just return null as default and would then automatically fall back to the value set in the Database class.

@afbora
Copy link
Member

afbora commented Jan 16, 2024

You're right @bastianallgeier I think we should implement like that

$parts[] = 'charset=' . ($params['charset'] ?? Config::get('db.charset', 'utf8mb4'));

https://github.com/getkirby/kirby/blob/develop-minor/src/Database/Database.php#L569

@distantnative
Copy link
Member

@bastianallgeier @afbora wouldn't the opposite make more sense? Keep the Config::get together with the other configs, add the fallback there and then remove any fallback here https://github.com/degoya/kirby/blob/db-fix/src/Database/Database.php#L569 as it won't be needed anymore?

@afbora
Copy link
Member

afbora commented Jan 16, 2024

But charset won't set if params argument passed and chartset not defined in params.

@distantnative
Copy link
Member

distantnative commented Jan 16, 2024

But my understanding is that $params['charset'] would always be defined when we merge this PR, wouldn't it?

$params is

@distantnative
Copy link
Member

Ah sorry, I see your point. If someone sets explicit $params for Db then it could be missing.

@distantnative
Copy link
Member

Then I would do

'charset'  => Config::get('db.charset', null)

https://github.com/degoya/kirby/blob/db-fix/src/Database/Db.php#L51

And

		$parts[] = 'charset=' . ($params['charset'] ?? 'utf8mb4');

https://github.com/degoya/kirby/blob/db-fix/src/Database/Database.php#L569

@bastianallgeier
Copy link
Member

bastianallgeier commented Jan 17, 2024

@distantnative yep, that's how I would solve it too. @degoya do you want to fix it in your PR or should we take over?

@bastianallgeier
Copy link
Member

@degoya I've taken over and made the last changes. Thank you for your help. We will make sure to mention you in the release notes. #6153

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants