xowiki::Package instproc reparent (public)

 <instance of xowiki::Package[i]> reparent [ -item_id item_id ] \
    [ -new_parent_id new_parent_id ] \
    [ -allowed_parent_types allowed_parent_types ]

Defined in packages/xowiki/tcl/package-procs.tcl

Reparent a wiki page from one parent page to another one. The function changes the parent_id in cr_items, updates the cr-child-rels, and clears the caches. The function does not require the item to be instantiated. Limitations: The method does not perform permission checks (whether the actual user has rights to move the page to another parent folder), which should be implemented by the calling methods. Currently, the method does not perform cycle checks. It might be recommended to make sure the target parent is in the same package instance.

Switches:
-item_id
(optional)
item_id of the item to be moved
-new_parent_id
(optional)
item_id of the target parent
-allowed_parent_types
(defaults to "::xowiki::FormPage ::xowiki::Page") (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 xowiki::update_item_index xowiki::update_item_index (public) xowiki::Package instproc reparent xowiki::Package instproc reparent xowiki::Package instproc reparent->xowiki::update_item_index

Testcases:
No testcase defined.
Source code:
set parent_id [::xo::db::CrClass get_parent_id -item_id $item_id]
set name      [::xo::db::CrClass get_name      -item_id $item_id]
if {$new_parent_id == $parent_id} {
  # nothing to do
  return
}

set object_type [::xo::db::CrClass get_object_type -item_id $item_id]
set parent_object_type [::xo::db::CrClass get_object_type -item_id $new_parent_id]
if {$parent_object_type ni $allowed_parent_types} {
  error "parent_object_type $parent_object_type not in allowed types"
}
set relation_tag $parent_object_type-$object_type
::xo::dc transaction {
  ::xo::dc dml update_cr_items {
    update cr_items set parent_id = :new_parent_id where item_id = :item_id
  }
  ::xowiki::update_item_index -item_id $item_id -parent_id $new_parent_id

  ::xo::dc dml update_cr_child_rels {
    update cr_child_rels set parent_id = :new_parent_id, relation_tag = :relation_tag
    where child_id = :item_id
  }
  ::xo::dc dml update_rels_object {
    update acs_objects
    set context_id = :new_parent_id,
    title = :relation_tag || ': ' || :new_parent_id || ' - '  || :item_id
    where object_id = (select rel_id from cr_child_rels
                       where child_id = :item_id)
  }
}
#
# clear caches
#
:flush_references -item_id $item_id -name $name -parent_id $parent_id
:flush_page_fragment_cache -scope agg

::xo::xotcl_object_cache flush $item_id

#
# Clear potentially cached revisions. The function could be
# optimized in the future by an index of the cached revision_ids
# for an item_id
#
foreach revision_id [::xo::dc list get_revisions {
  select revision_id from cr_revisions where item_id = :item_id
}] {
  ::xo::xotcl_object_cache flush $revision_id
}
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: