32
© 2016 Magento, Inc. Page | 1 2.1 EE Content Staging Technical overview

Magento 2.1 ee content staging

Embed Size (px)

Citation preview

Page 1: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 1

2.1 EE Content

Staging Technical

overview

Page 2: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 2

Software Architect at Magento

Anton Kaplya

Page 3: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 3

Agenda

• What is Content Staging

• How Content Staging works

• How to work with Content Staging

Page 4: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 4

Magento StagingScheduling data changes for ecommerce

entities

Page 5: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 5

What is Content Staging

• Scheduling data changes

• Instant Preview

• Automatic changes deployment

Page 6: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 6

Page 7: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 7

Magento Content Staging

Page 8: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 8

Magento Content Staging

Page 9: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 9

Magento Staging Dashboard

Page 10: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 10

Magento Content Staging Preview

Page 11: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 11

Supported Entities • Products & Categories

• CMS Pages & Blocks

• Cart Price Rules

• Catalog Rule

Page 12: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 12

How Content Staging works

Page 13: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 13

MVCC

• Multiversion Concurrency Control

• InnoDB transaction engine is built upon MVCC

• Copy on change

Page 14: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 14

Page 15: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 15

MVCC

1 100 150 200

A

50 MAX

A'A''

BB'

C

Page 16: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 16

How MVCC influences Magento• Entity may have several representations in main table

• Creation time

• Expiration time

Page 17: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 17

Assumptions & Agreements

• We use UNIX_TIMESTAMP as a pointer for versions

• Default value for creation time is 1

• Default for value expiration time is MAX INT

Page 18: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 18

Table structure

CREATE TABLE entity_table (

row_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,

entity_id UNSIGNED NOT NULL,

created_in BIGINT UNSIGNED NOT NULL,

updated_in BIGINT UNSIGNED NOT NULL,

...

PRIMARY KEY ( row_id),

KEY ix_entity_id ( entity_id),

KEY ix_created_in ( created_in),

KEY ix_updated_in ( updated_in)

) ENGINE=InnoDB;

Page 19: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 19

Example

SELECT

e.row_id, e.entity_id, e.created_in,

e.updated_in, v.value

FROM catalog_product_entity e

JOIN catalog_product_entity_varchar v

ON v.row_id = e.row_id AND v.attribute_id = 73

WHERE e.entity_id = 1;

Page 20: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 20

Creation of new entity

+--------+-----------+------------+------------+-----------+

| row_id | entity_id | created_in | updated_in | value |

+--------+-----------+------------+------------+-----------+

| 1 | 1 | 1 | 2147483647 | Green Car |

+--------+-----------+------------+------------+-----------+

Page 21: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 21

Create a new version for entity

+--------+-----------+------------+------------+-----------+

| row_id | entity_id | created_in | updated_in | value |

+--------+-----------+------------+------------+-----------+

| 1 | 1 | 1 | 1474829340 | Green Car |

| 2 | 1 | 1474829340 | 2147483647 | Blue Car |

+--------+-----------+------------+------------+-----------+

Page 22: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 22

Create several future versions

+--------+-----------+------------+------------+-----------+

| row_id | entity_id | created_in | updated_in | value |

+--------+-----------+------------+------------+-----------+

| 1 | 1 | 1 | 1474829340 | Green Car |

| 2 | 1 | 1474829340 | 1474988880 | Blue Car |

| 3 | 1 | 1474988880 | 1475161680 | Red Car |

| 4 | 1 | 1475161680 | 2147483647 | Blue Car |

+--------+-----------+------------+------------+-----------+

Page 23: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 23

How select works

Page 24: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 24

How select works

WHERE (created_in <= 125 AND updated_in > 125)

+--------+-----------+------------+------------+

| row_id | entity_id | created_in | updated_in |

+--------+-----------+------------+------------+

| 1 | 1 | 1 | 100 |

| 2 | 1 | 100 | 200 |

| 3 | 1 | 200 | 2147483647 |

| 4 | 2 | 1 | 150 |

| 5 | 2 | 150 | 2147483647 |

| 6 | 3 | 1 | 2147483647 |

+--------+-----------+------------+------------+

Page 25: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 25

How SELECT works (Query)

SELECT e.row_id, e.entity_id,

e.created_in, e.updated_in, v.value

FROM catalog_product_entity e

JOIN catalog_product_entity_varchar v ON v.row_id = e.row_id

AND v.attribute_id = 73

WHERE e.entity_id = 1

AND (e.created_in <= 1474828140

AND updated_in > 1474828140

);

Page 26: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 26

How SELECT works (Data)

+--------+-----------+------------+------------+-----------+

| row_id | entity_id | created_in | updated_in | value |

+--------+-----------+------------+------------+-----------+

| 1 | 1 | 1 | 1474829340 | Green Car |

+--------+-----------+------------+------------+-----------+

| 2 | 1 | 1474829340 | 2147483647 | Blue Car |

+--------+-----------+------------+------------+-----------+

Page 27: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 27

How to work with

Content StagingShort notice for extension developers

Page 28: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 28

Content Staging & Code Compatibility• Magento API supports data versioning

• Collection API supports data versioning

• Magento\Db\Select except case with attribute table join;

Page 29: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 29

How to query values from attribute table• Do not use direct SQLs

• If you do not have other choice

Page 30: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 30

Example: how to query attributes from table

$metadata = $pool->getMetadata(ProductInterface::class);

$linkField = $this->metadata->getLinkField();

$connection->select()

->from(['e' => $entityTable], ['e.entity_id']);

->join(

['a' => $attributeTable],

'a.' . $linkField . ' = e.' . $linkField

);

Page 31: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 31

Summary

• Scheduling data changes

• Instant Preview

• Automatic changes deployment

Page 32: Magento 2.1 ee content staging

© 2016 Magento, Inc. Page | 32

Q&A