Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-22864

$services.refactoring.move - not deleting original

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Major
    • None
    • 16.4.6, 16.10.2
    • Velocity
    • None
    • Tested on organisation instance with 16.4.6 and on docker-image with 16.10.2
    • Unknown

    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.

      Attachments

        Activity

          People

            tmortagne Thomas Mortagne
            Ramzi Ramzi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: