Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

SaveAction.Publish | SaveAction.ForceCurrentVersion no longer triggers PublishingContent

Vote:
 

Hello Guys.

Previously I was using the command contentRepository.Save(newLangContent, SaveAction.Publish | SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);  in order to force trigger a PublishingContent event from the Mogul SEO manager package.

This no longer works in EPiServer CMS 9.12.2. I'm certain it worked before, but not when it broke. I also have no memory reading any change notes regarding this. I always read all of them.

Has something been changed regarding this? Is there any way to trigger the PublishingContent event without creating a new version still?

Now I have to do SaveAction.Publish without | SaveAction.ForceCurrentVersion. Adding SaveAction.ForceCurrentVersion causes the PublishingContent event to not fire.

#160562
Sep 28, 2016 16:18
Vote:
 

Hmm interesting. Ill have to test that when we release next version of SEO Manager :) I'll forward it to Sasa who is lead dev now...

#160572
Edited, Sep 28, 2016 20:02
Vote:
 
<p>There should have been no change in that area and the Publishing event should always be raised if the main SaveAction is Publish. Have you attached yourself to the PublishingContent event to verify?</p> <p>There is quite a bit of quirkyness happening in the events raised by Save, and it is something that has got a serious cleanup in the next major. But it's mostly been Saving/Saved events that's been a bit unpredictable, not Publishing/Published.</p>
#160579
Sep 29, 2016 6:09
Vote:
 

You were right Henrik. I wrote some of my own code to test this just now. I guess something has changed in the SEO manager package instead, there must be some check that's not triggering anymore unless an old version exists in the database or something.

My InstancePublishingContent events were at least being triggered regardless if I add ForceCurrentVersion or not.

Unfortunately I don't think that the PublishingContent event triggers at all when you do a Commerce Catalog.xml import. At least that never triggered the Mogul SEO manager package either to save old URLs for creating redirects. So I've had to write some code that triggers before an import, scans the whole XML and actually publishes new versions of pages where the URL changed.

After that the actual Catalog.xml import runs. Not quite a great solution but it works.

Here is the code in question that makes our PIM <-> Mogul SEO manager integration work at all:

private static void UpdateAndSaveOldUrl([NotNull] ContentReference cr, [NotNull] CultureInfo lang, [NotNull] string newRouteSegment)
        {
            // Ugly hack-method that is supposed to trigger the Mogul event code by actually publishing a new page... (Which will immediately get re-published again later, but without triggering publish events at this point in time)
            var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
            var currLangContent = contentRepository.Get<CatalogContentBase>(cr, lang);

            if (currLangContent == null) Log.Log(Level.Debug, "Unable to find existing content in the correct language.");
            if (currLangContent == null || currLangContent.RouteSegment.Equals(newRouteSegment, StringComparison.OrdinalIgnoreCase)) return;
            Log.Log(Level.Debug, $"Old route segment: {currLangContent.RouteSegment}, new route segment: {newRouteSegment}");

            var newLangContent = currLangContent.CreateWritableClone();
            newLangContent.RouteSegment = newRouteSegment;

            // 2016-09-28 It was discovered today that passing SaveAction.ForceCurrentVersion no longer triggers the PublishingContent event in Mogul SEO manager ever.
            // This has surely worked before.
            try
            {
                contentRepository.Save(newLangContent, SaveAction.Publish, AccessLevel.NoAccess);
            }
            catch (ValidationException)
            {
                // This has failed because of invalid SeoUri before. Lets try blanking it out and re-saving.
                var seoInfo = (ISearchEngineInformation)newLangContent;
                seoInfo.SeoUri = null; // I haven't really tested if this actually blanks out the field... but string.Empty seems to NOT change it.
                try
                {
                    contentRepository.Save(newLangContent, SaveAction.Publish, AccessLevel.NoAccess);
                }
                catch (Exception e)
                {
                    Log.Log(Level.Error, "Failed publishing page to trigger Mogul URL update.", e);
                    NewRelic.NoticeError(e);
                }
            }
        }

Previously I was using newLangContent.GetForceCurrentVersionSaveAction() as the SaveAction but now I've had to change to SaveAction.Publish. This works again but it creates a version that I don't really want.

#160584
Sep 29, 2016 10:02
Vote:
 

This is a bit unrelated but I tried to mark Henrik's post as the solution but currently the forum just takes me to a blank white page.

#160585
Sep 29, 2016 10:06
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.