xo::PackageMgr instproc import_prototype_page (public)
<instance of xo::PackageMgr> import_prototype_page \ [ -package_key package_key ] -name name -parent_id parent_id \ -package_id package_id [ -lang lang ] [ -add_revision on|off ]
Defined in /var/www/openacs.org/packages/xotcl-core/tcl/06-package-procs.tcl
Import a named page from the prototypes folder of the package, i.e. under www/prototypes/*.page of the package.
- Switches:
- -package_key (optional)
- when provided, the package_key used to locate the page. When not provided, use the package_key of the class, on which this function is called.
- -name (required)
- name of the page to be loaded (not including the language prefix)
- -parent_id (required)
- place to where the page should be loaded
- -package_id (required)
- package instance to which the page should be loaded
- -lang (optional, defaults to
"en"
)- -add_revision (optional, boolean, defaults to
"true"
)- When the page to be loaded exists already, add a new revision. When the page exists already, and the flag is not set, no change happens.
- Testcases:
- xowiki_test_cases
Source code: if {![info exists package_key] && [info exists :package_key]} { set package_key ${:package_key} } set page "" set fn [:prototype_page_file_name -name $name -package_key $package_key] #:log "--W check $fn" if {![ad_file readable $fn]} { ns_log notice "no such prototype page $fn" return "" } # # We have the file of the prototype page. We try to create # either a new item or a revision from definition in the file # system. # if {[regexp {^(..):(.*)$} $name _ lang local_name]} { set fullName $name } else { set fullName en:$name } :log "--sourcing page definition $fn, using name '$fullName'" set page [source $fn] $page configure -name $fullName -parent_id $parent_id -package_id $package_id # # xowiki::File has a different interface for build-name to # derive the "name" from a file-name. This is not important for # prototype pages, so we skip it # if {![$page istype ::xowiki::File]} { set nls_language [:get_nls_language_from_lang $lang] $page name [$page build_name -nls_language $nls_language] #:log "--altering name of page $page to '[$page name]'" set fullName [$page name] } if {![$page exists title]} { $page set title $object } $page destroy_on_cleanup $page set_content [string trim [$page text] " \n"] $page initialize_loaded_object xo::Package require $package_id set p [::$package_id get_page_from_name -name $fullName -assume_folder [$page is_folder_page] -parent_id $parent_id] #:log "--get_page_from_name '$fullName' -parent_id $parent_id --> '$p'" if {$p eq ""} { # # We have to create the page new. The page is completed with # missing vars on save_new. # #:log "--save_new of $page class [$page info class]" $page save_new } else { #:log "--save revision $add_revision" if {$add_revision} { # # An old page exists already, create a revision. Update the # existing page with all scalar variables from the prototype # page (which does not have always all instance variables set) # foreach v [$page info vars] { if {[$page array exists $v]} continue ;# don't copy arrays $p set $v [$page set $v] } #:log "--save of $p [$p name] class [$p info class]" $p save } set page $p } if {$page ne ""} { # # We want to be able to address the page after this call via the # canonical name ::$item_id # set page [::xo::db::CrClass get_instance_from_db -item_id [$page item_id]] } return $pageXQL Not present: Generic, PostgreSQL, Oracle