Index: openacs-4/packages/calendar/tcl/apm-callback-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/tcl/apm-callback-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/calendar/tcl/apm-callback-procs.tcl 7 Aug 2017 23:48:05 -0000 1.3 +++ openacs-4/packages/calendar/tcl/apm-callback-procs.tcl 3 Sep 2024 15:37:35 -0000 1.4 @@ -13,7 +13,7 @@ namespace eval calendar::apm {} -ad_proc -public calendar::apm::package_after_upgrade { +ad_proc -private calendar::apm::package_after_upgrade { -from_version_name:required -to_version_name:required } { @@ -34,9 +34,37 @@ } } +ad_proc -private calendar::apm::before_uninstantiate { + -package_id:required +} { + Cleanup calendars from this package instance upon uninstantiation. +} { + # get calendar ids + set calendar_list [db_list get_calendar_ids { + SELECT calendar_id FROM calendars + WHERE package_id = :package_id + }] + # delete calendars + foreach calendar_id $calendar_list { + # delete all calendar items + db_foreach get_calendar_items { + SELECT cal_item_id FROM cal_items + WHERE on_which_calendar = :calendar_id + } { + calendar::item::delete -cal_item_id $cal_item_id + } + # delete item types + db_foreach get_item_types { + SELECT item_type_id FROM cal_item_types + WHERE calendar_id= :calendar_id + } { + calendar::item_type_delete -calendar_id $calendar_id -item_type_id $item_type_id + } + # delete calendar + calendar::delete -calendar_id $calendar_id + } +} - - # Local variables: # mode: tcl # tcl-indent-level: 4