What is the good way to update a page with JAVA API?

Hello,

I made a script to create and update automatically some pages, and I have an history bug anyway :
When I click on the modification date, I have the following error like “Impossible to find versions of this page”.

I don’t understand it, because I set a version when I create the page, then I increment the version every time I update it, so there is always a version number linked to the page version.

static def updateBodyPage(Space space,Page pageToUpdate, String body, boolean addParentLabel,boolean disableLabel){

    if (body != '') {
        def bodyContent = new BodyContent(pageToUpdate, body, BodyType.XHTML)
        pageToUpdate.setBodyContent(bodyContent)
    }

    pageToUpdate.setVersion(pageToUpdate.getVersion()+1)
    pageToUpdate.setCreator(AuthenticatedUserThreadLocal.get())
    pageToUpdate.setCreationDate(new Date(System.currentTimeMillis()))

    if(!disableLabel){
        if(addParentLabel){
            List<Label> labelsParents=pageToUpdate.getParent().getLabels()
            for(Label lab:labelsParents){
                labelManager.addLabel(pageToUpdate,lab)
            }
        }
    }


    pageManager.saveContentEntity(pageToUpdate, DefaultSaveContext.MINOR_EDIT)
    if (!pageManager.getPage(space.getKey(), pageToUpdate.getTitle())) {
        throw new IllegalStateException("Unable to create a report ${pageToUpdate.getTitle()}")
    } else {
        logger.info("The report ${pageToUpdate.getTitle()} is created")
    }

}

Can you help me here ?

Have a nice day

1 Like