Update magento extension using direct package file upload - file already exists

magento, updates

Solution

Like Tim says, the correct way to install a newer version of a Magento extension package is by first running the uninstall option in MagentoConnect Manager to remove the old extension, and then running the install option to install from the newer package file.

Unfortunately this is the (poor) design of the MagentoConnect package manager feature.

Its also worth explaining what happens with any database modifications that the extension / package makes. Magento modules have no way to specify uninstall scripts or instructions. This means that after the original module / package is uninstalled, any database changes are still present and have NOT been removed. When the newer version of the module is reinstalled, this should trigger the module's DB upgrade scripts to run instead of it' install scripts.

So the detailed breakdown of what happens is the following:

When the module is originally installed from a package, the module's newest install script corresponding to the module version in config.xml is run, making any necessary database changes.

When the module is unistalled from MagentoConnect manager, the database is left as-is, so all changes the module made are still present in the DB.

When the newer version of the module is installed, the Magento database core_resource table tells the installer which version of the module was previously installed. The previous version and new version numbers are used to find an applicable database upgrade script in the module code. If the appropriate upgrade script is located, it is then run.

Problem

I have created a module, exported the extension and afterwords I have installed it (on a fresh store) using direct package file upload. The extension works as expected. Now, I have made some updates, exported the extension with another Release Version number, but when I try to upload the archive (in the same mode) I get an error ("CONNECT ERROR: Package file is invalid [..] './app/code/local/Smart2Pay/Globalpay/Block/Form/Pay.php' already exists") I read that I could alter some downloader\lib\Mage\Connect\Validator.php file (here) in order to permit file overwriting, but I want to know if there is any other best practice related solution. I need this extension update to work for all magento users.

Original source