Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Dec 14, 2013 @ 11:42
    Warren Buckley
    0

    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

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Dec 15, 2013 @ 07:27
    Richard Soeteman
    0

    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

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Dec 15, 2013 @ 17:17
    Warren Buckley
    0

    Hi Richard

    I have tried the InstalledPackage.BeforeDelete event without much luck at the moment.

    Have you ever got it to work before?

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Dec 15, 2013 @ 17:48
    Warren Buckley
    0

    My Bad

    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();
            }
        }
    
  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Dec 15, 2013 @ 22:01
    Lee Kelleher
    0

    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:

    <Action runat="install" undo="true" alias="uComponents_Uninstaller" />
    

    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

Please Sign in or register to post replies

Write your reply to:

Draft