| |
43 |
43 |
|
| |
44 |
44 |
ad_proc -public mount { |
| |
45 |
45 |
{-node_id:required} |
| |
46 |
46 |
{-object_id:required} |
| |
47 |
47 |
} { |
| |
48 |
48 |
mount object at site node |
| |
49 |
49 |
} { |
| |
50 |
50 |
db_dml mount_object {} |
| |
51 |
51 |
update_cache -node_id $node_id |
| |
52 |
52 |
|
| |
53 |
53 |
apm_invoke_callback_proc -package_key [apm_package_key_from_id $object_id] -type "after-mount" -arg_list [list node_id $node_id package_id $object_id] |
| |
54 |
54 |
} |
| |
55 |
55 |
|
| |
56 |
56 |
ad_proc -public instantiate_and_mount { |
| |
57 |
57 |
{-node_id ""} |
| |
58 |
58 |
{-parent_node_id ""} |
| |
59 |
59 |
{-node_name ""} |
| |
60 |
60 |
{-package_name ""} |
| |
61 |
61 |
{-context_id ""} |
| |
62 |
62 |
{-package_key:required} |
| |
|
63 |
{-package_id ""} |
| |
63 |
64 |
} { |
| |
64 |
65 |
Instantiate and mount a package of given type. If the package is a singleton (should only have one instance) |
| |
65 |
66 |
and an instance already exists then this proc will attempt to mount that instance. |
| |
66 |
67 |
|
| |
67 |
68 |
@param node_id The id of the node in the site map where the package should be mounted. |
| |
68 |
69 |
If not specified a new node under the main site will be created. |
| |
69 |
70 |
@param parent_node_id If no node_id is specified this will be the parent node under which the |
| |
70 |
71 |
new node is created. Defaults to the main site node id. |
| |
71 |
72 |
@param node_name If node_id is not specified then this will be the name of the |
| |
72 |
73 |
new site node that is created. Defaults to package_key. |
| |
73 |
74 |
@param package_name The name of the new package instance. Defaults to pretty name of package type. |
| |
74 |
75 |
@param context_id The context_id of the package. Defaults to the package_id at the parent |
| |
75 |
76 |
node in the site map. If there is no such package then context_id will be the |
| |
76 |
77 |
id of the parent node itself. |
| |
77 |
78 |
@param package_key The key of the package type to instantiate. |
| |
|
79 |
@param package_id The id of the new package. Optional. |
| |
78 |
80 |
|
| |
79 |
81 |
@return The id of the instantiated package |
| |
80 |
82 |
|
| |
81 |
83 |
@author Peter Marklund |
| |
82 |
84 |
} { |
| |
83 |
85 |
# Create a new node if none was provided |
| |
84 |
86 |
if { [empty_string_p $node_id] } { |
| |
85 |
87 |
if { [empty_string_p $parent_node_id ] } { |
| |
86 |
88 |
set parent_node_id [site_node::get_node_id -url "/"] |
| |
87 |
89 |
} |
| |
88 |
90 |
|
| |
89 |
91 |
# Default node_name to package_key |
| |
90 |
92 |
set node_name [ad_decode $node_name "" $package_key $node_name] |
| |
91 |
93 |
|
| |
92 |
94 |
set node_id [site_node::new -name $node_name -parent_id $parent_node_id] |
| |
93 |
95 |
} |
| |
94 |
96 |
|
| |
95 |
97 |
# Get the context_id of the new package |
| |
96 |
98 |
if {[empty_string_p $context_id]} { |
| |
97 |
99 |
# Attempt to use the package_id at the parent node |
| |
98 |
100 |
if { [empty_string_p $parent_node_id] } { |
| |
99 |
101 |
set parent_node_id [site_node::get_parent_id -node_id $node_id] |
| |
100 |
102 |
} |
| |
101 |
103 |
array set node [site_node::get -node_id $parent_node_id] |
| |
102 |
104 |
set context_id $node(object_id) |
| |
103 |
105 |
|
| |
104 |
106 |
if {[empty_string_p $context_id]} { |
| |
105 |
107 |
# No package at parent node, so use the id of the node itself instead |
| |
106 |
108 |
# Should we use default_context here instead? |
| |
107 |
109 |
set context_id $parent_node_id |
| |
108 |
110 |
} |
| |
109 |
111 |
} |
| |
110 |
112 |
|
| |
111 |
113 |
# Instantiate the package |
| |
112 |
114 |
set package_id [apm_package_instance_new -instance_name $package_name \ |
| |
113 |
115 |
-context_id $context_id \ |
| |
114 |
|
-package_key $package_key] |
| |
|
116 |
-package_key $package_key \ |
| |
|
117 |
-package_id $package_id] |
| |
115 |
118 |
|
| |
116 |
119 |
# Mount the package |
| |
117 |
120 |
site_node::mount -node_id $node_id -object_id $package_id |
| |
118 |
121 |
|
| |
119 |
122 |
return $package_id |
| |
120 |
123 |
} |
| |
121 |
124 |
|
| |
122 |
125 |
ad_proc -public unmount { |
| |
123 |
126 |
{-node_id:required} |
| |
124 |
127 |
} { |
| |
125 |
128 |
unmount an object from the site node |
| |
126 |
129 |
} { |
| |
127 |
130 |
set package_id [get_object_id -node_id $node_id] |
| |
128 |
131 |
apm_invoke_callback_proc -package_key [apm_package_key_from_id $package_id] -type before-unmount -arg_list [list package_id $package_id node_id $node_id] |
| |
129 |
132 |
|
| |
130 |
133 |
db_dml unmount_object {} |
| |
131 |
134 |
update_cache -node_id $node_id |
| |
132 |
135 |
} |
| |
133 |
136 |
|
| |
134 |
137 |
ad_proc -private init_cache {} { |