Hey,
I am trying to programmatically update the position and title of an existing page. The idea was to use the ContentService to find and update the pages.
I managed to update the title of an existing page with the following code:
SingleContentFetcher pageFinder = contentService
.find( new Expansion( "ancestors" ), new Expansion( "body" ), new Expansion( "children" ),
new Expansion( "container" ), new Expansion( "descendants" ), new Expansion( "history" ),
new Expansion( "metadata" ), new Expansion( "operations" ), new Expansion( "permissions" ),
new Expansion( "space" ), new Expansion( "status" ), new Expansion( "version" ) )
.withId( ContentId.of( pageID ) );
Content page = pageFinder.fetchOrNull();
ContentBuilder contentBuilder = Content.builder( page );
Version prefVersion = page.getVersion();
VersionBuilder newVersionBuilder = prefVersion.nextBuilder();
contentBuilder.title( title );
contentBuilder.version( newVersionBuilder.build() );
contentBuilder.extension( "position", Position.of( 3 ) );
Content updatedContent = contentBuilder.build();
contentService.update( updatedContent );
However the position attribute of the page is not updated at all and moreover the page gets automatically placed under the homepage as a direct childpage (ignoring the previous position in the page hierarchy).
Would be grateful for any help on this problem!
Best regards,
Fabian Ingenhorst