Copied to clipboard

Flag this post as spam?

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


  • Clair 36 posts 86 karma points
    Feb 14, 2012 @ 22:38
    Clair
    0

    Compare previous version in notification email.

     

    I am trying to create a notification email that will show the difference between the saved and previously published version.

    My plan was to create a AfterSendToPublish event and use the umbraco.cms.businesslogic.utilities.Diff.Diff2Html() method to create the body text. Pretty much exactly the same way the rollback feature works (that is where I got most of the code from).

    Can somebody explain how and where documents are “saved” vs “Published”? Maybe I'm comparing the worng versions?

    void Document_AfterSendToPublish(Document sender, umbraco.cms.businesslogic.SendToPublishEventArgs e)
        {
            Document currentDoc = sender;
            DocumentVersionList[] versions = currentDoc.GetVersions().OrderByDescending(v => v.Date).ToArray();
            
            Document rollback = new Document(currentDoc.Id, versions[1].Version);
            var props = sender.GenericProperties;
    
            StringBuilder propertiesCompare = new StringBuilder();
    
            foreach (Property p in props)
            {
                try
                {
                    if (p.Value != null)
                    {
                        string thevalue = p.Value.ToString();
    
                        thevalue = umbraco.library.StripHtml(p.Value.ToString());
                        Property cP = currentDoc.getProperty(p.PropertyType);
                        if (cP != null && cP.Value != null)
                        {
                            string cThevalue = umbraco.library.StripHtml(cP.Value.ToString());
    
                            propertiesCompare.Append(p.PropertyType.Name + " - " + umbraco.library.ReplaceLineBreaks(umbraco.cms.businesslogic.utilities.Diff.Diff2Html(cThevalue, thevalue)) + "<br />");
                        }
                        else
                        {
                            propertiesCompare.Append(p.PropertyType.Name + " - " + thevalue + "<br />");
                        }
                    }
                }
                catch { }
            }
    
            umbraco.library.SendMail("""""Sent To Publish", propertiesCompare.ToString(), true);
        }

     

    Maybe I’m going about this all wrong, if anybody has any better ideas let me know

     

  • James 4 posts 74 karma points
    Feb 20, 2020 @ 16:21
    James
    0

    Clair, did you ever figure this out?

Please Sign in or register to post replies

Write your reply to:

Draft