From 1c4e766984657411f58ad79732cb4333accf2382 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Sun, 12 Aug 2018 00:29:57 +0200 Subject: [PATCH] More standard usage of mysql helper --- scripts/install | 14 ++++---------- scripts/remove | 7 +++---- scripts/upgrade | 8 ++++++++ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/scripts/install b/scripts/install index 6c9b363..3e3eac1 100644 --- a/scripts/install +++ b/scripts/install @@ -89,16 +89,10 @@ ynh_install_app_dependencies php-gd php-curl php-imagick php-cli php-zmq # CREATE A MYSQL DATABASE #================================================= -# Generate and save random MySQL password -db_pwd=$(ynh_string_random 12) -ynh_app_setting_set "$app" mysqlpwd "$db_pwd" - -# Use 'movim' as database name and user -db_user=movim -db_name=movim - -# Create MySQL database -ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd" +db_name=$(ynh_sanitize_dbid "$app") +db_user=$db_name +ynh_app_setting_set "$app" db_name "$db_name" +ynh_mysql_setup_db "$db_user" "$db_name" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE diff --git a/scripts/remove b/scripts/remove index abff694..f9d7661 100644 --- a/scripts/remove +++ b/scripts/remove @@ -19,6 +19,8 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get "$app" domain) final_path=$(ynh_app_setting_get "$app" final_path) port=$(ynh_app_setting_get "$app" port) +db_name=$(ynh_app_setting_get "$app" db_name) +db_user=$db_name #================================================= # REMOVE NGINX CONFIGURATION @@ -52,10 +54,7 @@ ynh_remove_app_dependencies # REMOVE THE MYSQL DATABASE #================================================= -db_user=movim -db_name=movim -ynh_mysql_drop_db "$db_name" || true -ynh_mysql_drop_user "$db_user" || true +ynh_mysql_remove_db "$db_user" "$db_name" #================================================= # REMOVE APP MAIN DIR diff --git a/scripts/upgrade b/scripts/upgrade index 71f3c05..0b626a5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -23,6 +23,7 @@ ssoenabled=$(ynh_app_setting_get "$app" ssoenabled) public_site=$(ynh_app_setting_get "$app" public_site) timezone=$(cat /etc/timezone) final_path=$(ynh_app_setting_get "$app" final_path) +db_name=$(ynh_app_setting_get "$app" db_name) #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -34,6 +35,13 @@ if [ -z "$final_path" ]; then ynh_app_setting_set "$app" final_path "$final_path" fi + +# If db_name doesn't exist, create it +if [ -z "$db_name" ]; then + db_name=$(ynh_sanitize_dbid "$app") + ynh_app_setting_set "$app" db_name "$db_name" +fi + #================================================= # ACTIVE TRAP #=================================================