{"id":6468,"date":"2024-12-27T12:21:17","date_gmt":"2024-12-27T10:21:17","guid":{"rendered":"https:\/\/www.h-hennes.fr\/blog\/?p=6468"},"modified":"2024-12-27T12:22:13","modified_gmt":"2024-12-27T10:22:13","slug":"magento-2-gagner-du-temps-sur-la-creation-de-vos-datapatch","status":"publish","type":"post","link":"https:\/\/www.h-hennes.fr\/blog\/2024\/12\/27\/magento-2-gagner-du-temps-sur-la-creation-de-vos-datapatch\/","title":{"rendered":"Magento 2 : Gagner du temps sur la cr\u00e9ation de vos DataPatch"},"content":{"rendered":"\n<p>Les datapatches magento permettent de d\u00e9ployer rapidement des changements sp\u00e9cifiques via un module sur l\u2019ensemble des environnements de votre projet de mani\u00e8re automatique.<\/p>\n\n\n\n<ul>\n<li>\u2028Ils sont rang\u00e9s dans le dossier <em>Setup\/Patch\/Data<\/em> de votre module et ils impl\u00e9mentent l\u2019interface <em>\\Magento\\Framework\\Setup\\Patch\\DataPatchInterface<\/em><\/li>\n<li>Il sont appliqu\u00e9s automatiquement si n\u00e9cessaire uniquement lors de l\u2019ex\u00e9cution de la commande <strong>bin\/magento setup:upgrade<\/strong><\/li>\n<\/ul>\n<p>Dans le cas de la r\u00e9alisation de patchs complexes il peut \u00eatre n\u00e9cessaire de les rejouer plusieurs fois pour v\u00e9rifier que tout fonctionne correctement.<br \/>\u2028La proc\u00e9dure \u00e0 effectuer est la suivante :<\/p>\n<ol>\n<li>Suppression du patch dans la base de donn\u00e9es dans la table patch_list<\/li>\n<li>Ex\u00e9cution de la commande bin\/magento setup:upgrade<\/li>\n<\/ol>\n<p>\u2028Cette proc\u00e9dure est relativement lente comme l\u2019ex\u00e9cution du setup:upgrade est longue, car magento r\u00e9alise pleins d\u2019op\u00e9rations autres que l\u2019application des patches.\u2028<\/p>\n<p>Nous allons voir ici comment gagner du temps \u00e0 cette \u00e9tape.\u2028\u2028<\/p>\n<p>Nous allons utiliser une fonctionnalit\u00e9 qui est propos\u00e9e par l\u2019indispensable commande console n98-Magerun2 , que vous pouvez t\u00e9l\u00e9charger ici : <a href=\"https:\/\/github.com\/netz98\/n98-magerun2\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/netz98\/n98-magerun2 \u2028\u2028<\/a><br \/>La commande qui nous int\u00e9resse est <strong>dev:console<\/strong> .<br \/>\u2028Celle-ci permets d\u2019ex\u00e9cuter du code php directement dans la console, et utilise <a href=\"https:\/\/psysh.org\/\" target=\"_blank\" rel=\"noopener\">https:\/\/psysh.org\/<\/a> en technologie.<\/p>\n\n\n\n<p>Voici comment faire pour lancer directement votre data patch via ce biais<\/p>\n\n\n\n<p>On se rends dans la console<\/p>\n\n\n\n<pre lang=\"bash\">php n98-magerun2.phar dev:console<\/pre>\n\n\n\n<p>Dans la console : <br>\u2028On va charger la classe de notre dataPatch, puis on va appliquer la m\u00e9thode apply<br>\u2028Par exemple :<\/p>\n\n\n\n<pre lang=\"phg\">\n$patch = $di->create(\\Vendor\\Module\\Setup\\Patch\\Data\\DataPatchModule::class); \u2028\n$patch->apply()\n<\/pre>\n\n\n\n<p>Via ce biais plus besoin de perdre du temps \u00e0 attendre l\u2019\u00e9x\u00e9cution de la commande bin\/magento stup:upgrade \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Les datapatches magento permettent de d\u00e9ployer rapidement des changements sp\u00e9cifiques via un module sur l\u2019ensemble des environnements de votre projet de mani\u00e8re automatique. \u2028Ils sont rang\u00e9s dans le dossier Setup\/Patch\/Data de votre module et ils impl\u00e9mentent l\u2019interface \\Magento\\Framework\\Setup\\Patch\\DataPatchInterface Il sont appliqu\u00e9s automatiquement si n\u00e9cessaire uniquement lors de l\u2019ex\u00e9cution de la commande bin\/magento setup:upgrade Dans le [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[246],"tags":[610,612,482,611],"class_list":["post-6468","post","type-post","status-publish","format-standard","hentry","category-magento-2","tag-datapatch","tag-dev-console","tag-magento-2","tag-magerun2"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/posts\/6468","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/comments?post=6468"}],"version-history":[{"count":2,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/posts\/6468\/revisions"}],"predecessor-version":[{"id":6470,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/posts\/6468\/revisions\/6470"}],"wp:attachment":[{"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/media?parent=6468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/categories?post=6468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/tags?post=6468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}