Automating page template migration and component refactoring in AEM as a Cloud Service

This article explains how to automate one-time content migrations, such as updating page templates and refactoring components, in Adobe Experience Manager as a Cloud Service using supported programmatic approaches.

Description description

Environment

Adobe Experience Manager as a Cloud Service, all versions

Issue/Symptoms

When migrating or refactoring content in Adobe Experience Manager (AEM) as a Cloud Service, you need to update page templates or move components to new locations across many pages. Manual migration is impractical for large content volumes. Traditional tools such as the Groovy Console, used in previous AEM versions, aren’t supported in AEM as a Cloud Service. Instead, implement migration logic as deployable application code using supported APIs and deployment processes.

  • Existing pages require migration to a new template and bulk updates to the component structure.
  • Manual migration isn’t feasible due to the content volume.
  • Previous scripting tools, such as the Groovy Console, aren’t available.

Cause

AEM as a Cloud Service doesn’t support runtime scripting tools or direct repository modifications outside the deployment pipeline. Implement migration logic as application code and deploy it through Cloud Manager.

Resolution resolution

Follow these steps to resolve the issue:

  1. Plan the migration:

    • Identify the pages and components that require migration.
    • Define the required changes, such as updating the page template reference and adding or removing components in page content.
  2. Choose a supported migration approach:

    • Option A: Use Sling Pipes

      • Implement migration logic using the Sling Pipes Java API as an OSGi service.
      • Define pipes to locate pages using the old template, update the cq:template property, and modify components as needed.
      • Execute the migration as a background Sling Job using a dedicated service user with only the required permissions.
      • Optionally, provide a Servlet to enqueue the migration job. Don’t perform migration logic directly in the Servlet.
    • Option B: Develop a custom OSGi migration service or job

      • Create an OSGi service or background job using JCR/Sling APIs to perform the migration steps programmatically.
  3. Test the migration code:

    • Deploy and run the migration in a development environment with a small content subset to validate the behavior.
    • Test the migration in a staging environment with the full content scope.
  4. Execute the migration in production:

    • Deploy the migration code to the production Author environment.
    • Run the migration once to update the required pages and components.
    • Replicate the updated pages to the Publish environment as needed.
  5. Clean up the migration code:

    • Remove the migration code from the codebase after successful execution to prevent unintended future changes.
  6. Verify the migration:

    • Review the migrated pages to ensure the new template and component structure are applied as expected.
recommendation-more-help
experience-cloud-kcs-help-kbarticles