Attention

This document was written for an unsupported version of Plone, Plone 2.5.x, and was last updated 898 days ago.

For more information, see the version support policy.

To learn how to upgrade to the current version of Plone, read the upgrade manual.

Uninstall with GenericSetup

by Anton Stonor last modified Dec 06, 2009 09:27 PM
How to remove configuration profiles with Generic Setup

So far you have probably read the other documentation describing how to add configuration to a Plone site with GenericSetup. But what if you want to remove it again? Typically any Plone Product author want to offer uninstall of his project.
Fortunately, GenericSetup allows you to pinpoint and remove selected elements. From a high level you do this:

  • create an additional GenericSetup profile with the name "uninstall" - many times you can just copy the "default" profile
  • Sprinkle remove="True" attributes around the XML files
  • Wire the uninstall profile up with the Install.py of your product if you like.

How to create an uninstall profile

Imagine a profile that configures a custom portal type, e.g. the following lines in types.xml and the corresponding MyType.xml

<?xml version="1.0"?>
<object name="portal_types" meta_type="Plone Types Tool">
<object name="MyType"
meta_type="Factory-based Type Information with dynamic views"/>
</object>
Now, copy the types.xml over to the a new profile directory called uninstall and alter it a bit:
<?xml version="1.0"?>
<object name="portal_types" meta_type="Plone Types Tool">
<object name="MyType"
meta_type="Factory-based Type Information with dynamic views" remove="True" />
</object>
That's it. Run the new profile and it will remove the MyType configuration.

If you like, you can clean it up a bit:
<?xml version="1.0"?>
<object name="portal_types">
<object name="MyType" remove="True"/>
</object>

What works and what doesn't yet

The magic "remove" attribute has been implemented for many of the GenericSetup handlers, but not all of them.

Remove works for these handlers:
  • Skins
  • Types
  • Workflows
  • Catalog indexes

It does not work for these -- yet:
  • Actions
  • Properties
  • Configlets

I haven't tested with the rest of the handlers.


Wiring up the Quick Installer

You can wire up the uninstall profile with Quick Installer the same way as you wire up a normal install profile, e.g.

from Products.CMFCore.utils import getToolByName

def uninstall(portal):
setup_tool = getToolByName(portal, 'portal_setup')
setup_tool.setImportContext('profile-MYPRODUCT:uninstall')
setup_tool.runAllImportSteps()
setup_tool.setImportContext('profile-CMFPlone:plone')
return "Ran all uninstall steps."
Until all the GenericSetup handlers support the "remove" attribute, you might need an hybrid uninstall method that runs an uninstall profile and uninstalls the remaining elements using old style scripting afterwards.



Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.