Sitecore tips and tricks and community news !

Post Top Ad

Post Top Ad

Thursday, April 20, 2017

11:40 AM

Redirects 2/2

Hi !

It took a few days to continue the topic, but now is good time to do it :)

In part one we have created list of redirects and singleton factory provide list of redirects in Redirect Handler. But thing which hasn't been mentioned is - How to refresh list of redirects in our factory ?

1. Redirects list synchronization 

If you are thinking now like:

"What are you talking about Robert? We have a list of redirects and what special is there?" 

Please notice one thing - That list is derived from singleton factory and if we want to refresh this list, we have to take care of it by ourselves.

To achieve that we need to create Redirect Synchronization  Handler which will be responsible for refreshing our redirect lists.

So now, we have some information how to sync our list. Cool, question is, where we should to invoke this ?

2. Invoke sync action

This is the point that we are really close to finish our functionality. To make it, we have to inject our class to sync redirects in some place.

What can be the most obvious ?

We have to ask, when we want to clean and sync our redirects ? Probably when we will add new ones. Hence, if we would like to be sure that potentially new added redirect items will be sync, we have to inject our code into publishing process.

To do that we can easily create a config patch and invoke our class in publish event. Could be done like:

What we can see here is also publish:end:remote event. It's very important for this ones from you, who use scalable architecture with servers CD, CM. Don't forget to use remote event :)

At the end I hope that information I wrote will be helpful for you. Keep fingers crossed and of course feel free to write me if you would like to.