Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento
front end book you'll ever need. Get your copy
today!

If you’ve followed my work here, on Stack Overflow, or on Twitter, you know I have a perpetual bee in my bonnet over Magento Connect’s file permissions issues. There’s a few common cases where Magento Connect will tell you an extension is installed, but in actuality Connect couldn’t install the extension because of insufficient file permissions. Permissions are always a thorn in a developer’s side — but the Connect application’s willingness to lie to its users about an extension being installed crosses some invisible line of unacceptable behavior.

The Magento 2 team at eBay is aware of the problem, and working on it, but that leaves working Magento developers with the problem of never knowing what’s actually installed when clients or customers use Magento Connect. That’s why I’ve created a new command for n98-magerun called extension:validate. Today we’ll cover how to use the command, as well as discuss some implementation details so you understand what the command is doing.

Using the Command

The extension:validate command requires no arguments. If you run it you’ll see something like this

When invoked with no options, extension:validate will look at all the third party Magento Connect extensions a user has installed on their system, and validate their contents against the package.xml manifest.

In the above example, our system has the Magento Connect extensions Customchecoutstep, Pulsestorm_Commercebug, and Auctionmaid_Matrxrate installed. Customchecoutstep and Pulsestorm_Commercebug were fine, but the Auctionmaid_Matrxrate was missing a file (Webshopapps_Matrixrate.xml), and one of the files didn’t match the stored hash (config.xml). Not matching the stored hash means the file’s been modified/edited.

Troubleshooting Connect Details

While this tool is useful, it’s not a cure all. Once you’ve detected problems with an extension you’ll need to figure out why they happened. In other words, are they real problems or intended changes from more reckless developers. There’s a good chance the original package for an extension will be in the

downloader/.cache/community/

folder. This where Magento Connect downloads the packages prior to installing them. Copying a package from here and extracting the files will let you replace missing files or run a diff to see what’s changed.

The extension:validate command reads the package information from the

downloader/cache.cfg

file. Despite being named cache.cfg, this really isn’t a cache file — it’s the file Magento Connect reads from when it lists out the installed packages on the system, and effectively acts as the source of truth for what is and isn’t installed.

If I speculate, the reason this file is named cache is it’s a cached list of what’s installed on the system. In other words the entire Magento system itself is the actual thing, and this file is just a cache. However, this falls apart when you consider there’s no way to query the Magento system itself for a list of installed packages, and the Magento Connect downloader always reads from this file. Another example of “The best laid plans …” problem.

Command Options

The extension:validate command will also let you check a single extension. Just pass in the extension’s name as the first argument

This is useful to run right after you’ve installed an extension to make sure it’s installed correctly. Keep in mind you need to use the Magento Connect Name for an extension, and not the Namespace_Modulename module name. (Auctionmaid_Matrxrate vs Webshopapps_Matrixrate above)

If you only want to do a specific type of check — that is only check if a file is missing, or if the hash matches — there’s options to skip each test type.

Magento Connect for Upgrades

In addition to installing third party extensions, Magento Connect’s other big feature is enabling package based updates of the Magento system itself. It does this by having the following 36 packages installed by default when you initialize a Magento Connect system.

This has always struck me as a little bit crazy. Because Magento Connect installations aren’t transactional, this creates a situation where an install that fails due to network connectivity issues or un-handled corner cases can leave a Magento installation in a “half-upgraded” state. If you’ve spent any time on the Magento forums or the various Stack Exchange sites, you know this is more than a theoretically concern.

Regardless, if you or your client are managing upgrades via Magento Connect, you may include these packages with the --include-default flag.

$ n98-magerun extension:validate --include-default

Be warned though, since it’s effectively running through every Connect managed file in your Magento application it’ll take a bit longer to finish. This is also a potentially useful way to keep your application “core hack” free. Finally, these extension names are hard-coded into the extension:validate command. If Magento adds any packages in the future, extension:validate will see them as 3rd party extensions until the n98-magerun command is updated with a new extension list. If anyone know a way to query something for a list of official packages, pull requests are welcome.