Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Apr 09, 2014 @ 13:30
    Ismail Mayat
    0

    Content published event not firing

    Guys,

    Using v.7.10 and I have wired up content service published event however it never fires. Content does publish and gatheringnode event which is wired up in same class also fires. Any ideas?

    My code looks like:

    public class Events : IApplicationEventHandler
    {
    
        void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<Umbraco.Core.Models.IContent> e)
        {
            LogHelper.Info<string>("published settings object");
            //if content being published is sitesettings we need to restart app pool 
            //else our settings changes will not be picked up
            if (e.PublishedEntities.Count() == 1 && e.PublishedEntities.First().ContentType.Alias == "SiteSettingDocType")
            {
                Restart();
            }
        }
    
        private static void Restart()
        {
            //restart web app (instead of iisreset)
            DirectoryInfo dir = new DirectoryInfo(HttpContext.Current.Server.MapPath("restart"));
            if (dir.Exists)
            {
                Directory.Move(dir.FullName, dir.FullName + "ed");
            }
            else
            {
                DirectoryInfo dired = new DirectoryInfo(HttpContext.Current.Server.MapPath("restarted"));
                if (dired.Exists)
                {
                    Directory.Move(dired.FullName, dir.FullName);
                }
                else
                {
                    Directory.CreateDirectory(dir.FullName);
                }
            }
        }
    
    
        public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
    
        }
    
        public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            ContentService.Published += ContentService_Published;
        }
    
        public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
    
        }
    }
    
  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Apr 10, 2014 @ 13:25
    Ismail Mayat
    0

    Ok so in answer to my own question i was being dumb. In my web.config debug was set to false i set it to true and found i could now debug and figure out what issues in my code. Weird thing is i was with debug set to false able to debug razor macros?? Weirdness.

    Ismail

  • Simon 692 posts 1068 karma points
    Feb 07, 2016 @ 13:46
    Simon
    0

    Hi Ismail,

    When the event will be fired:

    exactly before node will be published or after?

    And How can I access the node values to set a particular value?

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft