Update ynh_mysql_connect_as in mysql helper

Update ynh_mysql_connect_as() helper to be able, when restoring a database, to specify --default-character-set="xxx", xxx being latin1 or utf8mb4
This commit is contained in:
Thatoo 2024-05-16 22:35:10 +02:00 committed by GitHub
parent 498b8d9c43
commit 5babe3dce6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,16 +14,25 @@
# Requires YunoHost version 2.2.4 or higher. # Requires YunoHost version 2.2.4 or higher.
ynh_mysql_connect_as() { ynh_mysql_connect_as() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=upd local legacy_args=updc
local -A args_array=([u]=user= [p]=password= [d]=database=) local -A args_array=( [u]=user= [p]=password= [d]=database= [c]=default_character_set= )
local user local user
local password local password
local database local database
local default_character_set
# Manage arguments with getopts # Manage arguments with getopts
ynh_handle_getopts_args "$@" ynh_handle_getopts_args "$@"
database="${database:-}" database="${database:-}"
default_character_set="${default_character_set:-}"
mysql --user="$user" --password="$password" --batch "$database" if [ -n "$default_character_set" ]
then
default_character_set="--default-character-set=$default_character_set"
else
default_character_set="--default-character-set=latin1"
fi
mysql --user="$user" --password="$password" "$default_character_set" --batch "$database"
} }
# Execute a command as root user # Execute a command as root user