Use getopts helpers in mysql, again

This commit is contained in:
Maniack Crudelis 2019-01-04 17:21:17 +01:00
parent 976f160afb
commit 7de184a520

View file

@ -40,8 +40,8 @@ ynh_mysql_execute_as_root() {
ynh_handle_getopts_args "$@" ynh_handle_getopts_args "$@"
database="${database:-}" database="${database:-}"
ynh_mysql_connect_as "root" "$(sudo cat $MYSQL_ROOT_PWD_FILE)" \ ynh_mysql_connect_as --user="root" --password="$(sudo cat $MYSQL_ROOT_PWD_FILE)" \
"$database" <<< "$sql" --database="$database" <<< "$sql"
} }
# Execute a command from a file as root user # Execute a command from a file as root user
@ -59,8 +59,8 @@ ynh_mysql_execute_file_as_root() {
ynh_handle_getopts_args "$@" ynh_handle_getopts_args "$@"
database="${database:-}" database="${database:-}"
ynh_mysql_connect_as "root" "$(sudo cat $MYSQL_ROOT_PWD_FILE)" \ ynh_mysql_connect_as --user="root" --password="$(sudo cat $MYSQL_ROOT_PWD_FILE)" \
"$database" < "$file" --database="$database" < "$file"
} }
# Create a database and grant optionnaly privilegies to a user # Create a database and grant optionnaly privilegies to a user
@ -83,7 +83,7 @@ ynh_mysql_create_db() {
sql+=" WITH GRANT OPTION;" sql+=" WITH GRANT OPTION;"
fi fi
ynh_mysql_execute_as_root "$sql" ynh_mysql_execute_as_root --sql="$sql"
} }
# Drop a database # Drop a database
@ -96,7 +96,7 @@ ynh_mysql_create_db() {
# usage: ynh_mysql_drop_db db # usage: ynh_mysql_drop_db db
# | arg: db - the database name to drop # | arg: db - the database name to drop
ynh_mysql_drop_db() { ynh_mysql_drop_db() {
ynh_mysql_execute_as_root "DROP DATABASE ${1};" ynh_mysql_execute_as_root --sql="DROP DATABASE ${1};"
} }
# Dump a database # Dump a database
@ -126,7 +126,7 @@ ynh_mysql_dump_db() {
# | arg: pwd - the password to identify user by # | arg: pwd - the password to identify user by
ynh_mysql_create_user() { ynh_mysql_create_user() {
ynh_mysql_execute_as_root \ ynh_mysql_execute_as_root \
"CREATE USER '${1}'@'localhost' IDENTIFIED BY '${2}';" --sql="CREATE USER '${1}'@'localhost' IDENTIFIED BY '${2}';"
} }
# Check if a mysql user exists # Check if a mysql user exists
@ -142,7 +142,7 @@ ynh_mysql_user_exists()
# Manage arguments with getopts # Manage arguments with getopts
ynh_handle_getopts_args "$@" ynh_handle_getopts_args "$@"
if [[ -z $(ynh_mysql_execute_as_root "SELECT User from mysql.user WHERE User = '$user';") ]] if [[ -z $(ynh_mysql_execute_as_root --sql="SELECT User from mysql.user WHERE User = '$user';") ]]
then then
return 1 return 1
else else
@ -157,7 +157,7 @@ ynh_mysql_user_exists()
# usage: ynh_mysql_drop_user user # usage: ynh_mysql_drop_user user
# | arg: user - the user name to drop # | arg: user - the user name to drop
ynh_mysql_drop_user() { ynh_mysql_drop_user() {
ynh_mysql_execute_as_root "DROP USER '${1}'@'localhost';" ynh_mysql_execute_as_root --sql="DROP USER '${1}'@'localhost';"
} }
# Create a database, an user and its password. Then store the password in the app's config # Create a database, an user and its password. Then store the password in the app's config
@ -210,7 +210,7 @@ ynh_mysql_remove_db () {
fi fi
# Remove mysql user if it exists # Remove mysql user if it exists
if $(ynh_mysql_user_exists $db_user); then if $(ynh_mysql_user_exists --user=$db_user); then
ynh_mysql_drop_user $db_user ynh_mysql_drop_user $db_user
fi fi
} }