How to deal with missing properties on nodes from earlier versions | Community
Skip to main content
levif78323183
Level 2
January 26, 2017
Solved

How to deal with missing properties on nodes from earlier versions

  • January 26, 2017
  • 5 replies
  • 2664 views

Hi guys, imagine the following scenario:

I have a custom Template, let's call it my-template. This template is used to create Pages with properties called propA, propB and propC. My Sling scripts under /apps/<...>/components expects the Pages under /content to have those properties.

This is deployed to production environment and everything works fine.

Now, the business needs changes and I need to change my-template. It now has properties propA, propX and propY, where: 

  • propX is the same of former propB, but the previous name doesn't make more sense;
  • propY is a brand new property and,
  • propC was deleted as we don't need it anymore.

Then, my questions are:

  1. How should my Sling scripts deal with the old Pages (the ones with propA, propB and propC) created before the new Template properties where there? 
  2. Should I write my code to deal with both "versions" of Page I might have in the production environment?
  3. Having a relational database background, I would run a update SQL script to fix the old data. But how can I do such a thing with JCR? And more, Am I supposed to do such a thing?
  4. And lastly, how about nodes that are not under /content (e.g. /etc nodes)?

I  hope I could get my idea through. Shall you have any question, please, let me know.

Thank you in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by daniel_henriqu1

Hi.

How about this tool: https://github.com/HS2-SOLUTIONS/hs2-aem-commons/tree/master/on-deploy-scripts-framework?
(I'm not sure if it is suitable for production environments)

Regards,

Daniel.

5 replies

sandeepm744005
Level 5
January 27, 2017

question - how many pages in there which have old properties ? if they are few, you can write a groovy script or java code to update those properties. If those pages are in great number, you still can use the same script but need to be very careful while running it. You can run the script on the chunks to make sure that is works fine, other option is also fine -- put the condition inside the code to make it backward compatible with new properties but it is little weird to check the conditions for non existing properties in new pages.

levif78323183
Level 2
January 27, 2017

Hi, thank you very much for your reply.

Unfortunately my Production environment is controlled by another team and I do not access to run scripts or even fix the Page nodes  by myself.

I can only send them packages to be installed via Package Manager.

I have definitely think about make the code backward compatible, but it doesn't seem to me as a good practice. In the future we might have new updates and then the code complexity could get to a point where it is very high just to keep the backward compatibility.

daniel_henriqu1
daniel_henriqu1Accepted solution
Level 4
May 16, 2017

Hi.

How about this tool: https://github.com/HS2-SOLUTIONS/hs2-aem-commons/tree/master/on-deploy-scripts-framework?
(I'm not sure if it is suitable for production environments)

Regards,

Daniel.

MC_Stuff
Level 10
May 17, 2017
levif78323183
Level 2
May 23, 2017
Hi kautuk, I didn't have the chance to apply any of this approaches as I moved to another project that does not AEM. :( I appreciate all the replies though, and they seems really promising. Let us know your experience if you apply any of them (or even a different approach) Thank you