Error after upgrade to 8.5+ "Using SaveAction.Save + SaveAction.ForceCurrentVersion on published content is not allowed"

Member since: 2010

Hi,

We have been using the code that was working quite well:

_contentRepository.Save(clone, SaveAction.Save | SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);

However, after upgrade, this gives the error: "EPiServer.Core.EPiServerException: Using SaveAction.Save + SaveAction.ForceCurrentVersion on published content is not allowed". 

Is there a reason why the behavior was changed or is this a bug?

#122813 Jun 15, 2015 16:47
  • Hi,

    It was one of the breakng change in EPiServer 8.

    The reason is described in:

    http://world.episerver.com/documentation/Items/Upgrading/EPiServer-CMS/8/Breaking-changes/

    in section Saving published content with save action Save and ForceCurrentVersion

    #122814 Jun 15, 2015 18:56
  • Member since: 2010

    Thx a lot, Grzegorz, I didn't manage to find this.

    Do you understand this part: "You are supposed to pass in either Save on versions or Publish to modify a published content without changing status."

    I can't publish, since I don't want to change the ChangedBy value (publish changes it). When I save, the new version is not forced, so the page is not changed.

    I tried using SaveAction.Publish | SaveAction.SkipSetCommonDraft (since I've noticed the latter is new to SaveAction), however, this works as it should when I first modify the page, but when I do the same the second time, I see the previously published page (instead of the first published one).

    BR,

    Marija

    #122815 Jun 15, 2015 19:04
  • Member since: 2010

    Ah no, it's been a while since I wrote that code. The combination Save and ForceCurrentVersion does change the ChangedBy, but at least it doesn't change Changed. Then, in on publishing event, I set a RealChangedBy value (this is not called with Save | ForceCurrentVersion, so that worked well).

    Now, when I switched to Published, the event is called and RealChangedBy is set anyways. So, I need a way to know if the page is "really" changed. I am now checking the following:

    ((SaveContentEventArgs)e).Action != SaveAction.Publish | SaveAction.SkipSetCommonDraft,

    I'll dig deeper if EPi uses the same combination elsewhere.

    #122817 Edited, Jun 15, 2015 21:59
  • Member since: 2004

    I guess this doesn't help with your problem Marija, but it may be good to know that there's a extension method called page.GetForceCurrentVersionSaveAction();. With that you don't have to check if a page is published etc when resaving.

    #122826 Jun 16, 2015 10:37
  • Member since: 2010

    Hi, Erik,

    Thx, it's not what I need, but still good to know.

    For now, I took the following approach - when saving, I save with SaveAction.Publish | SaveAction.SkipSetCommonDraft. That doesn't change the Changed date value, which is great.

    Then, in Publishing event, I check if SaveAction is different from that combination and set my own RealChangedBy, if so.

    It looks like it's working, for now :)

    #122828 Jun 16, 2015 11:12