This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-44643c24-ab95-4b1e-aff6-04701c7e5013 XWIKI-22864 Open

$services.refactoring.move - not deleting original

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-71e4fe5e-c138-4b29-bd04-dd30d71c1a6e Ramzi created this issue on 07/Feb/25 14:36
 
Summary: $services.refactoring.move - not deleting original
Issue Type: cid:jira-generated-image-avatar-44643c24-ab95-4b1e-aff6-04701c7e5013 Bug
Affects Versions: 16.10.2, 16.4.6
Assignee: Unassigned
Components: Velocity
Created: 07/Feb/25 14:36
Environment: Tested on organisation instance with 16.4.6 and on docker-image with 16.10.2
Priority: cid:jira-generated-image-static-major-3b41dd99-fc1c-462e-bec3-196255b6b19b Major
Reporter: Ramzi
Description:

The method `$services.refactoring.move` seems to have a bug, that the old page is not deleted. Adding a `$services.refactoring.delete` solves the problem.

Assuming the following tree:

  Ramzi
  |-+ meinTest3
    |-- My new title

The following code:

#set($source = $services.model.resolveDocument('Ramzi.meinTest3.sub-site'))
#set ($destination = $services.model.resolveSpace('Ramzi.meinTest3.submenu'))
$services.refactoring.move($source, $destination).join()

will produce the following tree:

  Ramzi
  |-+ meinTest3
    |-- sub-site   ## This should not be anymore
    |-+ submenu
      |-- My new title

The 'old' page (Ramzi.meinTest3.sub-site) has a redirect to the 'new' page (Ramzi.meinTest3.submenu.sub-site).

 

A reproducable snippet (before running, create the page 'Ramzi.meinTest3.sub-site' or set '$resetWorkingEnv' to true):

{{velocity}}
## This should be saved in Ramzi.meinTest3.WebHome
 #* -=-=-=-=-=-=-=-=-=- optional setup -=-=-=-=-=-=-=-=-=- *#
#set ($resetWorkingEnv = false)

#macro(createNewPage)
  #set($myDoc = $xwiki.getDocument("Ramzi.meinTest3.sub-site"))
  $myDoc.setTitle("My new title")
  $myDoc.setContent("My cool content...")
  $myDoc.save()
#end
#macro(deletePages $space)
  #set($query = "where doc.space like '$space' and doc.name <> 'WebHome'")
  #set($data = $services.query.xwql($query).execute())
  $data.size() to be deleted.
  #foreach ($page in $data)
    #set($currDoc = $xwiki.getDocument($page))
    $currDoc.delete()
  #end
#end

#if ($resetWorkingEnv)
  ## start from clean state
  #deletePages('Ramzi.meinTest3%')
  #createNewPage()
#end

#* -=-=-=-=-=-=-=-=-=- Here the actual code starts -=-=-=-=-=-=-=-=-=- *#
#set($source = $services.model.resolveDocument('Ramzi.meinTest3.sub-site'))
#set ($destination = $services.model.resolveSpace('Ramzi.meinTest3.submenu'))
$services.refactoring.move($source, $destination).join()
##$services.refactoring.delete($source).join()  ## This causes the wanted behaviour.

{{/velocity}}

 

The redirect could be desired behaviour, but keeping the 'old' page in the nav-view is not expected behaviour from a move-method.

Thanks for any input.