Expand my Community achievements bar.

SOLVED

Version Creation after deployed bundle into package manger AEM6.5

Avatar

Level 2

Greetings to all,
We are using AEM 6.5

I have a requirement on new version creation in AEM Page Version Creation/history, when I deploy a bundle (having some new content/image) in package manager the corresponding page should create a new version, is it possible?

Example
1. I'm not going to manually edit some content on the page when I deploy the bundle in the package manager, can we get the version history.
2. I have a page xyz.html with V1.0,V1.1, when I change some content in the page, then publish it, will get V1.2 comes, this one is expected but our requirement, with some additional content when I install new bundle in package manager, can we get a new version V1.2.

sivav84492733_0-1718205061937.png

sivav84492733_2-1718205138304.png

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @sivav84492733 

 

As @gkalyan mentioned, it is not available OOTB, but you can achieve this through workflows. I will try to outline the steps you can follow to create page versions on package installation - 

  1. Create a new workflow model with "Create Version" step
  2. Add a new workflow launcher with below details
    • Event Type = Created
    • Nodetype = cq:Page
    • Path = <your-content-path>
    • Run Mode = Author
    • Workflow Model = workflow created in step#1
  3. Repeat Step#2 with Event Type = Modified 

 

I highly recommend enabling the Version Purge configuration and retain only certain number of versions to avoid the performance impacts in environments. You can refer to this document for reference - https://experienceleague.adobe.com/en/docs/experience-manager-65/content/implementing/deploying/conf... 

 

Thanks,

Lokesh 

 

View solution in original post

6 Replies

Avatar

Level 8

HIi @sivav84492733 

There is no out-of-the-box way to automatically trigger page versioning when deploying packages with new content.

This requires custom development, involving creating an OSGi service, analyzing package contents to map resources to pages, and invoking the PageManager API to create versions for affected pages when a package is deployed.

Avatar

Correct answer by
Community Advisor

Hi @sivav84492733 

 

As @gkalyan mentioned, it is not available OOTB, but you can achieve this through workflows. I will try to outline the steps you can follow to create page versions on package installation - 

  1. Create a new workflow model with "Create Version" step
  2. Add a new workflow launcher with below details
    • Event Type = Created
    • Nodetype = cq:Page
    • Path = <your-content-path>
    • Run Mode = Author
    • Workflow Model = workflow created in step#1
  3. Repeat Step#2 with Event Type = Modified 

 

I highly recommend enabling the Version Purge configuration and retain only certain number of versions to avoid the performance impacts in environments. You can refer to this document for reference - https://experienceleague.adobe.com/en/docs/experience-manager-65/content/implementing/deploying/conf... 

 

Thanks,

Lokesh 

 

Avatar

Level 10

Hi @sivav84492733 ,

To automatically create a new version of a page in AEM 6.5 when you deploy a bundle via the Package Manager, you will need to implement a custom event handler that listens for package installation events and then triggers the versioning of the relevant pages.

Here’s a step-by-step guide on how you can achieve this:

1. Implement an Event Listener

Create an event listener that listens for package installation events. This listener will then trigger the versioning process for the pages affected by the package deployment.

Example Code for Event Listener

  1. Create an Event Listener in OSGi:

 

package com.example.aem.core.listeners;

import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.event.jobs.consumer.JobConsumer;
import org.apache.sling.event.jobs.consumer.JobConsumer.JobResult;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationEvent;

import javax.jcr.Node;

@Component(
        service = JobConsumer.class,
        property = {
                JobConsumer.PROPERTY_TOPICS + "=" + ReplicationEvent.EVENT_TOPIC
        }
)
public class PackageInstallEventListener implements JobConsumer {

    private static final Logger LOG = LoggerFactory.getLogger(PackageInstallEventListener.class);

    @Reference
    private ResourceResolverFactory resourceResolverFactory;

    @Override
    public JobResult process(Job job) {
        String path = (String) job.getProperty(ReplicationAction.PROPERTY_PATH);

        try (ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(null)) {
            PageManager pageManager = resolver.adaptTo(PageManager.class);
            if (pageManager != null) {
                Page page = pageManager.getPage(path);
                if (page != null) {
                    Node pageNode = page.adaptTo(Node.class);
                    if (pageNode != null) {
                        pageNode.getSession().getWorkspace().getVersionManager().checkpoint(pageNode.getPath());
                        LOG.info("Version created for page: {}", path);
                    }
                }
            }
        } catch (Exception e) {
            LOG.error("Error creating version for page: {}", path, e);
            return JobResult.FAILED;
        }
        return JobResult.OK;
    }
}
​

 

2. Configure the Event Listener

Ensure the event listener is configured to respond to package installation events. This usually involves setting up the appropriate event topics and filters.

3. Ensure Service User Mapping

Make sure that your service user mapping is correctly set up for your bundle to have the necessary permissions to create versions of pages.

Example Configuration for sling.serviceUser.mapping:

In your org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended-serviceUserMapping configuration:

 

{
    "user.mapping": [
        "com.example.aem.core.listeners:your-service-user"
    ]
}

 

4. Deploy and Test

Deploy your bundle and test the functionality:

  1. Install a package via the Package Manager that affects specific pages.
  2. Verify that the event listener is triggered and a new version is created for the affected pages.

 

  • Event Listener: An OSGi event listener that listens for package installation events and triggers the version creation for affected pages.
  • Configuration: Properly configure the listener and service user mapping to ensure the necessary permissions.
  • Testing: Verify the functionality by deploying a package and checking the version history of the affected pages.

This approach ensures that every time a package is deployed that affects specific pages, a new version is automatically created, meeting your requirement for automated versioning without manual intervention.




Avatar

Level 7

Thanks ChatGPT, man you need to stop spamming with these ai, CHATGPT, comments...

Avatar

Community Advisor

Hi @sivav84492733 
Are these images/pages are deployed from maven project with build & deploy and are part of ui.content package?

 



Arun Patidar

Avatar

Administrator

@sivav84492733 Did you find the suggestions from users helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!



Kautuk Sahni