Hello!
How can I change the version number of a document?
In fact, I would like to get the version and change its number to another one.
Or, as an option, delete the version and add a new one with the required number.
Hello. You cannot and shouldn’t change it. The versioning scheme is managed by XWiki.
What’s your real need (i.e. why do you want to change the version numbers)?
Thanks
I am importing data from another system where there are versions. And I wanted the versions to match each other.
In general, I can create a separate object in which to store the version comparison.
Thanks for your answer!
You can force the version you want to have (provided it follow the format <x>.<y>
) in a new history entry when you save the document. That’s what importers (like the Confluence one) usually do.
There’s also another solution but it’s quite involved, it means re-implementing the versioning store.
EDIT: I don’t think it’s ever been done so it might not even work (there might ties to the XWiki versioning scheme).
If you only need to set versions on first time import, then Thomas’s solution is the best. Then the impored docs will follow xwiki’s versioning scheme afterwars for any subsequent modifications.
Could you please point me to a code example?
Or a link where to read it.
This option is quite suitable.
Thank you
It depends a lot on how you are exactly doing your import:
- if you are using the Filter framework, all it takes is to indicate the version in the
#beginWikiDocumentRevision
, see for example mediawiki/mediawiki-xml/src/main/java/org/xwiki/contrib/mediawiki/xml/internal/input/MediaWikiInputFilterStream.java at master · xwiki-contrib/mediawiki · GitHub - if you are directly modifying and saving the XWikiDocument yourself, then the trick is to set metadata and content dirty to false in XWikiDocument before calling saveDocument (which tells the store that you want to fully control all the plumbing, like the version, date, etc.). See for example xwiki-platform/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/internal/filter/output/DocumentInstanceOutputFilterStream.java at master · xwiki/xwiki-platform · GitHub
Thank you tmortagne!
It works.