Index: openacs-4/packages/xowiki/tcl/import-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/import-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/tcl/import-procs.tcl 25 Apr 2008 17:23:35 -0000 1.1 @@ -0,0 +1,107 @@ +ad_library { + XoWiki - importer + + @creation-date 2008-04-25 + @author Gustaf Neumann + @cvs-id $Id: import-procs.tcl,v 1.1 2008/04/25 17:23:35 gustafn Exp $ +} + + +namespace eval ::xowiki { + + Class Importer -parameter { + {added 0} {replaced 0} {updated 0} + {package_id} {folder_id} {user_id} + } + Importer instproc init {} { + my destroy_on_cleanup + } + Importer instproc report {} { + my instvar added updated replaced + return "$added objects newly inserted, $updated objects updated, $replaced objects replaced
" + } + + Importer instproc import {-object -replace -base_object} { + my instvar package_id folder_id user_id + $object demarshall -parent_id $folder_id -package_id $package_id -creation_user $user_id + set item_id [::xo::db::CrClass lookup -name [$object name] -parent_id [$object parent_id]] + if {$item_id != 0} { + if {$replace} { ;# we delete the original + ::xo::db::CrClass delete -item_id $item_id + set item_id 0 + my incr replaced + } else { + ::xo::db::CrClass get_instance_from_db -item_id $item_id + $item_id copy_content_vars -from_object $object + if {[info exists base_object]} {$item_id set page_template $base_object} + $item_id save -use_given_publish_date [$item_id exists publish_date] + #my msg "$item_id updated: [$object name]" + my incr updated + } + } + if {$item_id == 0} { + if {[info exists base_object]} {$object set page_template $base_object} + set n [$object save_new -use_given_publish_date [$object exists publish_date]] + $object set item_id $n + set item_id $object + #my msg "$object added: [$object name]" + my incr added + } + # + # The method demarshall might set the mapped __category_ids in $object. + # Insert these into the category object map + # + if {[$object exists __category_ids]} { + #my msg "$item_id map_categories [object set __category_ids] // [$item_id item_id]" + $item_id map_categories [$object set __category_ids] + } + } + + Importer instproc import_all {-replace -user_id -objects:required } { + my instvar package_id folder_id + set todo [list] + foreach o $objects { + # page instances have references to page templates, add these first + if {[$o istype ::xowiki::PageInstance]} { + lappend todo $o + continue + } + my log "importing (1st round) $o [$o name] [$o info class]" + my import -object $o -replace $replace + } + + while {[llength $todo] > 0} { + #my log "importing (2nd round) todo=$todo" + set c 0 + set found 0 + foreach o $todo { + set old_template_id [$o set page_template] + set old_template_name [::$old_template_id set name] + if {[lsearch $todo ::$old_template_id] > -1} { + #my msg "*** delay import of $o ($old_template_id not processed yet)" + incr c + continue + } + set template_id [::xo::db::CrClass lookup -name $old_template_name -parent_id $folder_id ] + if {$template_id == 0} { + #my msg "delay import of $o ($old_template_id [$old_template_id set name] missing)" + incr c + continue + } + #my msg "can import $o ($old_template_id [$old_template_id set name] not missing)" + set todo [lreplace $todo $c $c] + set found 1 + break + } + if {$found == 0} { + my log "can't resolve dependencies in $todo" + break + } + my log "importing (2nd round) process $o, todo=$todo" + my import -object $o -replace $replace -base_object $template_id + } + foreach o $objects {$o destroy} + } + + +} \ No newline at end of file Index: openacs-4/packages/xowiki/tcl/includelet-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/includelet-procs.tcl,v diff -u -r1.29 -r1.30 --- openacs-4/packages/xowiki/tcl/includelet-procs.tcl 25 Apr 2008 11:43:05 -0000 1.29 +++ openacs-4/packages/xowiki/tcl/includelet-procs.tcl 25 Apr 2008 17:23:35 -0000 1.30 @@ -506,7 +506,7 @@ lappend trees [list $tree_id $my_tree_name] } - my msg "[llength $trees] == 0 && $tree_name" + #my msg "[llength $trees] == 0 && $tree_name" if {[llength $trees] == 0 && $tree_name ne ""} { # we have nothing left from mapped trees, maybe the tree_names are not mapped; # try to get these @@ -515,7 +515,7 @@ lappend trees [list [lindex [category_tree::get_id $tree_name] 0] $name] } } - my msg "[llength $trees] == 0 && $tree_name" + #my msg "[llength $trees] == 0 && $tree_name" foreach tree $trees { foreach {tree_id my_tree_name ...} $tree {break} if {!$no_tree_name} { Index: openacs-4/packages/xowiki/tcl/package-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/package-procs.tcl,v diff -u -r1.118 -r1.119 --- openacs-4/packages/xowiki/tcl/package-procs.tcl 25 Apr 2008 11:43:05 -0000 1.118 +++ openacs-4/packages/xowiki/tcl/package-procs.tcl 25 Apr 2008 17:23:35 -0000 1.119 @@ -603,103 +603,14 @@ Package ad_instproc import {-user_id -folder_id {-replace 0} -objects} { import the specified pages into the xowiki instance } { - set package_id [my id] if {![info exists folder_id]} {set folder_id [my folder_id]} if {![info exists user_id]} {set user_id [::xo::cc user_id]} if {![info exists objects]} {set objects [::xowiki::Page allinstances]} set msg "processing objects: $objects
" - set added 0 - set replaced 0 - set updated 0 - set todo [list] - - foreach o $objects { - - # page instances have references to page templates, add these first - if {[$o istype ::xowiki::PageInstance]} { - lappend todo $o - continue - } - my log "importing (1st round) $o [$o name] [$o info class]" - - $o demarshall -parent_id $folder_id -package_id $package_id -creation_user $user_id - - set item_id [::xo::db::CrClass lookup -name [$o set name] -parent_id $folder_id] - if {$item_id != 0} { - if {$replace} { ;# we delete the original - ::xo::db::CrClass delete -item_id $item_id - set item_id 0 - incr replaced - } else { - ::xo::db::CrClass get_instance_from_db -item_id $item_id - $item_id copy_content_vars -from_object $o - $item_id save -use_given_publish_date [$item_id exists publish_date] - incr updated - } - } - if {$item_id == 0} { - set n [$o save_new -use_given_publish_date [$o exists publish_date]] - $o set item_id $n - incr added - } - } - - while {[llength $todo] > 0} { - my log "importing (2nd round) todo=$todo" - set c 0 - set found 0 - foreach o $todo { - $o demarshall -parent_id $folder_id -package_id $package_id -creation_user $user_id - set old_template_id [$o set page_template] - set template_id [::xo::db::CrClass lookup \ - -name [::$old_template_id set name] \ - -parent_id $folder_id ] - if {$template_id == 0} { - my log "importing (2nd round) delay import of $o" - incr c - } else { - set todo [lreplace $todo $c $c] - set found 1 - break - } - } - if {$found == 0} { - my log "can't resolve dependencies in $todo" - break - } - my log "importing (2nd round) process $o, todo=$todo" - db_transaction { - set item_id [::xo::db::CrClass lookup -name [$o set name] -parent_id $folder_id] - if {$item_id != 0} { - if {$replace} { ;# we delete the original - ::xo::db::CrClass delete -item_id $item_id - set item_id 0 - incr replaced - } else { - ::xo::db::CrClass get_instance_from_db -item_id $item_id - $item_id copy_content_vars -from_object $o - $item_id set page_template $template_id - $item_id save -use_given_publish_date [$item_id exists publish_date] - incr updated - } - } - if {$item_id == 0} { ;# the item does not exist -> update reference and save - $o set page_template $template_id - set n [$o save_new -use_given_publish_date [$o exists publish_date]] - $o set item_id $n - incr added - } - } - } - foreach o $objects { - if {[$o exists __category_ids]} { - my msg "$o map_categories [$o set __category_ids] // [$o item_id]" - $o map_categories [$o set __category_ids] - } - $o destroy - } - append msg "$added objects newly inserted, $updated objects updated, $replaced objects replaced
" + set importer [Importer new -package_id [my id] -folder_id $folder_id -user_id $user_id] + $importer import_all -replace $replace -objects $objects + append msg [$importer report] } # @@ -969,6 +880,9 @@ } } + + + # # policy management # Index: openacs-4/packages/xowiki/tcl/xowiki-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-procs.tcl,v diff -u -r1.237 -r1.238 --- openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 25 Apr 2008 11:43:05 -0000 1.237 +++ openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 25 Apr 2008 17:23:35 -0000 1.238 @@ -265,7 +265,7 @@ my log "cmd=$cmd" } Page instproc category_export_referenced_categories {form_fields} { - my log "--ff=$form_fields" + #my log "--ff=$form_fields" foreach f $form_fields { if {[$f exists category_tree]} { set tree_key ::__xowiki_exported_category_tree([$f category_tree]) @@ -278,7 +278,7 @@ } } Page instproc category_import {-name -description -locale -categories} { - my msg "catetegoy_import [self args]" + #my msg "catetegoy_import [self args]" # ignore locale in get_id for now, since it seems broken set tree_id [category_tree::get_id $name] set tree_id [lindex $tree_id 0]; # handle multiple trees with same name @@ -346,6 +346,11 @@ my set creation_user $creation_user # if we import from an old database without page_order, take care about this if {![my exists page_order]} {my set page_order ""} + # handle category import + if {[my exists __category_command]} { + eval [my set __category_command] + #my log "reverse map: [array get ::__xowiki_reverse_category_map]" + } # in the general case, no more actions required } @@ -373,27 +378,17 @@ if {![my exists anon_instances]} { my set anon_instances "t" } - # handle category import - if {[my exists __category_command]} { - eval [my set __category_command] - my log "reverse map: [array get ::__xowiki_reverse_category_map]" - } next } FormPage instproc demarshall {args} { my instvar page_template # - # handle category import - if {[my exists __category_command]} { - eval [my set __category_command] - #my msg "reverse map: [array get ::__xowiki_reverse_category_map]" - } # # FormPages must be demarshalled after Form, since Form builds # the reverse category map. # set category_ids [list] - #my msg "reverse map ?[info exists ::__xowiki_reverse_category_map] [my name] [$page_template exists __category_use]" + if {[info exists ::__xowiki_reverse_category_map] && [$page_template exists __category_use] } { @@ -406,11 +401,11 @@ foreach {name value} [my instance_attributes] { #my msg "use($name) --> [info exists use($name)]" if {[info exists use($name)]} { + #my msg "try to map value '$value' (category tree: $use($name))" if {[info exists ::__xowiki_reverse_category_map($value)]} { - my msg "map value '$value' (category tree: $use($name)) of [my name] to an ID" + #my msg "map value '$value' (category tree: $use($name)) of [my name] to an ID" lappend ia $name $::__xowiki_reverse_category_map($value) lappend category_ids $::__xowiki_reverse_category_map($value) - my msg category_ids=$category_ids } elseif {$value eq ""} { lappend ia $name "" } else {