Wiki source code of Migration from 1.x
Last modified by Vincent Massol on 2026/09/10 13:54
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
![]() |
1.1 | 1 | {{velocity}} |
![]() |
4.1 | 2 | ## The migration converts every 1.x change document of the wiki and saves it, and the conversion cannot be undone: |
| 3 | ## it removes the 1.x object from the page it converts. Its query is not restricted to the ReleaseNotes space, so | ||
| 4 | ## administering the wiki is what it takes to run it. The check gates the listing as well as the conversion: a user | ||
| 5 | ## who may not run the migration has no use for the list of the pages it would touch, and hiding the action while | ||
| 6 | ## still answering the request that performs it would not keep that request from performing it. | ||
| 7 | ## The check is in the page content, so the document also enforces wiki_admin as a required right: that is | ||
| 8 | ## what refuses edit on this page to anyone who does not already hold the right the check tests for. | ||
| 9 | #set ($hasWikiAdmin = $services.security.authorization.hasAccess('admin', $doc.documentReference.wikiReference)) | ||
| 10 | #if (!$hasWikiAdmin) | ||
| 11 | {{error}}{{translation key="releasenotes.migration.notAllowed"/}}{{/error}} | ||
| 12 | #else | ||
![]() |
1.1 | 13 | ## Find all pages having a v1.x ReleaseNotes.Code.ChangesClass |
![]() |
2.1 | 14 | #set ($xwql = "from doc.object(ReleaseNotes.Code.ChangesClass) as changes") |
![]() |
3.1 | 15 | ## The migration writes to every 1.x change document, so it only runs on a request carrying a valid |
| 16 | ## form token; a request without one falls through to the unconfirmed state and changes nothing. | ||
| 17 | #set ($migrate = ($request.confirm == '1' && $services.csrf.isTokenValid($request.getParameter('form_token')))) | ||
| 18 | #if (!$migrate) | ||
![]() |
2.1 | 19 | {{translation key="releasenotes.migration.pending"/}} |
![]() |
1.1 | 20 | #else |
![]() |
2.1 | 21 | {{translation key="releasenotes.migration.migrated"/}} |
![]() |
1.1 | 22 | #end |
| 23 | #foreach ($item in $services.query.xwql($xwql).execute()) | ||
![]() |
3.1 | 24 | #if ($migrate) |
![]() |
1.1 | 25 | #set ($itemDoc = $xwiki.getDocument($item)) |
| 26 | ## Add a ReleaseNotes.Code.EntryClass | ||
![]() |
2.1 | 27 | #set ($newEntryObject = $itemDoc.newObject("ReleaseNotes.Code.EntryClass")) |
![]() |
1.1 | 28 | ## Add a ReleaseNotes.Code.Change.ChangeClass |
![]() |
2.1 | 29 | #set ($newChangeObject = $itemDoc.newObject("ReleaseNotes.Code.Change.ChangeClass")) |
![]() |
1.1 | 30 | ## Copy data from ReleaseNotes.Code.ChangesClass into the 2 new objects |
![]() |
2.1 | 31 | #set ($oldChangeObject = $itemDoc.getObject("ReleaseNotes.Code.ChangesClass")) |
![]() |
1.1 | 32 | #set ($discard = $newEntryObject.set('version', $oldChangeObject.getValue('version'))) |
| 33 | #set ($discard = $newEntryObject.set('product', $oldChangeObject.getValue('product'))) | ||
| 34 | #set ($discard = $newEntryObject.set('type', 'Change')) | ||
| 35 | #set ($discard = $newChangeObject.set('summary', $oldChangeObject.getValue('summary'))) | ||
| 36 | #set ($discard = $newChangeObject.set('audience', $oldChangeObject.getValue('audience'))) | ||
| 37 | #set ($discard = $newChangeObject.set('importance', $oldChangeObject.getValue('importance'))) | ||
| 38 | #set ($discard = $newChangeObject.set('description', $oldChangeObject.getValue('description'))) | ||
| 39 | #set ($discard = $newChangeObject.set('category', $oldChangeObject.getValue('category'))) | ||
| 40 | #set ($discard = $newChangeObject.set('title', $oldChangeObject.getValue('title'))) | ||
| 41 | #set ($discard = $newChangeObject.set('screenshots', $oldChangeObject.getValue('screenshots'))) | ||
| 42 | ## Remove the old ReleaseNotes.Code.ChangesClass xobject | ||
| 43 | #set ($discard = $itemDoc.removeObject($oldChangeObject)) | ||
| 44 | ## Save the changes | ||
| 45 | #set ($discard = $itemDoc.save('Migrated from v1.x format to v2.0', true)) | ||
| 46 | * [[$item>>$item]] | ||
| 47 | #else | ||
| 48 | * [[$item>>$item]] | ||
| 49 | #end | ||
| 50 | #end | ||
| 51 | |||
![]() |
3.1 | 52 | #if (!$migrate) |
| 53 | [[{{translation key="releasenotes.migration.start"/}}>>||queryString="confirm=1&form_token=$escapetool.url($services.csrf.token)"]] | ||
![]() |
1.1 | 54 | #end |
![]() |
4.1 | 55 | #end |
![]() |
1.1 | 56 | {{/velocity}} |
