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 -r1.6 --- openacs-4/packages/acs-tcl/tcl/application-data-link-procs.tcl 25 Sep 2006 13:39:19 -0000 1.5 +++ openacs-4/packages/acs-tcl/tcl/application-data-link-procs.tcl 1 Nov 2006 19:22:51 -0000 1.6 @@ -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 @@ -53,10 +55,39 @@ } { 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 $this_object_id .*" + util_memoize_flush_regexp "application_data_link::get_linked_not_cached -from_object_id $target_object_id .*" + util_memoize_flush_regexp "application_data_link::get_linked_content_not_cached -from_object_id $this_object_id .*" + util_memoize_flush_regexp "application_data_link::get_linked_content_not_cached -from_object_id $target_object_id .*" + if { [catch { + db_dml create_forward_link {} + db_dml create_backward_link {} + }]} { + # 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" + } + } } +# 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 +} { + 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 } { @@ -113,6 +144,12 @@ @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 return [db_list linked_object {}] } @@ -127,6 +164,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.4 --- 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 1 Nov 2006 19:22:51 -0000 1.4 @@ -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