When editing a CMS page in Magento Enterprise Edition's admin panel, it's easy enough to make a mistake and accidentally remove a section of text or accidentally modify markup which may be a crucial part of the page's layout. While you may have back-ups to handle a situation like this, it can still be a time consuming process to retrieve and then restore the original content. However, using Magento's built-in version control system, you can conveniently restore your page to how it was at any time in the past, and also switch between different versions of a page with ease. In this post, we'll explain how this feature works and why you should use it.
How It Works
Version control is available for any CMS page in Magento Enterprise Edition (v1.8 and above). When version control is activated for a CMS page, an automatic backup is made every time that page is edited. These backups (called revisions) are organised by Magento, and are retained indefinitely, meaning the page can be reverted instantly to how it was at any time in the past. You can also maintain alternate versions of a page (seasonal variations, for example), and switch between them at any time.
Version control was added to Magento's CMS feature set in version 1.8, and being a relatively new feature it is one that many users may not be aware of yet. If you're used to Magento's standard CMS page editor, activating version control can be intimidating at first — the familiar "Content" and "Design" tabs are removed, and are replaced with a "Versions" tab with little explanation of what to do next. However, while it's true that activating version control will mean a few extra steps when updating your CMS pages, the benefits when managing complex changes can make it well worthwhile.
Setting Up Version Control for a CMS Page
For this example, we'll be using a standard installation of Magento Enterprise Edition. We'll activate version control for the About Us page, and then create a second version, where we'll change the main image on the page. We can then switch between these two versions instantly.
Preparation
In Magento's admin panel, go to CMS > Pages > Manage Content, and click on the About Us page. This brings up the Edit Page screen, where we can change the Under Version Control option to Yes.
Note that the Content, Design, and Meta Data tabs to the left have now been replaced with a new Versions tab.
The Versions tab shows the different versions of the page.
Versions and Revisions
While a version of a page is manually created by the administrator, a new revision is automatically created every time the page is modified. You can use versions if you are maintaining a page that has a number of significantly different variations, which you may need to switch between. On the other hand, revisions are mainly used to revert the page to how it was at an earlier date, if a mistake is made while updating the page. In our About Us page example, we'll create a new version with a different image.
Clicking on one of the entries on the Versions tab will show the list of revisions for this version.
At this point, the only version of this page has a version name of About Us, because the version name is copied from the page name by default. This name isn't shown to visitors, so it's a good idea to give it a more descriptive name that will help you remember what it's for. In our example, we'll call this version Original.
Editing the Page
Click on a revision to bring up the familiar CMS page editor. The editor shows you the name of the version, as well as the revision number that you're editing.
We'll turn off the WYSIWYG editor, and change the image by finding the line that reads:
<img title="Varien" src="{{skin url='images/media/about_us_img.jpg'}}" alt="Varien" />
and changing it to this:
<img title="Varien" src="{{skin url='images/media/col_left_callout.jpg'}}" alt="Varien" />
Saving Changes
Even though the editor says we're editing "Revision #1", if we click "Save", revision 1 won't be modified at all. Instead, Magento automatically creates a new revision (Revision #2) with our changes. This is the principle idea of version control - no data is lost with each change.
However, as we're making a fairly major change to this page, we want to create a new version, and not just a new revision in this version. We can quickly do this using the "Save in New Version" button, which will prompt us for a name for the new version. As the name entered here won't be shown to visitors, it should have a descriptive name that will explain what's unique about this version. In our example, because this version has a different image, we'll call it Alternate Image.
Publishing
After choosing "Save in New Version", we remain in the editor, and the page on the frontend hasn't been updated with our changes. Although the new "Version" has been saved, it still needs to be published before it's shown on the frontend. Clicking the "Publish" button will publish the page immediately (if there's any changes since the last save, this button will read "Save and Publish", which will create a new revision and publish at once).
After publishing the page, we are taken all the way back to the main Edit Page screen. The Currently Published Revision is now our Alternate Image version, at revision 1. This link is a handy shortcut that jumps straight back to the editor.
We can now view the page on the frontend, which will have our new image.
Recovering From Disaster
Let's say I was editing the page, and I accidentally deleted a paragraph while I was changing the image. I didn't notice initially, so I saved it and published it, and then I saw the missing text on the frontend. I can't remember what the text said, so normally I'd have to hope that I've got a backup somewhere.
However, because the page was under version control, I can just publish the "Original" version to restore the page to exactly how it was before I made my changes. Then, I'll delete the Alternate Image version, make my changes again as above (more carefully this time!), and finally publish the correct version.
Although it takes some getting used to and adds a few steps to the process of updating CMS page content, Magento's version control for CMS pages is incredibly useful. After taking the time to learn how it works, you may find it actually saves you time overall. After all, no matter how careful we are when editing important pages, we all make mistakes!