Top Banner
18

MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

May 15, 2018

Download

Documents

lexuyen
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event
Page 2: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

MAGENTO 2 CONTENTUNDER VERSION CONTROL

Gordon Lesti

• Student

• @GordonLesti

• gordonlesti.com

Page 3: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

Typical scenario

• content of a CMS page isn’t decoupled from styles

• content of a CMS page is large and confusing

• content manager tries to change a CMS page

• the layout is destroyed

• nobody knows why

Page 4: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

Possible solutions

Database backups

• hopefully one with the last stable content

• time consuming and complicated to restore

• has to be done by a developer

CMS pages under version control

• has every version of the content

• can be restored in seconds

• can be done by a content manager in the backend

Page 5: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

Example - Wordpress

• it’s called revision

• every save creates a new rowin the database

• versions can be compared

• older versions can be restoredeasily

Page 6: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

Is that possible with Magento 2?

Page 7: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

ContentVersion

• Magento 2 content under version control

• https://github.com/GordonLesti/ContentVersion

• MIT License

Page 8: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

Installation

• Add the repository to the repositories section of your composer.json file

"repositories": [

{

"type": "vcs",

"url": "[email protected]:GordonLesti/ContentVersion.git"

}

],

• Require the module and install

composer require lesti/module-content-version:dev-master

Page 9: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

Example - ContentVersion

• creates version with eventcms page save after

• send Ajax request to compareversion x with y

• sebastian/diff compares xwith y

• send Ajax response with thediff back to client

Page 10: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

Possible feature plan

• version for more model properties• Title• ...

• version control for other models• CMS blocks• ...

• restore versions

• store the saving admin user

• save x last versions

Page 11: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

Feel free to contribute!

Page 12: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

How does diff algorithm work?

Different approaches for different purposes

• maximize matching lines

• maximize size of the biggest matching subsequence

• ...

Page 13: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

Example - diff algorithm

from toM Me ee et tM Ma ag gn ee nt to o?

Page 14: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

Create matrix from × to

For all i = {1, . . . , |from|} , j = {1, . . . , |to|}• ai ,j = max {ai−1,j−1, ai−1,j , ai ,j−1}• if fromi == toj and ai ,j == ai−1,j−1 then

ai ,j = ai ,j + 1

Page 15: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

M e e t M a g n e t o ?M 1 1 1 1 1 1 1 1 1 1 1 1e 1 2 2 2 2 2 2 2 2 2 2 2e 1 2 3 3 3 3 3 3 3 3 3 3t 1 2 3 4 4 4 4 4 4 4 4 4M 1 2 3 4 5 5 5 5 5 5 5 5a 1 2 3 4 5 6 6 6 6 6 6 6g 1 2 3 4 5 6 7 7 7 7 7 7e 1 2 3 4 5 6 7 7 8 8 8 8n 1 2 3 4 5 6 7 8 8 8 8 8t 1 2 3 4 5 6 7 8 8 9 9 9o 1 2 3 4 5 6 7 8 8 9 10 10

Page 16: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

Find ADDs, REMOVE s and MATCHs

• start at ai ,j

• end at a1,1

• prefer maximum or diagonal if there is more than one maximum value

• every step• left is a ADD• top is a REMOVE• diagonal is a MATCH

for the current position

Page 17: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

M e e t M a g n e t o ?M 1 1 1 1 1 1 1 1 1 1 1 1e 1 2 2 2 2 2 2 2 2 2 2 2e 1 2 3 3 3 3 3 3 3 3 3 3t 1 2 3 4 4 4 4 4 4 4 4 4M 1 2 3 4 5 5 5 5 5 5 5 5a 1 2 3 4 5 6 6 6 6 6 6 6g 1 2 3 4 5 6 7 7 7 7 7 7e 1 2 3 4 5 6 7 7 8 8 8 8n 1 2 3 4 5 6 7 8 8 8 8 8t 1 2 3 4 5 6 7 8 8 9 9 9o 1 2 3 4 5 6 7 8 8 9 10 10

Page 18: MAGENTO 2 CONTENT - gordonlesti.com · content manager tries to change a CMS page ... Magento 2 content under version control ... creates version with event

Thanks for listening