Overriding the Current Version
There is a specific pattern for overriding the current version. Current version is associated with the current request, or if not within a request, the current thread. It is 'global' to code running within this context. Therefore it needs to be handled carefully to avoid inconsistencies occurring.
VersionManager.Instance.PushState(VersioningMode.Specific, itemVersion); try { ... Access Data API or code depending on current version ... } finally { VersionManager.Instance.PopState(); }
The above code ensures the original state of the current version is restored in all circumstances.
The VersioningMode enumeration has the following values which indicate how the current version is determined:
Current | The default. The current version is determined by the request according to the code in the currently registered Versioners. |
Specific | The current version is set to a specific ItemVersion value. |
Public | The current version is the 'public' version - which version this is is defined by relevant code in the currently registered Versions. The intention is that this is the version seen by default by an anonymous user. It may actually include a range of versions where the version is determined by the url of the current request. |
All | All versions are current. |
Note that where multiple versions are current, the Data API will likely return multiple version records for the same content item. Only allow this situation to happen with care and ensure the results are as intended.