Magento 2 Code Migration Tool

Post on 13-Apr-2017

99 views 2 download

Transcript of Magento 2 Code Migration Tool

@SergiiShymko #mm16it

Magento 2 Upgrade Scope

Database

Schema

Data

Codebase

Magento framework

3rd party extensions

Custom modules

Custom themes

@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

@SergiiShymko #mm16it

Code Migration Tool Scope

Directorystructure

Configuration

<?php // code ;)

Layout

Magentomodule

@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

@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

@SergiiShymko #mm16it

Directories Utilization

Code migration tool<src> <dst>

<m1> <m2>

@SergiiShymko #mm16it

Directories Utilization

Code migration tool<src> <dst>

<m1> <m2>

Read-only

Writeable

@SergiiShymko #mm16it

Migration Sequence

Generate mappings

Migrate directory structure

Migrate layout

Migrate config

Migrate PHP code

1. 2. 3. 4. 5.

@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>

@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>

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

@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>

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

@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>

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

@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>

@SergiiShymko #mm16it

5. PHP Code Migration

@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>

@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

Sergii Shymkosshymko@magento.com

sergey@shymko.net

github.com/magento/code-migrationgithub.com/magento/data-migration-tooldevdocs.magento.com/guides/v2.0/migration/migration-tool.html

Thank You!Q & A