eZ Community » Blogs » Carlos Revillo » Migrating sillonbol.com from eZ...

By

Migrating sillonbol.com from eZ Publish 4 to eZ Publish 5

Wednesday 12 February 2014 2:14:58 pm

  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Since few days ago, sillonbol.com site is powered by eZ Publish 5. In fact, it’s powered with clones of the master versions from the eZ Publish Community Edition and the eZ Publish Legacy versions and its core is updated regularly to get new functionalities accepted by the eZ crew.  

 

What you see in the page is the result of a migrating from a site fully powered by the eZ Legacy Stack to a site powered by the Symfony part at (i would say) 80%. It’s also the result of a redesign of the site.

What we had

Our site was quite basic. It was just a root node with a bunch of folders (called “subcategoria” in our case) with childrens inside. Those children can be objects of two classes, but those two classes were identical and were rendered by the same template. It had also a frontpage powered by eZ Flow, a tags system powered by the eZ Tags extension, a search form and results page powered by eZ Find, a comments system powered by eZ Disqus and finally a Contact Form. Finally, it also had a custom extension where all the customization of the look and feel happened.

We keep this version of the site still accessible just to be linked from this article and to show how the site powered by symfony stack and  the site powered by the legacy one can live together. Actually, both installations are sharing database and var folders.

What we wanted.

Apart from moving to eZ 5, we thought we needed a redesign of the site. Our previous site has no mobile version and was no responsive, and our (few) readers asked us about it. We’re no designers, and so we googled searching for something that could fit our new ideas. And thats were this Fullby theme appeared. It’s a wordpress one, but i thought it could be easily ported to the Symfony stack. Finally, some friends helped us with the colours.

The result

With these ideas in mind, i started with the development of a bundle. It’s heavily based on the eZ Demo one, so you can take this eZ Demo one as a really good starting point if you plan a new eZ 5 site or the migration of a eZ 4 one. This bundle has been published to github. Feel free to fork and contribute if you want :).

Actually, the site is even more basic than it was. As we don’t produce many pieces of content content, we decided to avoid the ez flow part. Apart from that, we maintain the more important functionalities of the previous site and here is what i’ve done for it.

Layout.

Css, js and images provided by the chosen theme were added to the bundle. Then, the main layout was built. This twig template has a condition for showing our main block just in the case we are in the home page (location 2). Some includes and controllers take care of the rest.

Folders and Article pages

I created some twig templates for them. They are quite basic. Article pages just render the fields, while listing pages uses PagerFanta for the pagination stuff. Both use a custom controller. In the articles case, this controller is used in allviewtypes. And i can make use of one of all of the variables added in one or another template.

Tags fields in articles are rendered thanks to the Netgens - TagsBundle. I just added a custom template to override how the tags are presented in the bundle and to add a link to a list of articles tagged with each tag.

As said above, articles had comments powered by ezdisqus extension. That extension added a datatype to the legacy code. But in the ez5 part, there is no need to keep that datatype. Instead, commentsBundle is used. But as we didn’t want any database modification in the migration, i just mapped that field to the null converter.

Finally, i added a bit of xslt to have custom online editor tags working. And to tell eZ to look for this xslt, a setting in the bundle config file is enough.

Tags and Search Pages

Listing of content tagged with a tag or search result module is still ran by the legacy system. (well, the search result pages needs some polish…). One of the greatness of eZ 5 is that even if lots of eZ 4 functionalities haven’t been ported to the symfony stack yet, they are still usable and without any configuration. The work here was just modify the legacy templates to adapt them to our new look and feel. Anyway, and thanks to the possibility of running legacy code, my next step will be create dedicated symfony controllers for this matter and use twig templates for the presentation part.

Contact Page

Even we used the famous information collection fields in our previous install, we rarely looked at them as we also received the inquiries by email. So, i decided go for symfony here. I truly believe form creation is an easier task in eZ 5 than in eZ 4 thanks to the Symfony Form Component.

As in the eZ 4 version our contact form was found in “contacto”, i just added a new route and a new controller for rendering the form. Captcha functionality was easily added thanks to this great other bundle.

Rss page.

Actually i have an only rss file but the plan is add more of them. And again, I added a new route and a new controller. But take a look at the last part of the routing definition. Notice that “_format:rss”? Have a look to the Symfony CookBook, specially to the “The Special format Routing Parameter”. No need to add special headers on your side to output the rss because Symfony will take care of it!. Cool, isn’t it?

Home Page.

It was last part built. Main block has the last 3 published articles and secondary block has the following three.

Finally, I added two blocks in the left side of the page. Those blocks already existed in the eZ 4 version. So, i decided to use legacy code to get data and pass them to the templates.

Varnish

Our eZ4 was behind a Varnish Server and had purge capabilities thanks to the Mugo Varnish extension. This extension is not needed anymore in the eZ 5 version. Just with the proper varnish configuration and some changes in your config files, your publishing operations will send request to the Varnish server. Even more, the render_esi capabilities of Symfony will allow you to have some parts of the page cached for ages (thinking maybe in the footer) while have others uncached at all.

Conclusion

In the end, i’m quite happy with the result. I had some frustration in the past months but the eZ Crew continues evolving the kernel and adding some functionalities or even bundles (commentsBundle, PagerFanta, etc) that makes your work easier.

Let me add I was not a Symfony expert at all. In fact, I really hadn’t worked with it till i started with eZ 5. But i found the move easier than i thought. My advice, and also what i did,  is look at the Symfony Cookbook and pay special attention to the “Controllers” and “Service Container”  , chapters. Once i understood this and, again, looking to has been coded in the Demo Bundle, i found the move to eZ5 fairly easy. And believe me, learning a bit of symfony will take you much (really much) less time than it took you to learn about tpl, module definitions, function definitions and all that things you have used in the past.  

Probably the biggest change comparing to what we did in eZ 4 is what you can and what you can’t do in the templates. Surely you have heard about “fetch” functions and how you put them in your templates to, let’s say, execute a query to the database from the template. That was cool, but on the other side, i think that wasn’t really a separation between logic and presentation.

So, to finish, some notes and advices:

  • Don’t try to reproduce in Twig templates what you did in tpl templates. They are totally different engines.
  • Don’t be afraid of Twig Engine. Is easy to learn.
  • Don’t be afraid of adding php code to your bundles. Probably with eZ 4 you could built a website without a line of php. But as said, that probably was because your “logic” was also in templates. Here, play with Symfony. It’s really more extensible than the eZ4. framework. You will also find more reusable code coming from the Symfony community.
  • There isn't any (i mean ANY) problem in using your legacy code from the Symfony stack. It's brilliant what eZ Crew have done in this part. Don't delay your migrations thinking you'll lost functionalities. 

I encourage everybody having an eZ 4 site to start with eZ 5. The sooner you start to code eZ 5, the sooner you’ll find its benefits. And there a lot of them!.

Proudly Developed with from