Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Sergii Shymko - Code migration tool for upgrade to Magento 2


Published on

Since the official release of Magento 2 in November 2015, upgrading from Magento 1.x has become a goal for store owners and extension vendors. Being a major release, Magento 2 has made leaps forward in the application architecture, which contributes to the upgrade complexity. One of the major challenges is upgrade of a codebase. Code migration tool has been created to tackle this task. Current presentation goes over the capabilities of the tool. We discuss how to employ the tool for a successful upgrade project.

Sergii Shymko - Code migration tool for upgrade to Magento 2

  1. 1. Magento 2 Upgrade Scope Database Schema Data Codebase Magento framework 3rd party extensions Custom modules Custom themes @SergiiShymko #mm16it
  2. 2. Magento 2 Upgrade Tooling Database Schema Data Codebase Magento framework 3rd party extensions Custom modules Custom themes Data migration tool Code migration tool @SergiiShymko #mm16it
  3. 3. Code Migration Tool Scope Directory structure Configuration <?php // code ;) Layout Magento module @SergiiShymko #mm16it
  4. 4. Code Migration Tool Overview • Audience: Magento developers • Interface: Command line interface (CLI) • Goal: Automate routine code changes • Methodology: Static code analysis Code migration tool @SergiiShymko #mm16it Magento 1.x source code Magento 2 source code
  5. 5. Prerequisite Directory Structure @SergiiShymko #mm16it <tool> – Installed M2 code migration tool <src> – Custom M1 code to be migrated <dst> – Empty directory to put generated M2 code to <m1> – Vanilla M1 codebase + Custom M1 code (<src>) <m2> – Vanilla M2 codebase
  6. 6. Directories Utilization Code migration tool @SergiiShymko #mm16it <src> <dst> <m1> <m2>
  7. 7. Directories Utilization Code migration tool @SergiiShymko #mm16it <src> <dst> <m1> <m2>
  8. 8. Migration Sequence Generate mappings Migrate directory structure Migrate layout Migrate config Migrate PHP code 1. 2. 3. 4. 5. @SergiiShymko #mm16it
  9. 9. Command to run: 1. Mapping Generation • Mapping between: – Latest M1 and M2 releases – out of the box – Any M1 and M2 versions – generated on demand • Mapping covers: – Module names – Class names & dependencies – Table names – View files @SergiiShymko #mm16it php <tool>/bin/utils.php generateClassMapping <m1> <m2>
  10. 10. Command to run: 2. Directory Structure Migration • Removal of code pools (core, community, local) • Aggregation of module’s files in a single directory: – PHP code – Templates – Layouts – Static assets – Translation dictionaries @SergiiShymko #mm16it php <tool>/bin/migrate.php migrateModuleStructure <src> <dst>
  11. 11. Magento 1.x Magento 2 app/ code/ community/ Example/Module/ etc/modules/ locale/<locale>/ design/ <area>/base/default/ skin/ <area>/base/default/ app/ code/ Example/Module/ etc/ i18n/<locale>/ view/<area>/ 2. Directory Structure Migration @SergiiShymko #mm16it
  12. 12. Command to run: 3. Layout Migration • Breaking down layout files by handles • Format of layout XML files: – Block types – Block names – Template references – References to blocks and containers – Adding JS/CSS assets to page head @SergiiShymko #mm16it php <tool>/bin/migrate.php convertLayout <dst>
  13. 13. Magento 1.x Magento 2 app/ design/ frontend/ base/default/ layout/ example.xml app/ code/ Example/Module/ view/ frontend/ layout/ default.xml … 3. Layout Migration @SergiiShymko #mm16it
  14. 14. Command to run: 4. Configuration Migration • Breaking down config.xml into granular configs • Format of config XML files: – Module declaration – Routers – Indexers – Admin menu – System configuration – Widgets @SergiiShymko #mm16it php <tool>/bin/migrate.php convertConfig <dst>
  15. 15. Magento 1.x Magento 2 app/ code/community/ Example/Module/ etc/ config.xml app/ code/ Example/Module/ etc/[<area>/] module.xml … 4. Configuration Migration … @SergiiShymko #mm16it
  16. 16. Command to run: 5. PHP Code Migration • Breaking down controllers by actions • Format of PHP files: – Class namespaces – Dependency injection via constructor – Class name aliases in factory methods – Class names in static calls, constants, arguments, operator “new”, PHPDoc – Table name aliases – Translation via “gettext” @SergiiShymko #mm16it php <tool>/bin/migrate.php convertPhpCode <dst> <m1> <m2>
  17. 17. 5. PHP Code Migration @SergiiShymko #mm16it
  18. 18. Tool Commands Summary 1. Generate mappings 2. Migrate directory structure 3. Migrate layout 4. Migrate configuration 5. Migrate PHP code php <tool>/bin/migrate.php migrateModuleStructure <src> <dst> php <tool>/bin/migrate.php convertLayout <dst> php <tool>/bin/migrate.php convertConfig <dst> php <tool>/bin/migrate.php convertPhpCode <dst> <m1> <m2> php <tool>/bin/utils.php generateClassMapping <m1> <m2> @SergiiShymko #mm16it
  19. 19. a. Commit disabled M2 modules b. Test, fix, and enable module by module 3. M2 codebase tasks Upgrade Project Breakdown 2. Code migration tool tasks a. Tailor the tool for patterns unique to the project b. Run the tool against M1 codebase 1. M1 codebase tasks a. Remove unused modules b. Remove fixes of M1 bugs irrelevant in M2 @SergiiShymko #mm16it
  20. 20. Sergii Shymko Thank You! Q & A