From 82e6e95c516e7fe138a067e6446b476c04656ab3 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Wed, 21 Dec 2022 16:55:53 +0100 Subject: [PATCH] Improve extension activation commands --- scripts/_common.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 67824e4..f62abc4 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -43,9 +43,10 @@ activate_flarum_extension() { sql_command="SELECT \`value\` FROM settings WHERE \`key\` = 'extensions_enabled'" old_extensions_enabled=$(ynh_mysql_execute_as_root "$sql_command" $database | tail -1) - # Append the extension name at the end of the list - addition=",\"${short_extension}\"]" - new_extensions_enabled=${old_extensions_enabled::-1}$addition + # Use jq to test presence of the extension in the list of enabled extensions + # if not, then add it. + new_extensions_enabled=$(jq -jrc --arg short_extension 'if (any(index("$short_extension")) | not) then . |= + $short_extension else . end' <<< $old_extensions_enabled) + # Update activated extensions list sql_command="UPDATE \`settings\` SET \`value\`='$new_extensions_enabled' WHERE \`key\`='extensions_enabled';" ynh_mysql_execute_as_root "$sql_command" $database