imp: several improvements on add-ons uninstall process

- only try to uninstall already installed add-ons
- display the final list of add-ons to remove (dependencies included)
- ask final confirmation
- remove useless temporary files
- clean code
This commit is contained in:
Stéphan Sainléger
2024-11-26 13:05:02 +01:00
parent 09a855258e
commit 4afbcbf55b
3 changed files with 32 additions and 74 deletions

View File

@@ -1,8 +0,0 @@
account_balance_line
account_menu
account_statement_import
account_statement_import_file_reconciliation_widget
project_mail_chatter
project_timeline_task_dependency
web_drop_target
web_ir_actions_act_view_reload

View File

@@ -1,32 +0,0 @@
account_balance_line
account_menu
account_statement_import
account_statement_import_file_reconciliation_widget
project_mail_chatter
project_timeline_task_dependency
web_drop_target
web_ir_actions_act_view_reload
galicea_base
galicea_environment_checkup
mass_editing
mass_mailing_themes
muk_autovacuum
muk_fields_lobject
muk_fields_stream
muk_utils
muk_web_theme_mail
muk_web_utils
account_usability
kpi_dashboard
web_window_title
website_project_kanbanview
project_usability
project_tag
maintenance_server_monitoring_ping
maintenance_server_monitoring_ssh
maintenance_server_monitoring_memory
maintenance_server_monitoring_maintenance_equipment_status
maintenance_server_monitoring_disk
project_task_assignees_avatar
account_partner_reconcile
account_invoice_import_simple_pdf

View File

@@ -6,13 +6,6 @@ DB_NAME="$2"
DB_FINALE_MODEL="$3" DB_FINALE_MODEL="$3"
DB_FINALE_SERVICE="$4" DB_FINALE_SERVICE="$4"
# Function to display the combined list of add-ons to uninstall
display_combined_list(){
cat 404_addons force_uninstall_addons > combined_addons
echo "UPGRADE: Add-ons to uninstall (forced and not found in final Odoo version):"
cat combined_addons
}
# Function to ask if the add-ons list to uninstall is OK # Function to ask if the add-ons list to uninstall is OK
ask_confirmation() { ask_confirmation() {
while true; do while true; do
@@ -20,27 +13,17 @@ ask_confirmation() {
Do you accept to uninstall all these add-ons? (Y/N/R)" Do you accept to uninstall all these add-ons? (Y/N/R)"
echo "Y - Yes, let's go on with the upgrade." echo "Y - Yes, let's go on with the upgrade."
echo "N - No, stop the upgrade" echo "N - No, stop the upgrade"
echo "R - I've edited the list, please Re-display it"
read -n 1 -p "Your choice: " choice read -n 1 -p "Your choice: " choice
case "$choice" in case "$choice" in
[Yy] ) return 0;; [Yy] ) echo "
[Nn] ) return 1;; Upgrade confirmed!"; return 0;;
[Rr] ) display_combined_list; continue;; [Nn] ) echo "
* ) echo "Please answer by Y, N or R.";; Upgrade cancelled!"; return 1;;
* ) echo "Please answer by Y or N.";;
esac esac
done done
} }
# Read names from file and create SQL commands
generate_sql_to_remove_commands() {
local name
local sql_commands=""
while IFS= read -r name; do
sql_commands+="UPDATE ir_module_module SET to_remove = TRUE WHERE name = '$name';"
done < combined_addons
echo "$sql_commands"
}
# Main execution # Main execution
echo "UPGRADE: Start database preparation" echo "UPGRADE: Start database preparation"
@@ -105,29 +88,35 @@ SQL_404_ADDONS_LIST="
echo "Retrieve 404 addons... " echo "Retrieve 404 addons... "
query_postgres_container "$SQL_404_ADDONS_LIST" "$DB_NAME" > 404_addons || exit 1 query_postgres_container "$SQL_404_ADDONS_LIST" "$DB_NAME" > 404_addons || exit 1
# Create combined list of add-ons not found and add-ons which must be removed
cat 404_addons force_uninstall_addons | sort | uniq > combined_addons
# Keep only the installed add-ons
INSTALLED_ADDONS="SELECT name FROM ir_module_module WHERE state='installed';"
query_postgres_container "$INSTALLED_ADDONS" "$DB_NAME" > installed_addons || exit 1
grep -Fx -f combined_addons installed_addons > addons_to_remove
rm -f 404_addons combined_addons installed_addons
# Ask confirmation to uninstall the selected add-ons # Ask confirmation to uninstall the selected add-ons
display_combined_list echo "
==== FIRST CHECK ====
Installed add-ons to uninstall (forced OR not found in final Odoo version):
if ask_confirmation; then "
echo "Upgrade goes on..." cat addons_to_remove
else ask_confirmation || exit 1
echo "Upgrade stopped."
exit 1
fi
# Tag the selected add-ons as "to remove" # Tag the selected add-ons as "to remove"
echo "TAG the add-ons to remove..." echo "TAG the add-ons to remove..."
SQL_TAG_TO_REMOVE="" SQL_TAG_TO_REMOVE=""
while IFS= read -r name; do while IFS= read -r name; do
SQL_TAG_TO_REMOVE+="UPDATE ir_module_module SET to_remove = TRUE WHERE name = '$name' AND state = 'installed';" SQL_TAG_TO_REMOVE+="UPDATE ir_module_module SET to_remove = TRUE WHERE name = '$name' AND state = 'installed';"
done < combined_addons done < addons_to_remove
echo $SQL_TAG_TO_REMOVE
query_postgres_container "$SQL_TAG_TO_REMOVE" "$DB_NAME" || exit 1 query_postgres_container "$SQL_TAG_TO_REMOVE" "$DB_NAME" || exit 1
echo "Add-ons to be removed TAGGED." echo "Add-ons to be removed TAGGED."
rm -f addons_to_remove
# Identify the add-ons which depend on the add-on to uninstall # Identify the add-ons which depend on the add-on to uninstall
echo "Detect and tag add-ons dependencies..." echo "Detect and tag add-ons dependencies..."
@@ -152,6 +141,15 @@ SQL_UPDATE_STATE="UPDATE ir_module_module SET state = 'to remove' WHERE to_remov
query_postgres_container "$SQL_UPDATE_STATE" "$DB_NAME" || exit 1 query_postgres_container "$SQL_UPDATE_STATE" "$DB_NAME" || exit 1
echo "Add-ons to remove with state 'to remove'" echo "Add-ons to remove with state 'to remove'"
# Last check on all the add-ons to be removed
echo "
==== LAST CHECK! ====
Here is the whole list of add-ons to be removed:
"
SQL_ADDONS_TO_BE_REMOVED="SELECT name from ir_module_module WHERE state='to remove';"
query_postgres_container "$SQL_ADDONS_TO_BE_REMOVED" "$DB_NAME" || exit 1
ask_confirmation || exit 1
# Launch Odooo container and launch the uninstall function # Launch Odooo container and launch the uninstall function
echo "Launch Odoo to uninstall add-ons..." echo "Launch Odoo to uninstall add-ons..."