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.57 -r1.58
--- openacs-4/packages/xowiki/tcl/package-procs.tcl	1 Jun 2007 11:47:12 -0000	1.57
+++ openacs-4/packages/xowiki/tcl/package-procs.tcl	5 Jun 2007 11:29:39 -0000	1.58
@@ -580,6 +580,10 @@
 
     foreach o $objects {
       if {[$o istype ::xowiki::PageInstance]} {
+	set old_template_id [$o set page_template]
+	set template_id [CrItem lookup \
+			  -name [::$old_template_id set name] \
+			  -parent_id $folder_id]
         db_transaction {
           set item_id [CrItem lookup -name [$o set name] -parent_id $folder_id]
           if {$item_id != 0} {
@@ -589,17 +593,14 @@
 	      incr replaced
 	    } else {
 	      ::Generic::CrItem instantiate -item_id $item_id
-              $item_id copy_content_vars -from_object $o
+	      $item_id copy_content_vars -from_object $o
+              $item_id set page_template $template_id
 	      $item_id save
 	      incr updated
 	    }
 	  }
 	  if {$item_id == 0} {  ;# the item does not exist -> update reference and save
-            set old_template_id [$o set page_template]
-            set template [CrItem lookup \
-                              -name [::$old_template_id set name] \
-                              -parent_id $folder_id]
-            $o set page_template $template
+	    $o set page_template $template_id
             $o save_new
             incr added
           }