Sitecore tips and tricks and community news !

Post Top Ad

Post Top Ad

2:58 PM

Hackathon 2017

I had a great opportunity to be a part of Sitecore Hackathon 2017 team member. It was my first time in this event and I have to say it were unforgettable 24 hours :)




Team
In our team expect me were: Wojtek Urban and Tomek Juranek. Two awesome guys which with I have pleasure to work with. We called our team "Error 404" and start as a 1 of 3 teams which has been entered into competition.



Topic
We've chosen topic with "Habitat Module" according to which we would like build user report module, called "User Report Module" :) The main idea was to create a place in Sitecore where will be available reports from conent work. In that case we had to use xDB part and make it with Speak from UI side. 

Work
I can say, that in my age is not easy to work for 24h :) I had one break to sleep a little bit, but besides that we were working on our application and were still in touch with other hackathon attendees.


Finish
At the finish we checked in as only one team from Poland :) We achieve our goal and made every rule, hence results could be send for jury ! :) First time with that success :)



Module in Speak looks like:


If you would like see hackathon results could be find as a video:



It wasn't easy but our achievement has been completed :) We hope it's only first step on our road and we would like to attend in next year as well.
Moreover of course we would like to find time and extend our module to make it as best as we can.


Exactly, satisfied, the best word in that time. Looking forward to meet you on next #SitecoreHackathon !


8:22 AM

Redirects 1/2



Once has to come a day when someone ask you to prepare Redirects in Sitecore. For instance you are working on some old site migration. You want to build new really cool structure so it means you will loose old content tree structure probably. Hence we will destroy SEO on which client has been working for months...

And here redirects come.


1. Why redirects in Sitecore ?

Because we can manage it ! We can create separate item which map single redirect and setup any settings that we will provide by ourselves. Additionally if we have a lot of redirects to create we can build importer from *.csv file for instance.

2. How it works ?

We are creating Sitecore items representation which will map our redirects. After that we can create custom code that will read this items during processing http request and decide to make redirect or not. To do that we create our custom processor that we will inherit from HttpRequestProcessor, and it will be added as a patch to config part like:

To help imagine that we can draw diagram

In this picture we can see how flow of http request goes through Sitecore. It processes in our custom http processor and as a result Sitecore change response url or not.

3. How can look sample use case ?

Everybody know if something looks understandable, then details could be more problematic. So, lets try to check how it will be in the field.

I would like to add that I'm omitting things like "how to create redirect template", because I'm sure all of you know what is item data template and how to create it :)

If we would like to have useful approach we should to distinguish between two kinds of subtrees.

a) Redirect type - which will describe status of particular redirect
b) Redirect item - which will define single redirect

Picture below describe this:

Ok, but what fields we can have in those items ? In our example we can have:

Redirect type fields
Redirect item fields









As you can see, old address field is marked on red, what means is validated as required field. I think is useful details, because who wants to create redirect without filling old address value?

After we have done redirect items, custom code left for us. At the point "2. How it works" I've mentioned about custom http processor, which will interpret http request and check is particular request target url exist in redirects list. If yes, Sitecore has to change url to new redirect value.

We have to stop here for a while and think a little bit about list of redirects. Because we have to check this list each time we will process http request, have to ask, is a good idea to collect this list each time from a scratch ?

Answer is:
- Definitely no :)

We should prepare some mechanism that will keep it in the memory and return value. Because list of redirects is common for whole application, we can clean up our studies memories and try to do Singleton object, which is common for whole application and it has only one instance. Hence, we will avoid situation to create multiple instance of the same list. Sounds great, doesn't it ? :) 


When we have our list of redirect, lets make redirect handler:

I hope you don't mind that I will avoid describing each of the method inside. But we have to notice one action: SyncRedirectsWithStore .Somebody can ask, "Yo dude, what is going on here ? ". Fortunately we know that our list is Singleton instance and sometimes we will have situations when we will have to sync. In this place I realized that post is really long, so rest information I will back to the new one.

As the summary for our place in the redirect's space we know:
- when can do redirects in Sitecore
- what is the flow of http request
- which items we need in Sitecore to serve redirects
- which processor will be responsible for redirects in Sitecore

I hope that information will be helpful for you, feel free to contact with me on socials or email ;)

All the bests,
Robert !