Magento 2 Code Migration Tool

22

Transcript of Magento 2 Code Migration Tool

Page 1: Magento 2 Code Migration Tool
Page 2: Magento 2 Code Migration Tool
Page 3: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

Magento 2 Upgrade Scope

Database

Schema

Data

Codebase

Magento framework

3rd party extensions

Custom modules

Custom themes

Page 4: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

Magento 2 Upgrade Tooling

Database

Schema

Data

Codebase

Magento framework

3rd party extensions

Custom modules

Custom themes

Data migration toolgithub.com/magento/data-migration-tool

Code migration toolgithub.com/magento/code-migration

Page 5: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

Code Migration Tool Scope

Directorystructure

Configuration

<?php // code ;)

Layout

Magentomodule

Page 6: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

Code Migration Tool Overview

• Audience: Magento developers• Interface: Command line interface (CLI)• Goal: Automate routine code changes• Methodology: Static code analysis

Code migration tool

Magento 1.xsource code

Magento 2source code

Page 7: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

Prerequisite Directory Structure

<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

Page 8: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

Directories Utilization

Code migration tool<src> <dst>

<m1> <m2>

Page 9: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

Directories Utilization

Code migration tool<src> <dst>

<m1> <m2>

Read-only

Writeable

Page 10: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

Migration Sequence

Generate mappings

Migrate directory structure

Migrate layout

Migrate config

Migrate PHP code

1. 2. 3. 4. 5.

Page 11: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

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

php <tool>/bin/utils.php generateClassMapping <m1> <m2>

Page 12: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

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

php <tool>/bin/migrate.php migrateModuleStructure <src> <dst>

Page 13: Magento 2 Code Migration Tool

Magento 1.x Magento 2

@SergiiShymko #mm16it

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

Page 14: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

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

php <tool>/bin/migrate.php convertLayout <dst>

Page 15: Magento 2 Code Migration Tool

Magento 1.x Magento 2

@SergiiShymko #mm16it

app/design/

frontend/base/default/

layout/ example.xml

app/code/

Example/Module/view/

frontend/layout/ default.xml …

3. Layout Migration

…handles

Page 16: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

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

php <tool>/bin/migrate.php convertConfig <dst>

Page 17: Magento 2 Code Migration Tool

Magento 1.x Magento 2

@SergiiShymko #mm16it

app/code/community/

Example/Module/etc/ config.xml

app/code/

Example/Module/etc/[<area>/] module.xml …

4. Configuration Migration

Page 18: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

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”

php <tool>/bin/migrate.php convertPhpCode <dst> <m1> <m2>

Page 19: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

5. PHP Code Migration

Page 20: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

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>

Page 21: Magento 2 Code Migration Tool

@SergiiShymko #mm16it

a. Commit disabled M2 modulesb. 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 projectb. Run the tool against M1 codebase

1. M1 codebase tasks

a. Remove unused modulesb. Remove fixes of M1 bugs irrelevant in M2