Reacting to your module being disabled

Topics: Customizing Orchard, Writing modules
Dec 12, 2011 at 11:35 PM

Hi guys, haven't posted here in a while, but I've been working with Orchard on pretty much a daily basis.

I have a question for anyone who might be able to answer this.

I'd like to know if there is a way in Orchard right now to react to your module being disabled (and/or enabled) and doing some cleanup.

My use case is this:

My module contains a custom content part.  When my module is enabled, I'd like to go into some of the default content types (such as Page, BlogPost, etc.) and add my part to those types.  And when my module is disabled, I'd like to do the reverse.

Right now I could add some manual setup steps, such as create install and uninstall buttons in the admin for the user to press after enabling the module or before disabling the module, but there is always the possibility that someone can forget.

I've seen some modules try to do some of the "enable" steps in the migration, but that has two problems: 1. no chance to symmetrically disable these, and 2. the steps are not run again when the module is reenabled later.

If anyone can provide information, thanks =)

Dec 12, 2011 at 11:55 PM

There is no way to detect that, as your module can be disabled by renaming the manifest, deleting the folder, etc.

What is it you want to do on disable? If it's just cleanup, Orchard actually prefers not to do that, so that the data can be retrieved if the module is re-enabled. The right thing to do for cleanup would be to have a generic cleanup module.

Dec 13, 2011 at 4:39 AM

Thanks, I think that makes sense.


Is there defined behavior as to what happens if a content type on the system refers to a content part that's not enabled? 

Dec 13, 2011 at 5:00 AM

The driver won't run, so it won't be displayed.

Dec 13, 2011 at 7:01 AM

Okay.  Thank you.  I appreciate your quick and concise answers =)