Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do we move correctly pages using ScriptRunner PageManager and movePageAsChild?

Aleksey Dzyapko September 22, 2021

When I move a page I get an error in the log file:

2021-09-22 18:42:29,536 ERROR [http-nio-8090-exec-5] [comalatech.confluence.workflow.DefaultWorkflowActionManager] executeAction Error Processing Workflow Trigger action page: page: new page v.1 (4816912) trigger action: {send-email:user=@Editor in Chief@|subject=Page ready for final approval}
The page @page@ has been approved by [~@user@] and is waiting for your final approval.
{pageactivity}
{send-email} Error Message: h4. Exception ( 391 lines)
{code}
java.lang.NullPointerException: null
at com.comalatech.confluence.workflow.macros.actions.SendEmailMacro.execute(SendEmailMacro.java:107)
at com.atlassian.renderer.v2.macro.ResourceAwareMacroDecorator.execute(ResourceAwareMacroDecorator.java:51)
at com.atlassian.renderer.v2.components.MacroRendererComponent.executeMacro(MacroRendererComponent.java:192)
at com.atlassian.renderer.v2.components.MacroRendererComponent.processMacro(MacroRendererComponent.java:156)
at com.atlassian.renderer.v2.components.MacroRendererComponent.makeMacro(MacroRendererComponent.java:59)
at com.atlassian.renderer.v2.components.WikiContentRendererHandler.handleMacro(WikiContentRendererHandler.java:18)
at com.atlassian.renderer.v2.WikiMarkupParser.makeMacro(WikiMarkupParser.java:120)
at com.atlassian.renderer.v2.WikiMarkupParser.handlePotentialMacro(WikiMarkupParser.java:100)
at com.atlassian.renderer.v2.WikiMarkupParser.parse(WikiMarkupParser.java:60)
at com.atlassian.renderer.v2.components.MacroRendererComponent.render(MacroRendererComponent.java:43)
at com.atlassian.renderer.v2.V2Renderer.render(V2Renderer.java:53)
at com.atlassian.renderer.v2.plugin.PluggableV2Renderer.render(PluggableV2Renderer.java:30)
at com.atlassian.renderer.v2.V2RendererFacade.convertWikiToXHtml(V2RendererFacade.java:57)
at jdk.internal.reflect.GeneratedMethodAccessor1787.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at com.atlassian.spring.interceptors.SpringProfilingInterceptor.invoke(SpringProfilingInterceptor.java:16)
{code}
PageManager pageManager = getComponent(PageManager)
pageManager.movePageAsChild(childPage, newParentPage)

When I do the same using UI interface of confluence I don't get any errors.
I tried to add one more line after parent was changed:

pageManager.refreshPage(childPage)

 but without any luck.

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Aleksey Dzyapko September 23, 2021

Maybe someone finds it useful. 

import com.atlassian.confluence.core.DefaultSaveContext
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager

import static com.atlassian.sal.api.component.ComponentLocator.getComponent

PageManager pageManager = getComponent(PageManager)

Page childPage = pageManager.getPage(5275745L)
Page newParentPage = pageManager.getPage(4816980L)
Page previousParentPage = childPage.parent

// update list of previousParentPage children
List<Page> updatedListChildren = previousParentPage.children
updatedListChildren.remove(childPage)
previousParentPage.setChildren(updatedListChildren)

// update list of previousParentPage ids
List<Long> updatedListIds = updatedListChildren.collect { page -> page.id }
pageManager.setChildPageOrder(previousParentPage, updatedListIds)

// update list of newParentPage children
childPage.setParentPage(newParentPage)
List<Page> children = newParentPage.children
children.add(childPage)
newParentPage.setChildren(children)

// update list of newParentPage ids
List<Long> childIds = children.collect { page -> page.id }
pageManager.setChildPageOrder(newParentPage, childIds)

// save content and refresh page
pageManager.saveContentEntity(childPage, new DefaultSaveContext(true, true, true))
pageManager.saveContentEntity(newParentPage, new DefaultSaveContext(true, true, true))
pageManager.saveContentEntity(previousParentPage, new DefaultSaveContext(true, true, true))
pageManager.refreshPage(childPage)
pageManager.refreshContentEntity(childPage)
TAGS
AUG Leaders

Atlassian Community Events