xo::PackageMgr instproc initialize (public)

 <instance of xo::PackageMgr[i]> initialize [ -ad_doc ad_doc ] \
    [ -parameter parameter ] [ -package_id package_id ] [ -url url ] \
    [ -user_id user_id ] [ -actual_query actual_query ] \
    [ -original_url_and_query original_url_and_query ] \
    [ -init_url init_url ] [ -keep_cc keep_cc ] \
    [ -form_parameter form_parameter ] [ -export_vars export_vars ]

Defined in packages/xotcl-core/tcl/06-package-procs.tcl

Create the connection context ::xo::cc and a package object if these are none defined yet. The connection context ::xo::cc and the package object will be destroyed on cleanup, when the global variables are reclaimed. As a side effect this method sets in the calling context the query parameters and package_id as variables, using the "defaults" for default values. init_url false requires the package_id to be specified and a call to Package instproc set_url to complete initialization. keep_cc true means that the original connection context is preserved (i.e. not altered) in case it exists already.

Switches:
-ad_doc
(optional)
-parameter
(optional)
-package_id
(defaults to "0") (optional)
-url
(optional)
-user_id
(defaults to "-1") (optional)
-actual_query
(defaults to " ") (optional)
-original_url_and_query
(optional)
-init_url
(defaults to "true") (optional)
-keep_cc
(defaults to "false") (optional)
-form_parameter
(optional)
-export_vars
(defaults to "true") (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_create_form_with_form_instance create_form_with_form_instance (test xowiki) xo::PackageMgr instproc initialize xo::PackageMgr instproc initialize test_create_form_with_form_instance->xo::PackageMgr instproc initialize test_includelet_childresources includelet_childresources (test xowiki) test_includelet_childresources->xo::PackageMgr instproc initialize test_includelet_toc includelet_toc (test xowiki) test_includelet_toc->xo::PackageMgr instproc initialize test_link_tests link_tests (test xowiki) test_link_tests->xo::PackageMgr instproc initialize test_package_normalize_path package_normalize_path (test xowiki) test_package_normalize_path->xo::PackageMgr instproc initialize acs::root_of_host acs::root_of_host (public) xo::PackageMgr instproc initialize->acs::root_of_host ad_host ad_host (public) xo::PackageMgr instproc initialize->ad_host ad_parse_documentation_string ad_parse_documentation_string xo::PackageMgr instproc initialize->ad_parse_documentation_string api_page_documentation_mode_p api_page_documentation_mode_p (public) xo::PackageMgr instproc initialize->api_page_documentation_mode_p auth::require_login auth::require_login (public) xo::PackageMgr instproc initialize->auth::require_login

Testcases:
package_normalize_path, includelet_toc, includelet_childresources, xowiki_test_cases, link_tests, slot_interactions, path_resolve, create_form_with_form_instance
Source code:
#:msg "--i [self args], URL=$url, init_url=$init_url"

if {[info exists ad_doc] && [api_page_documentation_mode_p]} {
  ad_parse_documentation_string $ad_doc doc_elements
  set doc_elements(query) $parameter
  error [array get doc_elements] "ad_page_contract documentation"
}

if {$url eq "" && $init_url} {
  if {[ns_conn isconnected]} {
    set url [acs::root_of_host [ad_host]][ns_conn url]
  } else {
    #
    # In case, we are not connected and no URL path is provided,
    # we do a best effort job to set the "url" variable to a path
    # belonging to the right package. The is no way to provide
    # here a better approximation. Note that if e.g. a batch job
    # needs a more precise (object_specific) url, this has to be
    # generated on the caller side with [$object_id pretty_link]
    # or similar means.
    #
    set url [lindex [site_node::get_url_from_object_id -object_id $package_id] 0]
    ns_log warning "PackageMgr initialize sets best-effort URL <$url>"
  }
  #:log "--CONN ns_conn url -> $url"
}

#
# Get package_id from url in case it is not known. When the
# package_id is already known, this is a noop.
#
set package_id [ConnectionContext require_package_id_from_url  -package_id $package_id $url]
#
# Require connection context if needed
#
ConnectionContext require  -keep_cc $keep_cc  -package_id $package_id -user_id $user_id  -parameter $parameter -url $url -actual_query $actual_query

if {[info exists original_url_and_query]} {
  ::xo::cc original_url_and_query $original_url_and_query
}

if {[info exists form_parameter]} {
  ::xo::cc array set form_parameter $form_parameter
}

#
# Create package object instance if necessary.
#
if {$keep_cc} {
  :require $package_id
} else {
  :require -url $url $package_id
}

#
# In case the login expired, we can force an early login to
# prevent later login redirects, which can cause problems
# from within catch operations. The package can decide, if
# it want to force a refresh of the login, even if some pages
# might not require the real user_id.
#
#:msg "force [::$package_id force_refresh_login] && #    [::xo::cc set untrusted_user_id] != [::xo::cc user_id]"
if {[::$package_id force_refresh_login]
    && [::xo::cc set untrusted_user_id] != [::xo::cc user_id]} {
  auth::require_login
}

if {$export_vars} {
  ::xo::cc export_vars -level 2
}
return $package_id
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: