Index: openacs-4/packages/acs-admin/www/apm/package-delete-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-admin/www/apm/package-delete-2.tcl,v diff -u -r1.9 -r1.9.2.1 --- openacs-4/packages/acs-admin/www/apm/package-delete-2.tcl 7 Aug 2017 23:47:45 -0000 1.9 +++ openacs-4/packages/acs-admin/www/apm/package-delete-2.tcl 15 Nov 2021 17:28:05 -0000 1.9.2.1 @@ -28,6 +28,7 @@ if { [catch {apm_package_delete \ -sql_drop_scripts $sql_drop_scripts \ -remove_files=0 \ + -delete_site_nodes \ -callback apm_body_callback $package_key} errmsg] } { append body [subst { We encountered the following error when deleting package "$package_key": Index: openacs-4/packages/acs-tcl/tcl/apm-install-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/apm-install-procs.tcl,v diff -u -r1.126.2.17 -r1.126.2.18 --- openacs-4/packages/acs-tcl/tcl/apm-install-procs.tcl 2 Nov 2021 10:29:05 -0000 1.126.2.17 +++ openacs-4/packages/acs-tcl/tcl/apm-install-procs.tcl 15 Nov 2021 17:28:06 -0000 1.126.2.18 @@ -1144,6 +1144,7 @@ {-sql_drop_scripts ""} {-callback apm_dummy_callback} {-remove_files:boolean} + {-delete_site_nodes:boolean} package_key } { @@ -1159,6 +1160,7 @@ # Unmount all instances of this package with the Tcl API that # invokes before-unmount callbacks db_transaction { + set site_nodes [list] db_foreach all_package_instances { select site_nodes.node_id from apm_packages, site_nodes @@ -1168,6 +1170,7 @@ set url [site_node::get_url -node_id $node_id] apm_callback_and_log $callback "Unmounting package instance at url $url
" site_node::unmount -node_id $node_id + lappend site_nodes $node_id } # Delete the package instances with Tcl API that invokes @@ -1214,6 +1217,24 @@ } } + if {$delete_site_nodes_p} { + # We also cleanup the leftover site nodes. We must check that + # the nodes still exist because the uninstall callbacks might + # have taken care of them already. We also need to make sure + # that the nodes do not have subnodes, as the deletion would + # fail otherwise. + foreach node_id $site_nodes { + if {[db_0or1row still_exists_and_is_leaf { + select 1 from site_nodes n + where node_id = :node_id + and not exists (select 1 from site_nodes + where parent_id = n.node_id) + }]} { + site_node::delete -node_id $node_id + } + } + } + # Flush the installed_p cache util_memoize_flush [list apm_package_installed_p_not_cached $package_key]