Apply patches

The Magento Cloud Patches package delivers Magento patches and hot fixes, which improve the integration of all Magento Commerce versions with Cloud environments and supports quick delivery of critical fixes. The package can also deliver custom patches that you add to your project root directory.

The package is a dependency for the ece-tools package and is installed or updated when you install or update the ece-tools package version. You can also use and manage the as a stand-alone package for an existing Magento Commerce project.

When you deploy changes to the remote environment, ece-tools uses magento/magento-cloud-patches to check for pending patches and applies them automatically in the following order:

  1. Apply Magento-provided patches included in the magento/magento-cloud-patches package.
  2. Apply custom patches in the /m2-hotfixes directory in alphabetical order by patch name.

You can also apply patches manually.

All patch file names must end with the .patch extension.

Prerequisites

Before beginning an upgrade or a patching process, create an active branch from the Integration environment and checkout the new branch to your local workstation. Dedicating a branch to the upgrade or the patch process helps to avoid interference with your work in progress.

To apply the latest patches, install the latest version of ece-tools.

Apply patches manually

You can apply patches manually in a local environment and test them before you deploy.

To apply Magento Commerce Cloud patches manually:

  1. From the project root, apply the patches.

    1
    
    php ./vendor/bin/ece-tools patch
    
  2. Clear the Magento cache.

    1
    
    php ./bin/magento cache:clean
    

    You can also clean the cache using the Magento Admin Cache Management.

  3. Test the patches, make any necessary changes to custom patches.

Apply a custom patch

When you deploy, ece-tools applies all Magento patches and any custom patches that you add to the /m2-hotfixes directory in the Magento project root.

To apply and test a custom patch:

  1. In the project root, create a directory called m2-hotfixes if it does not exist

    1
    
    mkdir m2-hotfixes
    
  2. Copy the patch file to the /m2-hotfixes directory.

  3. Add, commit, and push code changes.

    1
    
    git add -A
    
    1
    
    git commit -m "Apply patch"
    
    1
    
    git push origin <branch-name>
    

    Make sure to test all patches in a pre-production environment. For Magento Cloud, new branches can be created with magento-cloud environment:branch <branch-name>

Apply patches to a Magento enterprise or open source project

You can use Magento Cloud Patches as a stand-alone package to apply Magento patches and hot fixes to a Magento project that is not deployed on the Cloud platform.

To use magento-cloud-patches as a stand-alone package:

  1. Add the magento-cloud-patches package to your composer.json file.

    1
    
    composer require magento/magento-cloud-patches
    
  2. From the project root, apply the patches.

    1
    
    php ./vendor/bin/ece-tools patch
    

    This command applies Magento patches and any custom patches found in the /m2-hotfixes directory.

  3. Clear the Magento cache.

    1
    
    php ./bin/magento cache:clean
    

    You can clean the cache using the Magento Admin Cache Management.

  4. Test the patches, and make any necessary changes to custom patches.