Hello fellow package developers,
I was wondering how you deal with running code on package uninstall to clean up any custom code that was run by the package. Such as a new DB table added, language keys and a new section added with new sections service API?
So any thoughts on this?
Is there any events or similar that can be hooked into, to run my cleanup code?
Usually I use package actions but that doesn't work to well. Maybe you can use the InstalledPackage.BeforeDelete event? If it works please let me know.
It does fire fine, I just forgot to register the old style event on App Startup of Umbraco.
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
//Check to see if section needs to be added
AddSection(applicationContext);
//Check to see if language keys for section needs to be added
AddSectionLanguageKeys();
//Add OLD Style Package Event
InstalledPackage.BeforeDelete += InstalledPackage_BeforeDelete;
}
/// <summary>
/// Uninstall Package - Before Delete (Old style events, no V6/V7 equivelant)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void InstalledPackage_BeforeDelete(InstalledPackage sender, System.EventArgs e)
{
//Check which package is being uninstalled
if (sender.Data.Name == "Analytics")
{
//Start Uninstall - clean up process...
Uninstall.RemoveSection();
Uninstall.RemoveSectionLanguageKeys();
}
}
I'm not sure if anything has changed in v7 with uninstalling packages, but here's what I do for the uComponents uninstall - which has been working fine since (at least) Umbraco 4.8.
In the package.xml manifest, you can add a custom PackageAction, with the option of undo=true:
How can I run code on package uninstall?
Hello fellow package developers, I was wondering how you deal with running code on package uninstall to clean up any custom code that was run by the package. Such as a new DB table added, language keys and a new section added with new sections service API?
So any thoughts on this?
Is there any events or similar that can be hooked into, to run my cleanup code?
Thanks Warren
Usually I use package actions but that doesn't work to well. Maybe you can use the InstalledPackage.BeforeDelete event? If it works please let me know.
Cheers,
Richard
Hi Richard
I have tried the InstalledPackage.BeforeDelete event without much luck at the moment.
Have you ever got it to work before?
My Bad
It does fire fine, I just forgot to register the old style event on App Startup of Umbraco.
I'm not sure if anything has changed in v7 with uninstalling packages, but here's what I do for the uComponents uninstall - which has been working fine since (at least) Umbraco 4.8.
In the
package.xml
manifest, you can add a custom PackageAction, with the option ofundo=true
:e.g. https://github.com/leekelleher/uComponents/blob/master/package/package.xml#L31
Then when the package is uninstalled, it will run the
Undo
method in the custom PackageAction,e.g. https://github.com/leekelleher/uComponents/blob/master/src/uComponents.Installer/PackageActions/Uninstaller.cs#L67
Cheers,
- Lee
is working on a reply...