We have a space which contains over 900 archived documents. For better organization, we decided to move them to sub-spaces by year and/or city. I’ll spare the business logic here.
So basically, there is a space space1.space2.space3
which includes all sorts of documents. Depending on attached xObjects and info there, it might be moved to space1.space2.${city}.space3
, space1.space2.space3.${year}
or space1.space2.${city}.space3.${year}
.
I have tried different approaches, splitting the spaces with split('\.')
or using .documentReference.getSpaceReferences()
to manipulate the spaces. Sadly none really gave me the desired result. I may add, the issue has always been with special characters like .
and :
which will be escaped in the string representation.
What I really would like is a way to convert a space into an array of strings, then manipulate that and create a space-reference from that string array.
#set($data = $services.query.xwql("some query")execute())
#foreach ($page in $data)
#set($currentDoc = $xwiki.getDocument($page)) ## or maybe use `$services.model.resolveDocument`?
#set($spacesList = $someMethodToSplitTheSpacesIntoArrays($currentDoc)) ## This should now be ['space1', 'space2', 'space3']
#set($theYear = $datetool.getYear($currentDoc.getValue('theDate')))
#set($theCity = $datetool.getYear($currentDoc.getValue('theCity')))
#if ($condition1)
#set ($ignore = $spacesList.add("${theYear}-Something"))
#end
#if ($condition2)
#set ($ignore = $spacesList.add(2, "${theCity}"))
#end
#set ($newSpace = SomeSerializerMethod($spacesList))
#set ($destination = $services.model.createSpaceReference($currentDoc.getName(), $newSpace))
#set ($res = $services.refactoring.move($source, $destination).join())
#end
Obviously, someMethodToSplitTheSpacesIntoArrays
and SomeSerializerMethod
don’t exists, but I’m having trouble writing them in a reliable way. As mentioned above, whenever there is a .
or :
, it doesn’t behave as expected.
I could reproduce the behaviour quite reliably with manually creating a page named Some page 1. and : for example
.
I have tried the operational wiki with 16.4.6 and in a local docker image with 17.1.0 - same result.
Can anyone help?