Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Story about Migration to Symfony Framework: F...

A Story about Migration to Symfony Framework: Fails and Successes

A Story about Migration to Symfony Framework: Fails and Successes / История одного переезда на Symfony: Ошибки и успехи

Avatar for Igor Onachenko

Igor Onachenko

October 24, 2015

Other Decks in Programming

Transcript

  1. About me • Web Developer since ~2006 • Symfony Developer

    at predanie.ru • github.com/igorRovenki • devsize.ru hot articles for web developers
  2. Agenda • Migrating site (CMS) to Symfony Framework. Why? •

    Things we wish to knew before migration to Symfony (cases)
  3. 1. Legacy Code Layers of ugly CMS code Previous developers

    against official docs The picture about our code Sometimes you can’t rewrite a whole project, because it’s crazy But sometimes it makes sense! All of us wants to rewrite a legacy project, isn’t it? :)
  4. 2. CMS Limits • It’s hard to develop custom statistics

    and analytics (when custom properties of Entity stored in 2 database tables) • Ugly model with CMS API • Lets find "entity" by id:
 
 • Where is entities? CIBlockElement::GetByID($id);
  5. 3. Continuous Integration and Automatic Testing? • CMS not adopted

    for Version Control • Impossible to store CMS Core in Git • Impossible to use PHPUnit because CMS API does not provide such opportunity PHPUnit
  6. 4. We wanted MVC • CMS system 1C-Bitrix does not

    have Front Controller. You need to create file for each url manually: /news/index.php?ELEMENT_ID=1 • We wanted to have Controllers and Actions • People says, Symfony is not MVC?
  7. 5. The way of working with objects - Doctrine 2

    • When I looked at it, I sad "YES". Such useful ways to work with objects I have not seen yet! • Doctrine helped us a little to understand what DDD is • It is impossible to compare the API of CMS and Doctrine ORM
  8. In the beginning we decided create something like this. 1.

    Bundle’s structure We created this bundle for storing files for all application (js, css, base entities) If your bundles cannot be used as standalone bundles in other Symfony projects - it makes no sense
  9. 1. Bundle’s structure But in 99% cases you need only

    one bundle http://symfony.com/doc/2.3/best_practices/creating-the-project.html * *
  10. Often we creating bundle and don’t realize that new bundle

    should become standalone application. Not just bundle
  11. Charity fund Media Archive Old bitrix monolith application and subject

    domain children, donations, help audio, video files, books, listen, watch, read
  12. Soon we understood: that was a bad solution • Bundles

    will have common Symfony kernel and services and it’s bad • If we will deploy code with a bugs for Media archive it may affect Charity Fund and fund will be down. But what about money for children? • Media Archive is more high load then fund. If Archive is down because of high load - fund is down also • If we want to run application on many instances, we will see - monolith application is not best case for scaling
  13. Think and ask questions before migrating to Symfony • If

    you will migrate to Symfony, you need to ask yourself question: will whole parts of old application migrate or maybe it makes sense to think about standalone services • At the beginning such thing is easy to understand, but often it is easy to forgot • We decided to divide bundles into 2 standalone services. But it is not easy and we need time for it.
  14. You have 2000 articles and you need to update field

    "slug" for all of them. What a first thought will come to you if you beginner in Symfony?
  15. Soon we understood: controllers is a bad choice • Сontrollers

    will be opened for whole world • You can forgot about it • It’s not useful for batch operations • Controllers was designed for other purposes
  16. In our case we have a composition/work with sections and

    audio files. And the main question we have: Where to store paths to files for Doctrine entities?
  17. - author folder - work folder - section folder -

    file /uploads/lyuis-klayv/hroniki-narnii-1-plemyannik-charodeya/kniga-tretya- kon-i-ego-malchik/klayv-lyuis-01-kon-i-ego-malchik.mp3 $audio->getSection()->getWork()->getAuthor()
  18. Something is wrong. How about foreach? {% for audio in

    section %} {{ webpath(audio) }} - query to database :( {% endfor %}
  19. • What if collection has 100-200 audio? :( • In

    all places, controllers and for all API we should call this service :( • Service every time makes query to DB :(