Expand my Community achievements bar.

SOLVED

Regarding Moving page in AEM 6.5

Avatar

Employee

Hello there I am trying to move page to achieve after a certain period of time I had created scheduler for that but  I am not able to move pages also i tried with workspace and session.move method to move the pages but it is not working kindly help!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
7 Replies

Avatar

Employee Advisor

You should use the PageManager API for this task, see [1].

 

It could look like this:

Page pageToMove = ...
String targetPath = ...
String[] references = ...
PageManager = pageToMove.adaptTo(PageManager.class);
PageManager.move (pageToMove.adaptTo(Resource.class),  targetPath, false, true, references);

You should not use the lowlevel of Sling and JCR for that task, because they cannot handle aspects like the MSM and many other specialities.

Another important aspect I left out is the question if references to this page must be adjusted, too. To help you in that task, please consult [2].

 

 

 

 

[1] https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/index.html?com/day/cq...

[2] https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/wcm/common...

Avatar

Employee

@Jörg_Hoh Hi there in continuation with the previous query i tried the same this still i am getting the error

This is my crxde Hierarchy

|-Articles
        |-jcr.content
        |-Article-1
        |      |-root
        |      |-container
        |      |-responsivegrid
        |                    |-rtetext
        |                    |-bannerarticle
        |-Article-2
...

This is my QueryBuilder Output

-------------------------------------------

/content/.../Articles/Article-3, (crxde, html, json)
/content/.../Articles/Article-5, (crxde, html, json)
/content/.../Articles/Article-2, (crxde, html, json)
/content/.../Articles/Article-4, (crxde, html, json)
/content/.../Articles/Article-1, (crxde, html, json)

Here is my code

---------------------------------------------

               
                Page pageToMove = hit.getResource().adaptTo(Page.class);
                String pagename= pageToMove.getPath().substring(pageToMove.getPath().lastIndexOf("/"));
                String targetPath = "/content/.../Articles/Archived"+pagename;
                String[] references = {"jcr:content", "jcr:content/root"};
                pageManager = pageToMove.adaptTo(PageManager.class);
                pageManager.move (pageToMove,  targetPath, pagename , false, true, references);
And the output for the same is
---------------------------------------------
2022-10-03 23:27:00.010 ERROR [com.aem.core.schedulers.ArticleArchive] Page to move is ====> /content/.../Articles/Article-5
2022-10-03 23:27:00.010 ERROR [com.aem.core.schedulers.ArticleArchive] Target path is ====> /content/.../Articles/Archived/Article-5 //There is no page like Article-5 i have embed that in code because i had read somewhere that we need to mention the name of file in targetpath
2022-10-03 23:27:00.010 INFO [com.aem.core.schedulers.ArticleArchive] Exception in Schedular====> java.lang.NullPointerException
Please Help!

Avatar

Community Advisor

You must have the path created till/content/.../Articles/Archived and trying to remove page name from target path. e.g.

 String targetPath = "/content/.../Articles/Archived



Arun Patidar

Avatar

Employee

@arunpatidar Done! Still getting java.lang.NullPointerException... is there any other modification needed?

Avatar

Level 5

I think you are not passing the right paths in the 'references' parameter.

You can also use acs common's MCP Renovator

 

Avatar

Employee

@poojac35931336 Hi Pooja I tried to include page path as well but that is also not working for me.

Avatar

Correct answer by
Community Advisor