From 5a114fddf658dd979fb9bf1b7aa31c66ac52511f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Sun, 11 Jun 2023 10:32:15 +0200 Subject: [PATCH] cleaning --- scripts/_ynh_mysql_connect_as.sh | 36 ------------------------------- scripts/install | 1 - scripts/upgrade | 37 +++++++++++++++++++++----------- 3 files changed, 24 insertions(+), 50 deletions(-) delete mode 100644 scripts/_ynh_mysql_connect_as.sh diff --git a/scripts/_ynh_mysql_connect_as.sh b/scripts/_ynh_mysql_connect_as.sh deleted file mode 100644 index a22963e..0000000 --- a/scripts/_ynh_mysql_connect_as.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -# Open a connection as a user -# -# example: ynh_mysql_connect_as --user="user" --password="pass" <<< "UPDATE ...;" -# example: ynh_mysql_connect_as --user="user" --password="pass" --default_character_set="utf8mb4" < /path/to/file.sql -# -# usage: ynh_mysql_connect_as --user=user --password=password [--database=database] [--default_character_set=character-set] -# | arg: -u, --user= - the user name to connect as -# | arg: -p, --password= - the user password -# | arg: -d, --database= - the database to connect to -# | arg: -c, --default_character_set= - the charset to use -# -# Requires YunoHost version 2.2.4 or higher. -ynh_mysql_connect_as() { - # Declare an array to define the options of this helper. - local legacy_args=updc - local -A args_array=( [u]=user= [p]=password= [d]=database= [c]=default_character_set= ) - local user - local password - local database - local default_character_set - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - database="${database:-}" - default_character_set="${default_character_set:-}" - - 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" -} \ No newline at end of file diff --git a/scripts/install b/scripts/install index b453dd0..c9d9feb 100755 --- a/scripts/install +++ b/scripts/install @@ -8,7 +8,6 @@ source _common.sh source /usr/share/yunohost/helpers -source _ynh_mysql_connect_as.sh #================================================= # STORE SETTINGS FROM MANIFEST diff --git a/scripts/upgrade b/scripts/upgrade index 9bc603e..306519c 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -123,8 +123,28 @@ local mount_id=$(exec_occ files_external:create --output=json \ && ynh_print_warn --message="Unable to create external storage" \ || exec_occ files_external:option "$mount_id" enable_sharing true } -# Define app's data directory -#data_dir="/home/yunohost.app/$app/data" + +#================================================= +# HANDLE DATABASE MIGRATION +#================================================= + +mysql_db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +if [ -n "$mysql_db_pwd" ] +then + ynh_script_progression --message="Migrate Database..." + + ynh_backup_if_checksum_is_different --file="$install_dir/config/config.php" + + ynh_psql_test_if_first_run + ynh_psql_setup_db --db_user=$db_name --db_name=$db_name + + exec_occ db:convert-type --all-apps --clear-schema pgsql $db_name 127.0.0.1 $db_name --password=$db_pwd -n + + ynh_mysql_remove_db --db_user=$db_name --db_name=$db_name + ynh_app_setting_delete --app=$app --key=mysqlpwd + + ynh_store_file_checksum --file="${install_dir}/config/config.php" +fi if [ "$upgrade_type" == "UPGRADE_APP" ] then @@ -142,15 +162,6 @@ then # Print the current version number of Nextcloud exec_occ -V - if [ "$(exec_occ config:system:get mysql.utf8mb4)" != "true" ]; then - db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) - # Change your databases character set and collation - ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name \ - <<< "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;" - # Set the mysql.utf8mb4 config to true in config.php - exec_occ config:system:set mysql.utf8mb4 --type boolean --value="true" - exec_occ maintenance:repair - fi # Upgrade may fail if this app is enabled # Take all apps enabled, and check if mail is one of them @@ -188,7 +199,7 @@ then # Load the value for this version source upgrade.d/upgrade.$current_major_version.sh - ynh_print_info --message="Upgrade to nextcloud $next_version" + ynh_print_info --message="Upgrade to Nextcloud $next_version" # Create an app.src for this version of Nextcloud cat > ../conf/app.src << EOF @@ -242,7 +253,7 @@ EOF current_version=$(grep OC_VersionString "$install_dir/version.php" | cut -d\' -f2) current_major_version=${current_version%%.*} - # Print the current version number of nextcloud + # Print the current version number of Nextcloud exec_occ -V done