You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
* MAGEDOC-3956: Added new how to topic to install guide
* MAGEDOC-3956: Moved content to existing patch topic
* MAGEDOC-3956: Replaced 2.3 file with symlink
* MAGEDOC-3956: Reorg topic sections
* MAGEDOC-3956: Minor wordsmithing
* Fixed up headers.
This topic discusses the workflow for applying a patch to your Magento application.
8
+
{:.bs-callout-warning}
9
+
We strongly recommend that test all patches in a staging/development environment before deploying to production. We also strongly recommend that you back up your data before applying a patche. See [Back up and roll back the file system][].
9
10
10
-
We strongly recommend that patches be tested in a staging/development environment before being deployed to production.
11
+
## How patches work
11
12
12
-
## First: backup your data
13
+
There are two types of patches:
13
14
14
-
We also strongly recommend that you back up your data before any patches are applied.
15
-
To back up your data, refer to [Back up and roll back the file system][].
15
+
-**Official patches**—patches that Magento publishes on the [Magento Security Center][].
16
+
-**Custom patches**—unofficial patches that you can create from a git commit.
16
17
17
-
## Get the patch
18
+
Patch (or diff) files are text files that note:
18
19
19
-
Magento patches can be found in the [Magento Security Center][]. Follow the instructions on the page to download the patch file, depending on your version and installation type.
20
+
- The file(s) to be changed.
21
+
- The line number to begin the change and the number of lines to be changed.
22
+
- The new code to swap in.
20
23
21
-
## How patches work
24
+
When the [patch][] program is run, this file is read in and the specified changes are made to the file(s).
22
25
23
-
Patch (or diff) files are text files that note:
26
+
## Official patches
24
27
25
-
* The file(s) to be changed.
26
-
* The line number to begin the change and the number of lines to be changed.
27
-
* The new code to swap in.
28
+
You can find official Magento patches in the [Magento Security Center][]. Follow the instructions on the page to download the patch file, depending on your version and installation type.
28
29
29
-
When the [patch][] program is run, this file is read in and the specified changes are made to the file(s).
30
+
## Custom patches
31
+
32
+
Sometimes it takes a while for the Magento Engineering Team to include a bug fix made on GitHub in a Magento 2 Composer release. In the meantime, you can create a patch from GitHub and use the [`cweagans/composer-patches`][1] plugin to apply it to your Composer-based Magento 2 installation.
33
+
34
+
There are many ways to create patch files. The example below focuses on creating a patch from a known commit.
35
+
36
+
To create a custom patch:
37
+
38
+
1. Create a `patches/composer` directory in your local project.
39
+
1. Identify the GitHub commit or pull request to use for the patch. This example uses the [`2d31571`][2] commit, linked to Magento 2 GitHub issue [#6474][3].
40
+
1. Append the `.patch` or the `.diff` extensions to the commit URL. Use `.diff` for a smaller file size. For example: [https://github.com/magento/magento2/commit/2d31571f1bacd11aa2ec795180abf682e0e9aede.diff][4]
41
+
1. Save the page as a file in the `patches/composer` directory. For example, `github-issue-6474.diff`.
42
+
1. Edit the file and remove `app/code/<VENDOR>/<PACKAGE>` from all paths so that they are relative to the `vendor/<VENDOR>/<PACKAGE>` directory.
43
+
44
+
{:.bs-callout-info}
45
+
Text editors that automatically remove trailing whitespace or add new lines can break the patch. Use a simple text editor to make these changes.
46
+
47
+
The following example shows the previously mentioned diff file after removing all instances of `app/code/Magento/Payment`:
1. Upload the local file into the `<Magento_root>` on the server using FTP, SFTP, SSH or your normal transport method.
34
73
1. Login to the server as the [Magento admin user][] and verify the file is in the correct directory.
35
74
1. In the command line interface, run the following commands according to the patch extension:
36
75
37
-
patch < patch_file_name.patch
76
+
```bash
77
+
patch < patch_file_name.patch
78
+
```
38
79
39
80
The command assumes the file to be patched is located relative to the patch file.
40
81
41
-
{: .bs-callout-info}
42
-
If the command line shows: `File to patch:`, it means it cannot locate the intended file, even if the path seems correct.
43
-
In the box displayed in the command line terminal, the first line shows the file to be patched.
44
-
Copy the file path and paste it into the `File to patch:` prompt and press `Enter` and the patch should complete.
82
+
{: .bs-callout-info}
83
+
If the command line shows: `File to patch:`, it means it cannot locate the intended file, even if the path seems correct. In the box displayed in the command line terminal, the first line shows the file to be patched. Copy the file path and paste it into the `File to patch:` prompt and press `Enter` and the patch should complete.
45
84
46
-
5. For the changes to be reflected, refresh the cache in the Admin under **System** > Tools > **Cache Management**.
85
+
1. For the changes to be reflected, refresh the cache in the Admin under **System** > Tools > **Cache Management**.
47
86
48
87
Alternatively, the patch can be applied locally with the same command, then committed and pushed normally.
49
88
50
-
## Using Composer to install patches
89
+
### Composer
90
+
91
+
{:.bs-callout-warning}
92
+
Always perform comprehensive testing before deploying any custom patch.
93
+
94
+
To apply a custom patch using Composer:
95
+
96
+
1. Open your command line application and navigate to your project directory.
97
+
1. Add the `cweagans/composer-patches` plugin to the `composer.json` file.
98
+
99
+
```bash
100
+
composer require cweagans/composer-patches
101
+
```
102
+
103
+
1. Edit the `composer.json` file and add the following section to specify:
104
+
-**Module:***\"magento/module-payment\"*
105
+
-**Title:***\"MAGETWO-56934: Checkout page freezes when ordering with Authorize.net with invalid credit card\"*
106
+
-**Path to patch:***\"patches/composer/github-issue-6474.diff\"*
51
107
52
-
It is possible to install a patch with Composer, but it takes a few more steps.
53
-
Please refer to the [Magento Help Center][] for details on how to use Composer to do patch installation.
108
+
For example:
109
+
110
+
```json
111
+
"extra": {
112
+
"composer-exit-on-patch-failure": true,
113
+
"patches": {
114
+
"magento/module-payment": {
115
+
"MAGETWO-56934: Checkout page freezes when ordering with Authorize.net with invalid credit card": "patches/composer/github-issue-6474.diff"
116
+
}
117
+
}
118
+
}
119
+
```
120
+
121
+
If a patch affects multiple modules, you must create multiple patch files targeting multiple modules.
122
+
123
+
1. Apply the patch. Use the `-v` option only if you want to see debugging information.
124
+
125
+
```bash
126
+
composer -v install
127
+
```
128
+
129
+
1. Update the `composer.lock` file. The lock file tracks which patches have been applied to each Composer package in an object.
[Magento Help Center]:https://support.magento.com/hc/en-us/articles/360005484154-Create-a-patch-for-a-Magento-2-Composer-installation-from-a-GitHub-commit
0 commit comments