callback::merge::MergePackageUser::impl::calendar (private)

 callback::merge::MergePackageUser::impl::calendar \
    -from_user_id from_user_id -to_user_id to_user_id

Defined in packages/calendar/tcl/calendar-callback-procs.tcl

Merge the calendars of two users. The from_user_id is the user_id of the user that will be deleted and all the calendar elements of this user will be mapped to the to_user_id.

Switches:
-from_user_id (required)
-to_user_id (required)
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 db_dml db_dml (public) db_list_of_lists db_list_of_lists (public) db_string db_string (public) db_transaction db_transaction (public) callback::merge::MergePackageUser::impl::calendar callback::merge::MergePackageUser::impl::calendar callback::merge::MergePackageUser::impl::calendar->db_dml callback::merge::MergePackageUser::impl::calendar->db_list_of_lists callback::merge::MergePackageUser::impl::calendar->db_string callback::merge::MergePackageUser::impl::calendar->db_transaction

Testcases:
No testcase defined.
Source code:
    ::callback::merge::MergePackageUser::contract__arg_parser {*}$args

    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
            lassign $calendar l_cal_id l_pkg_id

            # if the pkg_id of this cal_id is
            # 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
    #   }
    return $return_msg
Generic XQL file:
<fullquery name="callback::merge::MergePackageUser::impl::calendar.get_from_calendars">
    <querytext>	
	select calendar_id,package_id
	from calendars
	where owner_id = :from_user_id
    </querytext>
</fullquery>

<fullquery name="callback::merge::MergePackageUser::impl::calendar.get_repeated_pkgs">
    <querytext>	
      select count(*)
      from calendars
      where owner_id = :to_user_id
      and package_id = :l_pkg_id
    </querytext>
</fullquery>

<fullquery name="callback::merge::MergePackageUser::impl::calendar.calendars_upd">
    <querytext>	
      update calendars
      set owner_id = :to_user_id
      where owner_id = :from_user_id
      and calendar_id = :l_cal_id
    </querytext>
</fullquery>

<fullquery name="callback::merge::MergePackageUser::impl::calendar.gettocalid">
    <querytext>	
      select calendar_id 
      from calendars 
      where package_id = :l_pkg_id 
      and owner_id = :to_user_id
    </querytext>
</fullquery>

<fullquery name="callback::merge::MergePackageUser::impl::calendar.calendar_items_upd">
    <querytext>	
      update cal_items 
      set on_which_calendar = :to_cal_id
      where on_which_calendar = :l_cal_id
    </querytext>
</fullquery>

<fullquery name="callback::merge::MergePackageUser::impl::calendar.del_from_cal">
    <querytext>	
      delete
      from calendars
      where calendar_id = :l_cal_id
    </querytext>
</fullquery>
packages/calendar/tcl/calendar-callback-procs.xql

PostgreSQL XQL file:
packages/calendar/tcl/calendar-callback-procs-postgresql.xql

Oracle XQL file:
packages/calendar/tcl/calendar-callback-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: