Proper usage of GetDraftRequired method - creating a new version of content item when updating

Topics: General
Jul 30, 2014 at 2:45 PM
I'm creating a scheduled task where I find some content items that meet certain conditions and update them them as necessary.

I inject an IContentManager and use it for working with the content items. I've noticed that if I use Get or Query to retrieve the content items and update them, the update is applied to the currently published version instead of a new version being created.

Looking through the content management source code, I found the GetDraftRequired extension method which essentially just calls the content manager's Get method with VersionOptions.DraftRequired. Using this method to retrieve the content item before making my updates appears to result in a new version of the content being created (like I'm looking for).

Is this the proper usage of this method and the correct way to programatically create a new version of a content item when making updates? I've never used the GetDraftRequired method before and it doesn't appear to be used anywhere in the orchard source except in some unit tests so I wanted to check and make sure I'm not doing something stupid.

Thanks!
Developer
Aug 1, 2014 at 1:43 AM
Yes, this is the proper way to create new versions. I didn't know about the extension method you mentioned. If you look at the AdminController of the Contents module (In Orchard.Core) you'll see that the VersionOptions.DraftRequired is used there as well (see the EditPOST method).

Thumbs up for checking out the source code!