Index: openacs-4/contrib/packages/portal/tcl/datasource-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/portal/tcl/datasource-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/portal/tcl/datasource-procs.tcl 25 Oct 2002 21:29:17 -0000 1.1 +++ openacs-4/contrib/packages/portal/tcl/datasource-procs.tcl 3 Jan 2004 01:42:57 -0000 1.2 @@ -27,6 +27,148 @@ namespace eval portal::datasource { + ad_proc new_from_spec { + -spec:required + } { + + Create a new portal datasource from a specification. Why use this to define + your portal datasources? Because calling this procedure from your package's + post-install procedure is easier than writing PL/SQL for Oracle and PL/pgSQL + for Oracle. + + @param spec The specification (format described below) + + @author Don Baccus (dhogaza@pacifier.com) + @see acs_sc::impl::new_from_spec + + The specification is a list of name-value pairs. Possible names are + + name The name of the new datasource + owner The package that owns this portlet (defaults to name) + description A human-readable description (defaults to name) + params A list of param key/attributes and their values + aliases Service contract aliases clause for acs_sc::impl::new_from_spec + + Each parameter key can be followed by a comma-separated list of attributes + in the familiar style of ad_page_contract or ad_form. Do not include spaces + in the list of attributes. Only two attributes are allowed - "config_required_p" + and "configured_p". + + See the portal package documentation for the meaning of these two attributes. + + } { + + array set datasource $spec + + # Default datasource description to its name + if { ![info exists datasource(description)] } { + set datasource(description) $datasource(name) + } + + # Default datasource owner to its name + if { ![info exists datasource(owner)] } { + set datasource(owner) $datasource(name) + } + + db_transaction { + + set datasource_id [new -name $datasource(name) -description $datasource(description)] + + foreach {param value} $datasource(params) { + + if { ![regexp {^([^ \t:]+)(?::([a-zA-Z0-9_,(|)]*))} \ + $param match param_name flags] } { + ad_return -code error "Parameter name '$param' doesn't have the right format. It must be var\[:flag\[,flag ...\]\]" + } + + # set defaults for attributes + set config_required_p f + set configured_p f + + # now set the parameter flags + foreach flag [split [string tolower $flags] ","] { + switch -exact $flag { + configured { set configured_p t } + config_required { set config_required_p t} + default { ad_return -code error "\"$flag\" is not a legal portal datasource attribute" } + } + } + + # and define the parameter + set_def_param -datasource_id $datasource_id \ + -config_required_p $config_required_p \ + -configured_p $configured_p \ + -key $param_name \ + -value $value + + } + + acs_sc::impl::new_from_spec \ + -spec [list name $datasource(name) \ + contract_name portal_datasource \ + owner $datasource(owner) \ + aliases $datasource(aliases)] + + } + } + + ad_proc -private new { + {-name:required} + {-description:required} + } { + + @author Simon Carstensen (simon@bcuni.net) + + } { + + set var_list [list \ + [list name $name] \ + [list description $description]] + + return [package_exec_plsql -var_list $var_list portal_datasource new] + } + + ad_proc -private set_def_param { + {-datasource_id:required} + {-config_required_p:required} + {-configured_p:required} + {-key:required} + {-value:required} + } { + + @author Simon Carstensen (simon@bcuni.net) + + } { + set var_list [list \ + [list datasource_id $datasource_id] \ + [list config_required_p $config_required_p] \ + [list configured_p $configured_p] \ + [list key $key] \ + [list value $value]] + + package_exec_plsql -var_list $var_list portal_datasource set_def_param + } + + ad_proc -private delete { + {-name:required} + } { + + @author Don Baccus (dhogaza@pacifier.com) + + } { + + if { ![db_0or1row get_datasource_id {}] } { + # Returning an error here is a PITA developing, so we'll just log an error + ns_log Error "Datasource \"$name\" does not exist" + return + } + + acs_sc::impl::delete -contract_name portal_datasource -impl_name $name + set var_list [list [list datasource_id $datasource_id]] + return [package_exec_plsql -var_list $var_list portal_datasource del] + } + + ad_proc -public get { {-datasource_id:required} } {