Skip to content

Instantly share code, notes, and snippets.

@grafikchaos
Last active December 18, 2015 04:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grafikchaos/b14bf2c3158d214d6568 to your computer and use it in GitHub Desktop.
Save grafikchaos/b14bf2c3158d214d6568 to your computer and use it in GitHub Desktop.
Creating a diff file to upgrade Magento

Before you begin

Read Aaron Hawks' blog post for the original idea for this gist.

While this process should theoretically work to upgrade the core/default files that come with Magento from any old version to the most recent version (as long as they're in the same distribution, i.e., Community to Community or Enterprise to Enterprise), you should always refer to Magento's release notes and upgrade paths for the version you're upgrading to for full details and work flow. This is the process I used to go from Magento EE 1.12.0.2 to Magento EE 1.13.0.1 directly ( skipping over 1.13.0.0 due to the instructions outlined in this Magento article and release notes ).


Upgrade Pre-Requisites

Below is an excerpt of the pre-requisites I followed from Magento's upgrade instructions

Getting Ready For Your Upgrade

This section discusses how to get ready for your upgrade by backing up the database and customizations on the file system. The steps that follow do not affect your current production system. You can continue serving customers with no downtime.

To get ready for your upgrade:

  1. Get the Magento installation archive as discussed in Getting Magento CE 1.8 or EE 1.13.
  2. Set up a parallel system for deploying and testing the upgrade; in other words, set up a system identical to the one you have now.
  • The system must meet the Magento system requirements.
  1. Magento strongly recommends you observe the following guidelines when you set up the Magento database in your development environment:
  • Magento for the first time uses MySQL database triggers to improve database access during reindexing. Magento does not support any custom triggers in the Magento database because custom triggers can introduce incompatibilities with future Magento versions.
  • Familiarize yourself with these potential MySQL trigger limitations before you continue.
  • If you use MySQL database replication, Magento does not support MySQL statement-based replication. Make sure you use only row-based replication.
  • Review the MySQL recommendations for MySQL password security.
  1. Complete the tasks discussed in the following sections in the order shown:

Pre-Upgrade Tasks For Your Production Environment

Complete the tasks discussed in the following sections in the order shown:

  1. Enabling Exception Logging
  2. Setting All Indexers for Update on Save
  3. Backing Up the Database
  4. Archiving Customizations and Extensions
  5. Restoring Configuration Settings

Enabling Exception Logging

Before you start your upgrade, you should enable exception logging so it will be enabled on the development system. Without exception logging, it will be more difficult to diagnose errors during your upgrade. You can disable exception logging after you've exported the Magento database.

To enable exception logging:

  1. Log in to the Admin Panel as an administrator.
  2. Click System > Configuration.
  3. In the ADVANCED group, click Developer.
    This enables you to enable exception logging so you'll see exceptions in the development environment after the upgrade.
  4. In the right pane, click Log Settings to expand it.
    The following figure shows an example. Enable Exception Logging

Setting All Indexers for Update on Save (EE only)

This section applies to Magento EE 1.13 only. Skip this section if you're using Magento CE.

Because of the changes to indexing in Magento EE 1.13, you must set all indexers to update on save before you upgrade; otherwise, unpredictable performance will result. You can revert indexer settings after you've exported the Magento database.

To set indexers to update on save:

  1. Click System > Index Management.
  2. On the top left corner of the row, click Select All to select all indexers.
  3. From the Options list, click Change indexing mode.
    The Index Mode list displays.
  4. From the Index Mode list, click Update on Save.
    The following figure shows an example
    Update on Save index mode
  5. At the top right corner, click Submit.
  6. Make sure all indexers are now set for Update on Save as the following figure shows.
    Update on Save index mode desired example

Backing up the database

Back up your database using mysqldump or another tool. mysqldump syntax follows:

# mysqldump syntax for large database dumps
mysqldump --opt -Q --order-by-primary -u root -p my_magento_db > my_magento_db_dump.sql

Archive Customizations and Extentions

To archive your custom themes and extensions:

  1. Archive the Magento media directory and all subdirectories. For example,
    cd magento-install-dir && tar -czf media.tgz media
  2. Archive any custom theme packages in the magento-install-dir/app/design/frontend and magento-install-dir/skin/frontend directories.
    You may also need to check the magento-install-dir/js directory for files related to local or community modules.
  3. Archive any customizations or extensions in the magento-install-dir/app/code/local and magento-install-dir/app/code/community directories.
  4. Transfer the archives you just created to the development environment.
  5. Copy magento-install-dir/app/etc/local.xml and magento-install-dir/app/etc/session.xml (if any) to your development upgrade environment.

Restore Configuration Settings

After you've exported the Magento database and extensions, you can revert the configuration changes you made as discussed in these sections:

  • Enabling Exception Logging
  • Setting All Indexers for Update on Save (EE only)

Make sure that logging is disabled again when in the production environment

Pre-Upgrade Tasks For Your Development Environment

In your development enviroment:

  1. Start a new feature or topic branch in your version control system of choice. We use git-flow so you should do the following:
    git flow feature start enterprise-1.13.0.1
    and obviously replace enterprise-1.13.0.1 name with an appropriate branch name of your choosing.
    DO NOT EVEN THINK ABOUT DOING THIS IN THE develop branch! IF you do, you are on your own for fixing whatever issues may come from it. Seriously.
  2. Back up your development database. Refer to the Backing up the database section above or do something along the lines of
    mysqldump --opt -Q --order-by-primary -u root -p my_magento_dev_db > my_magento_dev_db_dump.sql
  • You may also consider setting up a new database that we'll import the production database into. It's up to and completely optional

Upgrading the File System and Database to Magento CE 1.8 or EE 1.13

Upgrade your Magento installation by completing all of the following tasks in the order shown:

  1. Upgrade Requirements
  2. Upgrading Assets on the Magento File System
  3. Upgrading the Magento Database
  4. Finishing the File System

Upgrade Requirements

Before attempting your Magento upgrade, complete all the tasks discussed in:

Upgrading Assets on the Magento File System

Now comes the fun part of updating Magento's file system while avoiding overwriting your customizations and extensions. The easiest way I've found to do this is with Aaron Hawks' Creating a diff file to upgrade Magento blog post. Keep in mind that it's typically easier to upgrade if you have been good about updating with each release of Magento, but you may be able to jump a couple versions if it's safe to do so. Again, refer to Magento's upgrade path instructions for your version of Magento.

Creating the diff file

To create a diff file between two different versions of Magento you'll need to do the following:

  • Make sure you have diff installed on your machine.
    • if you're using Linux or Mac OS X, you will most likely already have it installed
    • if you're using Windows, let me google that for you
  • Download clean copies of both versions
    • Magento Community Edition Release Archive (click on the Release Archive tab to see available releases)
    • Magento Enterprise Edition — either you or the client will need to have an account with access to Magento's Enterprise Edition download section.
  • Un-zip and un-tar the files and optionally rename the directories
tar -zxvf enterprise-1.12.0.2.tar.gz
mv magento magento-1.12.0.2
tar -zxvf enterprise-1.13.0.1.tar.gz
mv magento magento-1.13.0.1
  • Now you should have 2 directories... diff them and then you will have your diff file that we'll use to "patch" your Magento installation.
diff -ruN magento-1.12.0.2 magento-1.13.0.1 > enterprise-1.12.0.2-1.13.0.1.diff
  • Next you are going to need to patch your current code using the diff file you just created and replace with the appriately named paths to your Magento project directory and diff file. Remember, this should be done in a feature or topic branch instead of your main branch (e.g., develop).
cd /path/to/my/magento/project
patch -p1 < /path/to/my/enterprise-1.12.0.2-1.13.0.1.diff

If you created your diff file from two clean copies of Magento, then your patch file should only affect files/assets distributed by Magento and leave all customizations and extensions alone. You'll still need to test the upgrade, but we'll address that a bit later.

Upgrading the Magento Database

Before you import your production database dump into either your existing development database (which you should have backed up by now) or a new temporary development database you need to run a couple search and replace commands to set the unsecure web/unsecure/base_url and secure web urls web/secure/base_url (and any other config data that's specific to your project).

The following is perl's search and replace syntax. It's the quickest and easiest search and replace method I've seen or used so far.

Syntax:

perl -pi -e 's/oldstring/newstring/g' target_file
  • The s tells perl we're doing a search and replace
  • The forward slashes / separate the strings we wish to search and replace from the s command and g arguments. Use back slashes \ to escape characters (i.e., / . : ? *).
  • The g is the argument that tells to perl to do a global search and replace for the strings throughout the target_file
  • The target_file is the file you wish to make the changes to (e.g., my_magento_db_dump.sql)

Example:

perl -pi -e 's/http\:\/\/example\.com/http\:\/\/magex\.dev/g' my_magento_db_dump.sql
perl -pi -e 's/https\:\/\/example\.com/http\:\/\/magex\.dev/g' my_magento_db_dump.sql

It's important that you search for the full urls and not just the domain name or you will end up affecting email addresses as well.

You can now import your production database into the development database.

Finishing the File System

  • Check your app/etc/local.xml still has valid connection parameters.
  • Fix file permissions
find . -type f -exec chmod 644 {} \;
  • Fix directory permissions
find . -type d -exec chmod 755 {} \;
  • Make the var and media directories and subdirectories world-writable
chmod -R 777 media var var/.htaccess

Completing the Magento Upgrade

You should refer to the Magento directions for detailed instructions as that can vary from version to version. For example, read the instructions for Magento EE 1.13.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment