Tools to boost Magento upgrade or patch process

Upgrading or patching the Magento store can be painful, with many file changes, updates, and modifications that can potentially not be compatible with extensions and custom additions done for the project. Manual searches for changes and updates can take forever. This demotivates patching and upgrading the store frequently, which can lead to security issues and legacy code that no one wants to touch. In this article, we will explore tools that will help you or even automate the upgrade process. 

Rector

PHP Rector (https://github.com/rectorphp/rector) is a powerful automation tool that helps you upgrade, refactor, and improve PHP code with support for Laravel, Symfony, and Magento. Rector supports you in updating your PHP code to the latest standards by using modern PHP functions and syntax. It’s especially useful for upgrading your codebase—for instance, moving from PHP 8.1 to 8.3. It will automatically change the code: remove usage of the decrypted code and add usage of new features from the language. With proper rules set, it can also remove dead code and rename methods, which makes cleaning up legacy code much faster. Thanks to Rector, your codebase will not only be compatible with the new PHP version but also will be refactored to remove legacy. 

For example, you have such code:

class Product {

    public function getName($product) {

        return $product->getName();

    }

}

It can automatically update it:

class Product {

    public function getName(ProductInterface $product): string {

        return $product->getName();

    }

}

Much safer!

Rector uses a config file to set all rules and exclude unnecessary ones (some default rules break Magento code, as Reactor doesn’t understand XML configs that Magento uses).

Thankfully, Rector is already available in Magento code with custom rules and configs specific to Magento.

Here is a config prepared by the Magento team: https://github.com/magento/magento-coding-standard/blob/develop/rector.php

With the config done, you can use `vendor/bin/rector app/code` to update the project codebase. Firstly, you can use the option –dry-run to check what will be changed.

Rector is a great tool for major upgrades, like when you’re switching to a new PHP version. For smaller patches, it might feel a bit overwhelming, but there’s a solution for that too.

Ampersand’s Upgrade Patch Helper

This useful tool (https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper) can help you quickly gather what changed in the updated code to make sure to reflect these code changes that you modified.

It compares what changed between two versions of the vendor and then analyzes changes in the app/code to point out which files need to be updated to be compatible with the new changes in the vendor. The best part about it? It checks all files, not only PHP, and it can be used to update third-party modules too, not only Magento core. 

With a list of files changed and information on what was changed, you can simply go through the list and make the necessary updates. This saves a lot of time by going through files one by one and checking if there is any update in the vendor directory.

Upgrade Compatibility Tool

For Adobe Commerce, there is an official tool from Adobe that helps with upgrading Commerce stores. It can analyze module compatibility, database, or GraphQL updates. It can also do some refactoring automatically. It’s a great tool to use if you’re working with the commercial version of Magento. 

Blue Finch Patch

There are also commercial products like https://www.bluefinchcommerce.com/patch that automate the upgrade process to simply returning a GitHub PR with upgraded code. 

All those upgrade helpers can speed up the process, but still, you need to be extra careful and test the store with a good set of automated and manual tests that touch all the used functionalities. Do updates frequently; it pays off with a free state of mind. Smaller updates are easier to manage, and they also keep the store secured with the latest security patches. It rewards you by saving you from headaches down the road.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.