Index: openacs-4/packages/acs-tcl/tcl/parameter-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/parameter-procs.tcl,v diff -u -r1.26 -r1.27 --- openacs-4/packages/acs-tcl/tcl/parameter-procs.tcl 11 Feb 2019 11:57:34 -0000 1.26 +++ openacs-4/packages/acs-tcl/tcl/parameter-procs.tcl 3 Sep 2024 15:37:34 -0000 1.27 @@ -43,7 +43,17 @@ db_exec_plsql set_parameter_value {} - return [ad_parameter_cache -set $value $package_key $parameter] + # ::acs::dc call apm set_value \ + # -package_key $package_key \ + # -parameter $parameter \ + # -attr_value $value + + acs::clusterwide callback subsite::global_parameter_changed \ + -package_key $package_key \ + -parameter $parameter \ + -value $value + + ad_parameter_cache -delete $package_key $parameter } ad_proc -public parameter::get_global_value { @@ -56,7 +66,7 @@ Get the value of a global package parameter. @param localize should we attempt to localize the parameter - @param boolean insure boolean parameters are normalized to 0 or 1 + @param boolean ensure boolean parameters are normalized to 0 or 1 @param package_key identifies the package to which the global param belongs @param parameter which parameter's value to get @param default what to return if we don't find a value. Defaults to returning the empty string. @@ -70,7 +80,7 @@ # parameters. # 1. use the parameter file - set value [ad_parameter_from_file $parameter $package_key] + set value [ad_parameter_from_configuration_file $parameter $package_key] # 2. check the parameter cache if {$value eq ""} { @@ -92,7 +102,7 @@ # Special parsing for boolean parameters, true and false can be written # in many different ways if { $boolean_p } { - set value [template::util::is_true $value] + set value [string is true -strict $value] } return $value @@ -103,7 +113,7 @@ {-parameter:required} {-value:required} } { - Set the value of a package instance parameter + Set the value of a package instance parameter. @param package_id what package to set the parameter in. Defaults to [ad_conn package_id] @@ -114,9 +124,40 @@ set package_id [ad_requested_object_id] } + # + # We have two different definitions of set_parameter_value/3 with + # differently typed arguments. Polyphorism is not supported + # yet. We should define set_value/4, or mirror the names we have + # here (set_value vs. set_global_value). For the time being, we + # keep the .xql-files for "db_exec_plsql" around, maybe some other + # use cases hint a different approach. + # db_exec_plsql set_parameter_value {} - return [ad_parameter_cache -set $value $package_id $parameter] + #::acs::dc call apm set_value \ + # -package_id $package_id \ + # -parameter_name $parameter \ + # -attr_value $value + + try { + acs::clusterwide callback subsite::parameter_changed \ + -package_id $package_id \ + -parameter $parameter \ + -value $value + } on error {errorMsg} { + # + # Check if error happened during startup. The callbacks might + # not be loaded yet. + # + if {[ns_ictl epoch] == 0} { + ns_log notice "callback subsite::parameter_changed failed during startup: $errorMsg" + } else { + # The error did not happen during startup, so rethrow the + # error. + error $errorMsg $::errorInfo + } + } + ad_parameter_cache -delete $package_id $parameter } ad_proc -public parameter::get { @@ -129,7 +170,7 @@ Get the value of a package instance parameter. @param localize should we attempt to localize the parameter - @param boolean insure boolean parameters are normalized to 0 or 1 + @param boolean ensure boolean parameters are normalized to 0 or 1 @param package_id what package to get the parameter from. Defaults to [ad_conn package_id] @param parameter which parameter's value to get @@ -146,21 +187,12 @@ # 1. check whether there is a parameter by this name specified for # the package in the parameter file. The name - # ad_parameter_from_file is a misnomer, since it checks + # ad_parameter_from_configuration_file is a misnomer, since it checks # ns_config values # if {$package_id ne ""} { - set package_key "" - # This can fail at server startup--OpenACS calls parameter::get to - # get the size of the util_memoize cache so it can setup the cache. - # apm_package_key_from_id needs that cache, but on server start - # when the toolkit tries to get the parameter for the cache size - # the cache doesn't exist yet, so apm_package_key_from_id fails - if {![catch { - set package_key [apm_package_key_from_id $package_id] - }]} { - set value [ad_parameter_from_file $parameter $package_key] - } + set package_key [apm_package_key_from_id $package_id] + set value [ad_parameter_from_configuration_file $parameter $package_key] } # 2. check the parameter cache @@ -177,11 +209,12 @@ # Replace message keys in hash marks with localized texts set value [lang::util::localize $value] } - - # Special parsing for boolean parameters, true and false can be written - # in many different ways + # + # Normalize boolean results if required, since "true" and "false" + # can be written in many different ways. + # if { $boolean_p } { - set value [template::util::is_true $value] + set value [string is true -strict $value] } return $value @@ -206,72 +239,84 @@ -value $value } -ad_proc -public parameter::get_from_package_key { - -localize:boolean - -boolean:boolean - {-package_key:required} - {-parameter:required} - {-default ""} -} { - Gets an instance parameter for the package corresponding to package_key. +if {![db_table_exists apm_parameters]} { - Note that this makes the assumption that the package is a singleton. + ad_proc -public parameter::get_from_package_key { + -localize:boolean + -boolean:boolean + {-package_key:required} + {-parameter:required} + {-default ""} + } { + ns_log notice "parameter::get_from_package_key: called during initialization:" \ + "$package_key.$parameter -> '$default' (default)" + return $default + } - New packages should use global parameters instead. +} else { - @param package_key what package to get the parameter from. We will try - to get the package_id from the package_key. This - may cause an error if there are more than one - instance of this package - @param parameter which parameter's value to get - @param default what to return if we don't find a value -} { - # - # 1. Check to see if this parameter is being set in the server's - # configuration file; this value has highest precedence. - # - set value [ad_parameter_from_file $parameter $package_key] + ad_proc -public parameter::get_from_package_key { + -localize:boolean + -boolean:boolean + {-package_key:required} + {-parameter:required} + {-default ""} + } { + Gets an instance parameter for the package corresponding to package_key. - # - # 2. Try to get the value from a global package parameter. - # - if {$value eq ""} { - set value [parameter::get_global_value \ - -localize=$localize_p \ - -boolean=$boolean_p \ - -package_key $package_key \ - -parameter $parameter \ - -default ""] - } + Note that this makes the assumption that the package is a singleton. - # - # 3. Try to get the value from the package_id of this package_key - # and use the standard parameter::get function to get the - # value. Note that this lookup only makes sense for singleton - # packages. - # - if {$value eq ""} { - if {[db_string check_singleton { - select 1 from apm_package_types - where package_key = :package_key - and singleton_p = 't' - } -default 0]} { - set value [parameter::get \ + New packages should use global parameters instead. + + @param package_key what package to get the parameter from. We will try + to get the package_id from the package_key. This + may cause an error if there are more than one + instance of this package + @param parameter which parameter's value to get + @param default what to return if we don't find a value + } { + # + # 1. Check to see if this parameter is being set in the server's + # configuration file; this value has highest precedence. + # + set value [ad_parameter_from_configuration_file $parameter $package_key] + + # + # 2. Try to get the value from a global package parameter. + # + if {$value eq ""} { + set value [parameter::get_global_value \ -localize=$localize_p \ -boolean=$boolean_p \ - -package_id [apm_package_id_from_key $package_key] \ + -package_key $package_key \ -parameter $parameter \ - -default $default \ - ] - } else { - ns_log notice "tried to lookup parameter $parameter from non-singleton package $package_key" - set value $default + -default ""] } - } - return $value -} + # + # 3. Try to get the value from the package_id of this package_key + # and use the standard parameter::get function to get the + # value. Note that this lookup only makes sense for singleton + # packages. + # + if {$value eq ""} { + if {[apm_package_singleton_p $package_key]} { + set value [parameter::get \ + -localize=$localize_p \ + -boolean=$boolean_p \ + -package_id [apm_package_id_from_key $package_key] \ + -parameter $parameter \ + -default $default \ + ] + } else { + ns_log notice "tried to lookup parameter $parameter from non-singleton package $package_key" + set value $default + } + } + return $value + } +} # Local variables: # mode: tcl # tcl-indent-level: 4