Index: openacs-4/packages/calendar/tcl/calendar-callback-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/tcl/calendar-callback-procs.tcl,v diff -u -r1.8 -r1.9 --- openacs-4/packages/calendar/tcl/calendar-callback-procs.tcl 7 Aug 2017 23:48:05 -0000 1.8 +++ openacs-4/packages/calendar/tcl/calendar-callback-procs.tcl 24 Apr 2018 14:28:56 -0000 1.9 @@ -13,14 +13,14 @@ } { set msg "Calendars of user_id: $user_id" set return_msg [list $msg] - + set cals [db_list get_calendars {*SQL*} ] if { $cals eq "" } { - lappend return_msg "none" + lappend return_msg "none" } else { - lappend return_msg $cals + lappend return_msg $cals } - + return $return_msg } @@ -36,49 +36,48 @@ set msg "Merging calendar" ns_log Notice $msg set return_msg [list $msg] - + set from_calendars [db_list_of_lists get_from_calendars {*SQL*} ] db_transaction { - ns_log Notice " Entering to calendar transaction" - foreach calendar $from_calendars { - # l_* vars will represent - # each item of the from_user_id list of lists - set l_cal_id [lindex $calendar 0] - set l_pkg_id [lindex $calendar 1] - - # if the pkg_id of this cal_id is the - # the same for some to_user_id cal - # we have to delete it, else we must - # change the items from one cal to the other one - if { [db_string get_repeated_pkgs {*SQL*} ] } { - # We will move the cal items if the - # calendars are of the same type (package_id) - set to_cal_id [db_string gettocalid {*SQL*} ] - - db_dml calendar_items_upd { *SQL* } - - # ns_log Notice " Deleting calendar" - # TODO: calendar::delete -calendar_id $l_cal_i is broken - # so, we will delete directly from the calendars table - db_dml del_from_cal { *SQL* } - - } else { - ns_log Notice " Change owner of $calendar" - # change the owner - db_dml calendars_upd { *SQL* } - } - } - set msg " Calendar merge is done" - ns_log Notice $msg - lappend return_msg $msg + ns_log Notice " Entering to calendar transaction" + foreach calendar $from_calendars { + # l_* vars will represent + # each item of the from_user_id list of lists + lassign $calendar l_cal_id l_pkg_id + + # if the pkg_id of this cal_id is the + # the same for some to_user_id cal + # we have to delete it, else we must + # change the items from one cal to the other one + if { [db_string get_repeated_pkgs {*SQL*} ] } { + # We will move the cal items if the + # calendars are of the same type (package_id) + set to_cal_id [db_string gettocalid {*SQL*} ] + + db_dml calendar_items_upd { *SQL* } + + # ns_log Notice " Deleting calendar" + # TODO: calendar::delete -calendar_id $l_cal_i is broken + # so, we will delete directly from the calendars table + db_dml del_from_cal { *SQL* } + + } else { + ns_log Notice " Change owner of $calendar" + # change the owner + db_dml calendars_upd { *SQL* } + } + } + set msg " Calendar merge is done" + ns_log Notice $msg + lappend return_msg $msg } # I commented this section to avoid partial merges # If something is wrong the merge should be stopped. - # on_error { - # set msg " I couldn't merge calendar. The error was $errmsg" - # ns_log Notice $msg - # lappend return_msg $msg - # } + # on_error { + # set msg " I couldn't merge calendar. The error was $errmsg" + # ns_log Notice $msg + # lappend return_msg $msg + # } return $return_msg }