© 2016 Magento, Inc. Page | 1
2.1 EE Content
Staging Technical
overview
© 2016 Magento, Inc. Page | 2
Software Architect at Magento
Anton Kaplya
© 2016 Magento, Inc. Page | 3
Agenda
• What is Content Staging
• How Content Staging works
• How to work with Content Staging
© 2016 Magento, Inc. Page | 4
Magento Staging
Scheduling data changes for ecommerce
entities
© 2016 Magento, Inc. Page | 5
What is Content Staging
• Scheduling data changes
• Instant Preview
• Automatic changes deployment
© 2016 Magento, Inc. Page | 6
© 2016 Magento, Inc. Page | 7
Magento Content Staging
© 2016 Magento, Inc. Page | 8
Magento Content Staging
© 2016 Magento, Inc. Page | 9
Magento Staging Dashboard
© 2016 Magento, Inc. Page | 10
Magento Content Staging Preview
© 2016 Magento, Inc. Page | 11
Supported Entities
• Products & Categories
• CMS Pages & Blocks
• Cart Price Rules
• Catalog Rule
© 2016 Magento, Inc. Page | 12
How Content Staging works
© 2016 Magento, Inc. Page | 13
MVCC
• Multiversion Concurrency Control
• InnoDB transaction engine is built upon MVCC
• Copy on change
© 2016 Magento, Inc. Page | 14
© 2016 Magento, Inc. Page | 15
MVCC
1 100 150 200
A
50 MAX
A'
A''
B
B'
C
© 2016 Magento, Inc. Page | 16
How MVCC influences Magento
• Entity may have several representations in main table
• Creation time
• Expiration time
© 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
© 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;
© 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;
© 2016 Magento, Inc. Page | 20
Creation of new entity
+--------+-----------+------------+------------+-----------+
| row_id | entity_id | created_in | updated_in | value |
+--------+-----------+------------+------------+-----------+
| 1 | 1 | 1 | 2147483647 | Green Car |
+--------+-----------+------------+------------+-----------+
© 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 |
+--------+-----------+------------+------------+-----------+
© 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 |
+--------+-----------+------------+------------+-----------+
© 2016 Magento, Inc. Page | 23
How select works
© 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 |
+--------+-----------+------------+------------+
© 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
);
© 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 |
+--------+-----------+------------+------------+-----------+
© 2016 Magento, Inc. Page | 27
How to work with
Content Staging
Short notice for extension developers
© 2016 Magento, Inc. Page | 28
Content Staging & Code Compatibility
• Magento API supports data versioning
• Collection API supports data versioning
• MagentoDbSelect except case with attribute table join;
© 2016 Magento, Inc. Page | 29
How to query values from attribute table
• Do not use direct SQLs
• If you do not have other choice
© 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
);
© 2016 Magento, Inc. Page | 31
Summary
• Scheduling data changes
• Instant Preview
• Automatic changes deployment
© 2016 Magento, Inc. Page | 32
Q&A

Magento 2.1 ee content staging

  • 1.
    © 2016 Magento,Inc. Page | 1 2.1 EE Content Staging Technical overview
  • 2.
    © 2016 Magento,Inc. Page | 2 Software Architect at Magento Anton Kaplya
  • 3.
    © 2016 Magento,Inc. Page | 3 Agenda • What is Content Staging • How Content Staging works • How to work with Content Staging
  • 4.
    © 2016 Magento,Inc. Page | 4 Magento Staging Scheduling data changes for ecommerce entities
  • 5.
    © 2016 Magento,Inc. Page | 5 What is Content Staging • Scheduling data changes • Instant Preview • Automatic changes deployment
  • 6.
    © 2016 Magento,Inc. Page | 6
  • 7.
    © 2016 Magento,Inc. Page | 7 Magento Content Staging
  • 8.
    © 2016 Magento,Inc. Page | 8 Magento Content Staging
  • 9.
    © 2016 Magento,Inc. Page | 9 Magento Staging Dashboard
  • 10.
    © 2016 Magento,Inc. Page | 10 Magento Content Staging Preview
  • 11.
    © 2016 Magento,Inc. Page | 11 Supported Entities • Products & Categories • CMS Pages & Blocks • Cart Price Rules • Catalog Rule
  • 12.
    © 2016 Magento,Inc. Page | 12 How Content Staging works
  • 13.
    © 2016 Magento,Inc. Page | 13 MVCC • Multiversion Concurrency Control • InnoDB transaction engine is built upon MVCC • Copy on change
  • 14.
    © 2016 Magento,Inc. Page | 14
  • 15.
    © 2016 Magento,Inc. Page | 15 MVCC 1 100 150 200 A 50 MAX A' A'' B B' C
  • 16.
    © 2016 Magento,Inc. Page | 16 How MVCC influences Magento • Entity may have several representations in main table • Creation time • Expiration time
  • 17.
    © 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
  • 18.
    © 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;
  • 19.
    © 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;
  • 20.
    © 2016 Magento,Inc. Page | 20 Creation of new entity +--------+-----------+------------+------------+-----------+ | row_id | entity_id | created_in | updated_in | value | +--------+-----------+------------+------------+-----------+ | 1 | 1 | 1 | 2147483647 | Green Car | +--------+-----------+------------+------------+-----------+
  • 21.
    © 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 | +--------+-----------+------------+------------+-----------+
  • 22.
    © 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 | +--------+-----------+------------+------------+-----------+
  • 23.
    © 2016 Magento,Inc. Page | 23 How select works
  • 24.
    © 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 | +--------+-----------+------------+------------+
  • 25.
    © 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 );
  • 26.
    © 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 | +--------+-----------+------------+------------+-----------+
  • 27.
    © 2016 Magento,Inc. Page | 27 How to work with Content Staging Short notice for extension developers
  • 28.
    © 2016 Magento,Inc. Page | 28 Content Staging & Code Compatibility • Magento API supports data versioning • Collection API supports data versioning • MagentoDbSelect except case with attribute table join;
  • 29.
    © 2016 Magento,Inc. Page | 29 How to query values from attribute table • Do not use direct SQLs • If you do not have other choice
  • 30.
    © 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 );
  • 31.
    © 2016 Magento,Inc. Page | 31 Summary • Scheduling data changes • Instant Preview • Automatic changes deployment
  • 32.
    © 2016 Magento,Inc. Page | 32 Q&A