fortedigital/EpiserverRedirects

Published event is unnecessarily triggered when publishing content existing in various languages

Closed this issue · 0 comments

Consider this scenario:

  • We have a content which exists in two languages: English (en) and Norwegian (no)
  • Content has some previous versions published, both in en and no.
  • In following example it will be a home page. Norwegian url is /, English url is /en
  • Latest published version is Norwegian version
  • I do a change (any property value edit, nothing that changes the url) to an English page and publish the page
  • (here is where the buggy code is triggered)

Result:

  • a lot of new redirect rules are being added to redirect rule table. Actually it seems like these are rules for every child of a home page:
    image

Possible source of the issue:

In Forte.EpiserverRedirects.System.SystemRedirectsEventModule.PublishedContentHandler there is a logic that fetches lastVersion:

var lastVersion = ContentVersionRepository
                .Service
                .List(e.ContentLink)
                .Where(p => p.Status == VersionStatus.PreviouslyPublished)
                .OrderByDescending(p => p.Saved)
                .FirstOrDefault();

This logic ignores language branch

We assumed in preconditions that latest published version is Norwegian, hence lastVersion will be Norwegian.

Then we get newUrl:

var newUrl = GetContentUrl(e.ContentLink, e.Content.LanguageBranch());

but this time we check the language. Since we are publishing English content newUrl is /en

Then we compare oldUrl with newUrl. If this is different we assume content has changed in a way that forces us to generete redirect rules.

oldUrl is /, newUrl is /en - this causes to generate redirect rules which is wrong, since there was no change that justifies generating redirect rules