MIGRATE YOUR CODE FROM MAGENTO 1 TO MAGENTO

  • Slides: 27
Download presentation
MIGRATE YOUR CODE FROM MAGENTO 1 TO MAGENTO 2 Simon Frost

MIGRATE YOUR CODE FROM MAGENTO 1 TO MAGENTO 2 Simon Frost

ABOUT ME § Simon Frost § Senior Backend Magento Developer at Vortex Commerce §

ABOUT ME § Simon Frost § Senior Backend Magento Developer at Vortex Commerce § Magento Certified Developer Plus § Zend Certified Engineer § Working with PHP for about 10 years § Working with Magento for about 5 years

INTRODUCTION § Theory § What can be migrated? § What can't? § What shouldn't?

INTRODUCTION § Theory § What can be migrated? § What can't? § What shouldn't? § Practice § Tools § Process § A worked example

THEORY What you should take into account before migrating

THEORY What you should take into account before migrating

WHAT ARE THE BIG CODE CHANGES IN M 2? § Different directory structure §

WHAT ARE THE BIG CODE CHANGES IN M 2? § Different directory structure § Namespaces § Dependency Injection § Domain-specific config XML files § Handle-specific layout XML files

WHAT CAN BE MIGRATED AUTOMATICALLY? § Directory structure § Config XML § Layout XML

WHAT CAN BE MIGRATED AUTOMATICALLY? § Directory structure § Config XML § Layout XML § PHP Code

WHAT CAN'T BE MIGRATED AUTOMATICALLY? § Themes § Resource scripts § CSS conversion from

WHAT CAN'T BE MIGRATED AUTOMATICALLY? § Themes § Resource scripts § CSS conversion from plain CSS to LESS/SASS § JS conversion from Prototype to j. Query § Custom business logic (depends) § Module dependencies. These need to be done separately. § Unit tests § 3 rd Party Libraries - these should be added to M 2 composer. json manually § Layout XML in the admin

WHAT SHOULDN'T YOU MIGRATE? § Migrating is a lot of work, even if some

WHAT SHOULDN'T YOU MIGRATE? § Migrating is a lot of work, even if some of it is automated. § Don't bother migrating an extension if you can answer yes to any of the following questions: § Does it duplicate existing M 2 functionality? § Is there an M 2 extension already available that does the same thing? § Does the client no longer use the extension?

PRACTICE A comparison of the tools available

PRACTICE A comparison of the tools available

MIGRATING USING AUTOMATED TOOLS § These tools simply automate repetitive tasks, i. e. Splitting

MIGRATING USING AUTOMATED TOOLS § These tools simply automate repetitive tasks, i. e. Splitting the M 1 config. xml file into multiple M 2 config XML files § Depending on the age and purpose of the extension, it may be better to start from scratch than try to migrate it (hold that thought) § It would be very helpful to know about the part of M 2 your M 1 extension works with (i. e. Payment gateways, shipping methods, etc) so you can tell how accurate the migration was after it has been migrated § Convert your extension using each one, then compare, contrast and merge all changes (including any manual changes you've made) into one finished product

THE TOOLS (1/2) Code Migration Toolkit (Magento) Convert. M 1 M 2 (Unirgy) https:

THE TOOLS (1/2) Code Migration Toolkit (Magento) Convert. M 1 M 2 (Unirgy) https: //github. com/magento/code-migration https: //github. com/unirgy/convertm 1 m 2 § Standalone CLI tool, aimed at § Developed by ex-M 1 core developers to automate routine code changes using static analysis § M 1 code goes in, M 2 code comes out § Only covers custom extensions. Themes, data and database schema are not migrated. § Remaining work: Converting custom business logic, testing, troubleshooting § Last updated: Less than a month ago § Convert multiple extensions at once § Includes code validation of migrated classes § Difficult to configure § Remaining work: Converting custom business logic, testing, troubleshooting § Last updated: 9 months ago

THE TOOLS (2/2) Pestle (Alan Storm) https: //github. com/astorm/pestle Start from scratch § Not

THE TOOLS (2/2) Pestle (Alan Storm) https: //github. com/astorm/pestle Start from scratch § Not a migration tool, but an M 2 code § Maybe a better option if you don't get § Helpful for plugging the gaps that other § Use an M 2 module generator (e. g. § Last updated: Less than a month ago § Use your M 1 extension for reference generation tool code migration tools may miss good results from automated tools Pestle, n 98 -magerun 2)

PROCESS Steps to follow to get the most out of the migration process

PROCESS Steps to follow to get the most out of the migration process

PROCESS (1/2) Preparation Conversion § Get your M 1 extension into the best §

PROCESS (1/2) Preparation Conversion § Get your M 1 extension into the best § Run the tool(s) shape possible § Remove anything which depends on M 1 features which are not present in M 2 § Remove M 1 -specific bug fixes or obsolete customisations § Remove anything which duplicates M 2 functionality

PROCESS (2/2) Afterwards Testing § Manual inspection (diff) of code. § Run M 2

PROCESS (2/2) Afterwards Testing § Manual inspection (diff) of code. § Run M 2 unit tests. Make sure they all § Check to see what wasn't migrated. § Manually convert anything remaining. § Bonus points: If there is a design pattern which occurs across your extension which the tool doesn't convert, fork the tool and modify it to update that, rather than manually updating it wherever it occurs pass. § Install the migrated extension into vanilla M 2 instance. § Write M 2 unit tests for your migrated extension! § Run M 2 unit tests again.

USING THE MAGENTO CODE MIGRATION TOOLKIT A step-by-step guide to using Magento's official offering

USING THE MAGENTO CODE MIGRATION TOOLKIT A step-by-step guide to using Magento's official offering

USING THE MAGENTO CODE MIGRATION TOOLKIT Usage notes Installation § You'll need a vanilla

USING THE MAGENTO CODE MIGRATION TOOLKIT Usage notes Installation § You'll need a vanilla install of both M 1 § Requires min. PHP 5. 5 x and M 2 § You'll need your extension installed in the M 1 instance § If your extension has dependencies on other extensions or libraries, they must be installed in the M 1 instance as well, even if they are not to be migrated § Changes are cumulative, so each of the tools must be run in the specified order § Clone it: https: //github. com/magento/codemigration § Install with composer: § composer install

1. PREPARATION § <source> - Directory that contains custom Magento 1. x code that

1. PREPARATION § <source> - Directory that contains custom Magento 1. x code that is intended to be migrated. The code must follow the Magento 1. x directory structure. Magento 1. x core files must not be included. § <destination> - Empty directory for the toolkit to write the generated Magento 2 code into § <m 1> - Directory that contains: § Vanilla Magento 1. x codebase, and § Custom Magento 1. x code same as in <source> directory, and § Dependencies of the custom Magento 1. x code, if any, that are not part of <source> directory as not intended to be migrated at the moment § <m 2> - Directory that contains the vanilla Magento 2. x codebase

2. PREPARE MAPPINGS § Command: § php <tool>/bin/utils. php generate. Class. Mapping <m 1>

2. PREPARE MAPPINGS § Command: § php <tool>/bin/utils. php generate. Class. Mapping <m 1> <m 2> § Uses mappings to migrate module names, class names, table names and view files to M 2 equivalents § E. g. Mage_Catalog (in M 1) is mapped to Magento_Catalog (in M 2) § Pre-generated mappings are included for 1. 9 x, mappings for other versions can be created on demand

3. MIGRATE DIRECTORIES § Command: § php <tool>/bin/migrate. php migrate. Module. Structure  <source>

3. MIGRATE DIRECTORIES § Command: § php <tool>/bin/migrate. php migrate. Module. Structure <source> <destination> § Removes code pools § Aggregates extension files into one directory Before After

4. MIGRATE LAYOUT XML § Command: § php <tool>/bin/migrate. php convert. Layout <destination> §

4. MIGRATE LAYOUT XML § Command: § php <tool>/bin/migrate. php convert. Layout <destination> § Splits layout files into handle-specific XML files and reformats XML to M 2 syntax Before After

5. MIGRATE CONFIG XML § Command: § php <tool>/bin/migrate. php convert. Config <destination> §

5. MIGRATE CONFIG XML § Command: § php <tool>/bin/migrate. php convert. Config <destination> § Splits config XML files into domain-specific XML files Before After

6. MIGRATE PHP CODE § Command: § php <tool>/bin/migrate. php convert. Php. Code <destination>

6. MIGRATE PHP CODE § Command: § php <tool>/bin/migrate. php convert. Php. Code <destination> <m 1> <m 2> § Refactors controllers by actions § Updates PHP namespaces § Adds class dependencies to constructor using DI § Updates class name aliases in factory methods § Replaces calls to static methods (i. e. Mage: : )

Before After

Before After

. . . AND FINALLY – AN ALTERNATIVE § Refactor your extension so it

. . . AND FINALLY – AN ALTERNATIVE § Refactor your extension so it supports M 1 and M 2 simultaneously (but that's for another time ; )

THANK YOU! ANY QUESTIONS? §?

THANK YOU! ANY QUESTIONS? §?

SOURCES TOOLS AND DOCUMENTATION PRESENTATIONS § Magento: Code Migration Toolkit § Imagine 2016 -

SOURCES TOOLS AND DOCUMENTATION PRESENTATIONS § Magento: Code Migration Toolkit § Imagine 2016 - Developer Deep Dive: § https: //github. com/magento/code-migration § Unirgy: Convert. M 1 M 2 § https: //github. com/unirgy/convertm 1 m 2 § Alan Storm: Pestle § https: //github. com/astorm/pestle § Magento Dev. Docs: Migrate from Magento 1 to Magento 2 § http: //devdocs. magento. com/guides/v 2. 0/how doi/migrate. html Magento 1. x to Magento 2 Code Migration Tool § https: //www. youtube. com/watch? v=l. XJ 6 r. Md. Q vkk&feature=youtu. be § Meet Magento Serbia - Porting Magento 1. x extensions to Magento 2 § https: //www. youtube. com/watch? v=Q 19 f. J 2 U Qsa. I § Meet Magento Utrecht: Migrating from Magento 1 to Magento 2 § http: //www. slideshare. net/mzeis/migrating- from-magento-1 -to-magento-2