Hi,
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. Suppose i did some changes in Dev env at a page abc.html and page have versions up to V1,V2 and V3 then made a package through package manager(versionupgrade.zip) then i deployed into other env once i deployed into package manager i want to get the new version with updated content, which i have deployed the content from lower env..
Views
Replies
Total Likes
HIi @siva_vjwd
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.
Hi @siva_vjwd
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
@gkalyan Can you give me step by step process through WF
Views
Replies
Total Likes
Hi @siva_vjwd ,
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 @siva_vjwd
Are these images/pages are deployed from maven project with build & deploy and are part of ui.content package?
No, we are code deploying, not from maven project.
Views
Replies
Total Likes
@siva_vjwd 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
Likes
Replies
Views
Likes
Replies