Highlighted

PageManager move() Issue

avinasht6348431

05-02-2019

Hi All,

when i try to move pages from one location to another , page gets moved and finally page name changes to 1,2,3....

I need to maintain the same names for the pages.How it can be done?

Using pagemanager api for this.

pmgr.move(page, dest,null, false, true, null, null);

Also need to understand use of "beforeName" and "publishrefs[]" in this move().

kindly help with the info.

-Avinash

Replies

Highlighted

smacdonald2008

06-02-2019

I was able to move a page and it returned the page title as per expectations.

MovePage.png

The code is similar to the above code - but page service has this Move code:

package com.aem.community.core;

import org.apache.sling.settings.SlingSettingsService;

import org.osgi.service.component.annotations.Activate;

import org.osgi.service.component.annotations.Component;

import org.osgi.service.component.annotations.ConfigurationPolicy;

import org.osgi.service.component.annotations.Reference;

import org.osgi.service.metatype.annotations.Designate;

import java.util.HashMap;

import java.util.Map;

 

import javax.jcr.Node;

import javax.jcr.Session;

 

import org.apache.jackrabbit.commons.JcrUtils;

import org.apache.sling.api.resource.LoginException;

import org.apache.sling.api.resource.ResourceResolver;

import org.apache.sling.api.resource.ResourceResolverFactory;

 

import com.adobe.cq.sightly.WCMUsePojo;

import com.day.cq.commons.jcr.JcrConstants;

import com.day.cq.wcm.api.Page;

import com.day.cq.wcm.api.PageManager;

import org.apache.sling.api.resource.Resource;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

@Component

public class PageServiceImp implements PageService {

    

private final Logger logger = LoggerFactory.getLogger(getClass());

private String user = "";

    

    private Session session;

    

    //Inject a Sling ResourceResolverFactory

    @Reference

    private ResourceResolverFactory resolverFactory;

    

    

    public String MovePage()

    {

    String pagePath = "/content/MovePage64/fr";

    String newPagePath ="/content/MovePage64/en" ;

    String templatePath = "/apps/AEMPage/templates/page-home";

    String pageTitle = "AEM home page";

    Page newPage;

    PageManager pageManager;

    

    

    ResourceResolver resolver = null;

   

   

     String newPageName = "";  

    try {

                 

       

        //Invoke the adaptTo method to create a Session

        resolver = resolverFactory.getAdministrativeResourceResolver(null);

       

       

        Resource res = resolver.getResource(pagePath);   

       

        //Adapts the resource to another type - in this example to a     com.day.cq.wcm.api.page

         Page page = res.adaptTo(Page.class);

    

        

       // session = resolver.adaptTo(Session.class);

                

        //create a page manager instance

        pageManager = resolver.adaptTo(PageManager.class);

        

        //Move a given page and return the new page- 

        /*

         *

Page move(Page page,

   String destination,

   String beforeName,

  boolean shallow,

  boolean resolveConflict,

   String[] adjustRefs)

  throws WCMException

         */

      

//move the page using the API

newPage = pageManager.move(page,newPagePath,null,true,true,null);

       

        if (newPage != null) {

        newPageName= newPage.getPageTitle();

        logger.info("*** PAGE NAME IS "+newPageName);

            }

        else

        {

        logger.info("*** PAGE CANNOT BE MOVED -- ERROR");

        }

        

        return newPageName;

    } catch (Exception e) {

        // TODO Auto-generated catch block

        logger.info("&&&&& BIG ERROR" +e.getMessage());

    }

    

    return ""  ;

}

}

You can look at the parameters of the MOVE method in the Javadocs -- "The Adobe AEM Quickstart and Web Application."  (LOOK AT PAGE MANAGER)

Highlighted

bsloki

MVP

06-02-2019

Hi Avinash,

move method in pagemanager API should work without any issues.

Are you moving the same page to the same location multiple times? If so, it would create a node with 0,1,2.. etc.

Highlighted

knitshweta

05-08-2020

Properties as cq:lastReplicated, cq:lastReplicatedBy, cq:lastReplicationAction are not being copied while moving pages. Did someone encounter that?