From 72421ab7e2f12b00560c091b6119699e1f982b35 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 21 Jun 2023 13:08:33 +0800 Subject: [PATCH] Check mysql database charset when installation --- options/locale/locale_en-US.ini | 1 + routers/install/install.go | 6 ++++++ templates/install.tmpl | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 0cf8810702025..7b24a6157b272 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -216,6 +216,7 @@ err_empty_admin_email = The administrator email cannot be empty. err_admin_name_is_reserved = Administrator Username is invalid, username is reserved err_admin_name_pattern_not_allowed = Administrator username is invalid, the username matches a reserved pattern err_admin_name_is_invalid = Administrator Username is invalid +err_mysql_charset_must_utf8mb4 = The MySQL database should use UTF8Mb4 only general_title = General Settings app_name = Site Title diff --git a/routers/install/install.go b/routers/install/install.go index 16bb55b685b75..2aeff1ad1cb91 100644 --- a/routers/install/install.go +++ b/routers/install/install.go @@ -174,6 +174,12 @@ func checkDatabase(ctx *context.Context, form *forms.InstallForm) bool { return false } + if setting.Database.Type == "mysql" && setting.Database.Charset != "utf8mb4" { + ctx.Data["Err_DbCharset"] = true + ctx.RenderWithErr(ctx.Tr("install.err_mysql_charset_must_utf8mb4"), tplInstall, form) + return false + } + // Check if the user is trying to re-install in an installed database db.UnsetDefaultEngine() defer db.UnsetDefaultEngine() diff --git a/templates/install.tmpl b/templates/install.tmpl index 1cd5dcff8bacf..560496e8a38a4 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -70,7 +70,7 @@
-
+