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.
Solved! Go to Solution.
Views
Replies
Total Likes
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 -
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
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.
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 -
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
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:
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.
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;
}
}
Ensure the event listener is configured to respond to package installation events. This usually involves setting up the appropriate event topics and filters.
Make sure that your service user mapping is correctly set up for your bundle to have the necessary permissions to create versions of pages.
In your org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended-serviceUserMapping configuration:
{
"user.mapping": [
"com.example.aem.core.listeners:your-service-user"
]
}
Deploy your bundle and test the functionality:
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.
Views
Replies
Total Likes
Thanks ChatGPT, man you need to stop spamming with these ai, CHATGPT, comments...
Views
Replies
Total Likes
Hi @sivav84492733
Are these images/pages are deployed from maven project with build & deploy and are part of ui.content package?
@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!
Views
Replies
Total Likes
Views
Like
Replies
Views
Likes
Replies