Index: openacs-4/packages/file-storage/www/version-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/www/version-delete.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/file-storage/www/version-delete.tcl 20 Apr 2001 20:51:10 -0000 1.1 +++ openacs-4/packages/file-storage/www/version-delete.tcl 25 Aug 2001 00:38:54 -0000 1.2 @@ -33,16 +33,51 @@ db_exec_plsql version_delete " begin + + if :version_id = content_item.get_live_revision(:item_id) then content_revision.delete (:version_id); content_item.set_live_revision(content_item.get_latest_revision(:item_id)); else content_revision.delete (:version_id); end if; + end;" - ad_returnredirect "file?file_id=$item_id" + # JS: + # If the version is the last revision available, we also need to remove the + # item from cr_items! How come CR does not take care of this? (Note: CR merely + # sets live_revision in cr_items to null). The redirect should be to the parent + # folder if there are no more revisions, so we need to get the parent folder before we + # actually remove the entry in cr_items (I guess this is the reason why CR does not + # actually delete the item even if there are no more revisions for it). + if [db_string deleted_last_revision " + select (case when live_revision = null + then 1 + else 0 + end) + from cr_items + where item_id = :item_id"] { + # Get the parent if we will be deleting the item + set parent_id [db_string parent_folder " + select parent_id from cr_items where item_id = :item_id"] + + # Actually delete + db_exec_plsql delete_item " + begin + content_item.delete(:item_id); + end;" + + # Redirect to the folder, instead of the latest revision (which does not exist anymore) + ad_returnredirect "?folder_id=$parent_id" + + } else { + + # Ok, we don't have to do anything fancy, just redirect to th last revision + ad_returnredirect "file?file_id=$item_id" + } + } else { # they still need to confirm