Index: openacs-4/packages/acs-tcl/tcl/application-data-link-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/application-data-link-procs.tcl,v diff -u -r1.5.2.1 -r1.5.2.2 --- openacs-4/packages/acs-tcl/tcl/application-data-link-procs.tcl 14 Dec 2006 13:55:10 -0000 1.5.2.1 +++ openacs-4/packages/acs-tcl/tcl/application-data-link-procs.tcl 10 Jan 2007 09:45:32 -0000 1.5.2.2 @@ -8,6 +8,8 @@ namespace eval application_data_link {} +# modified 2006/07/25 nfl: db_transaction around db_dml +# modified 2006/07/26 nfl: change db_transaction to catch ad_proc -public application_data_link::new { -this_object_id:required -target_object_id:required @@ -18,12 +20,23 @@ object. @param target_object_id The ID of the target object. } { - application_data_link::new_from \ - -object_id $this_object_id \ - -to_object_id $target_object_id - application_data_link::new_to \ - -object_id $this_object_id \ - -from_object_id $target_object_id + if { [catch { + application_data_link::new_from \ + -object_id $this_object_id \ + -to_object_id $target_object_id + + application_data_link::new_to \ + -object_id $this_object_id \ + -from_object_id $target_object_id + + }]} { + # check if error occured because of existing link + if { [application_data_link::exist_link -object_id $this_object_id -target_object_id $target_object_id] eq "1" } { + ns_log Debug "application_data_link::new: link already exists" + } else { + ns_log Error "application_data_link::new: link creation failure" + } + } } ad_proc -public application_data_link::new_from { @@ -38,6 +51,12 @@ } { set forward_rel_id [db_nextval acs_data_links_seq] + # Flush the cache for both items + util_memoize_flush_regexp "application_data_link::get_linked_not_cached -from_object_id $object_id .*" + util_memoize_flush_regexp "application_data_link::get_linked_not_cached -from_object_id $to_object_id .*" + util_memoize_flush_regexp "application_data_link::get_linked_content_not_cached -from_object_id $object_id .*" + util_memoize_flush_regexp "application_data_link::get_linked_content_not_cached -from_object_id $to_object_id .*" + db_dml create_forward_link {} } @@ -53,12 +72,34 @@ } { set backward_rel_id [db_nextval acs_data_links_seq] - db_dml create_backward_link {} + # Flush the cache for both items + util_memoize_flush_regexp "application_data_link::get_linked_not_cached -from_object_id $object_id .*" + util_memoize_flush_regexp "application_data_link::get_linked_not_cached -from_object_id $from_object_id .*" + util_memoize_flush_regexp "application_data_link::get_linked_content_not_cached -from_object_id $object_id .*" + util_memoize_flush_regexp "application_data_link::get_linked_content_not_cached -from_object_id $from_object_id .*" - db_dml create_forward_link {} db_dml create_backward_link {} } +# created 2006/07/25 nfl exist a link, returns 0 or 1 +ad_proc -public application_data_link::exist_link { + -object_id:required + -target_object_id:required +} { + Check for the existence of a link from an object_id to a target_object_id + + @param object_id The object we're looking for a link from + @param target_object_id THe object we're looking for a link to +} { + set linked_objects [ application_data_link::get -object_id $object_id ] + if { [lsearch -exact $linked_objects "$target_object_id"] != -1 } { + # found link + return 1 + } else { + return 0 + } +} + ad_proc -public application_data_link::delete_links { -object_id:required } { @@ -115,6 +156,21 @@ @return object_id of linked object. } { + return [util_memoize [list application_data_link::get_linked_not_cached -from_object_id $from_object_id -to_object_type $to_object_type]] +} + +ad_proc -public application_data_link::get_linked_not_cached { + -from_object_id:required + -to_object_type:required +} { + Gets the ID for the object linked to from_object_id and matches the + to_object_type. + + @param from_object_id Object ID of linked-from object. + @param to_object_type Object type of linked-to object. + + @return object_id of linked object. +} { return [db_list linked_object {}] } @@ -129,6 +185,20 @@ @return item_id for the content item. } { + return [util_memoize [list application_data_link::get_linked_content_not_cached -from_object_id $from_object_id -to_content_type $to_content_type]] +} + +ad_proc -public application_data_link::get_linked_content_not_cached { + -from_object_id:required + -to_content_type:required +} { + Gets the content of the linked object. + + @param from_object_id Object ID of linked-from object. + @param to_content_type Content type of linked-to object. + + @return item_id for the content item. +} { return [db_list linked_object {}] } Index: openacs-4/packages/acs-tcl/tcl/application-data-link-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/application-data-link-procs.xql,v diff -u -r1.3 -r1.3.2.1 --- openacs-4/packages/acs-tcl/tcl/application-data-link-procs.xql 1 Sep 2006 20:33:18 -0000 1.3 +++ openacs-4/packages/acs-tcl/tcl/application-data-link-procs.xql 10 Jan 2007 09:45:32 -0000 1.3.2.1 @@ -40,25 +40,23 @@ - + - select o.object_id - from acs_data_links r, acs_objects o - where r.object_id_one = :from_object_id - and r.object_id_two = o.object_id - and o.object_type = :to_object_type - order by r.object_id_two + select o.object_id + from acs_objects o + where o.object_type = :to_object_type + and o.object_id in (select object_id_two from acs_data_links where object_id_one = :from_object_id) + order by o.object_id - + select i.item_id - from acs_data_links r, cr_items i - where r.object_id_one = :from_object_id - and r.object_id_two = i.item_id - and i.content_type = :to_content_type - order by r.object_id_two + from cr_items i + where i.content_type = :to_content_type + and i.item_id in (select object_id_two from acs_data_links where object_id_one = :from_object_id) + order by i.item_id