Code source wiki de Migration
Modifié par Vincent Massol le 2011/08/12 21:26
Afficher les derniers auteurs
author | version | line-number | content |
---|---|---|---|
1 | = Migration of Meeting Manager = | ||
2 | |||
3 | {{groovy}} | ||
4 | println "[[Confirm launching migration>>${doc.fullName}?confirm=1]]" | ||
5 | |||
6 | for(item in xwiki.searchDocuments("where doc.fullName like 'XWiki.Meeting%'")) { | ||
7 | def itemdoc = xwiki.getDocument(item) | ||
8 | println "* Moving page ${item} to space MMCode" | ||
9 | if (request.confirm=="1") | ||
10 | itemdoc.rename("MMCode.${itemdoc.name}") | ||
11 | } | ||
12 | |||
13 | for(item in xwiki.searchDocuments("where (doc.fullName like 'XWiki.Meeting%' or doc.space = 'MMCode' or doc.content like '%XWiki.Meeting%') and doc.name<>'Install' and doc.name<>'Migration'")) { | ||
14 | def changed = false | ||
15 | def itemdoc = xwiki.getDocument(item) | ||
16 | def content = itemdoc.getContent() | ||
17 | def newcontent = content.replaceAll("XWiki.Meeting", "MMCode.Meeting").replaceAll("MMCode.MeetingManager ", "XWiki.MeetingManager ").replaceAll("MMCode.MeetingManager\\.", "XWiki.MeetingManager.") | ||
18 | if (content!=newcontent) { | ||
19 | changed = true | ||
20 | if (request.confirm=="1") | ||
21 | itemdoc.setContent(newcontent) | ||
22 | } | ||
23 | |||
24 | // Modifying JS Extension code | ||
25 | itemdoc.use("XWiki.JavaScriptExtension") | ||
26 | def code = itemdoc.getValue("code") | ||
27 | if (code) { | ||
28 | def newcode = code.replaceAll("XWiki.Meeting", "MMCode.Meeting").replaceAll("MMCode.MeetingManager ", "XWiki.MeetingManager ").replaceAll("MMCode.MeetingManager\\.", "XWiki.MeetingManager.") | ||
29 | if (code!=newcode) { | ||
30 | changed = true | ||
31 | if (request.confirm=="1") | ||
32 | itemdoc.set("code", newcode) | ||
33 | } | ||
34 | } | ||
35 | |||
36 | if (changed) { | ||
37 | println "* Updating code in page ${item}" | ||
38 | if (request.confirm=="1") | ||
39 | itemdoc.save("Migrated Meeting Manager code") | ||
40 | } | ||
41 | } | ||
42 | |||
43 | def boolean migrateDoc(document, confirm) { | ||
44 | def result = false | ||
45 | result |= migrateClass(document, "XWiki.MeetingClass", "MMCode.MeetingClass", confirm) | ||
46 | result |= migrateClass(document, "XWiki.MeetingCycleClass", "MMCode.MeetingCycleClass", confirm) | ||
47 | result |= migrateClass(document, "XWiki.MeetingCycleItemClass", "MMCode.MeetingCycleItemClass", confirm) | ||
48 | result |= migrateClass(document, "XWiki.MeetingParticipantClass", "MMCode.MeetingParticipantClass", confirm) | ||
49 | result |= migrateClass(document, "XWiki.MeetingDateAttemptClass", "MMCode.MeetingDateAttemptClass", confirm) | ||
50 | return result | ||
51 | } | ||
52 | |||
53 | def boolean migrateClass(document, sourceclass, targetclass, confirm) { | ||
54 | def result = false | ||
55 | for(obj in document.getObjects(sourceclass)) { | ||
56 | result = true | ||
57 | if (obj!=null) { | ||
58 | if (confirm) { | ||
59 | def newobj = new com.xpn.xwiki.objects.BaseObject(); | ||
60 | newobj.merge(obj); | ||
61 | newobj.setClassName(targetclass); | ||
62 | document.addObject(targetclass, newobj); | ||
63 | document.removeObject(obj); | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | return result | ||
68 | } | ||
69 | |||
70 | for(item in xwiki.searchDocuments(", BaseObject as obj where doc.fullName=obj.name and obj.className like 'XWiki.Meeting%Class'")) { | ||
71 | println "* Migrating classes in page ${item}" | ||
72 | if (request.confirm=="1") { | ||
73 | def itemdoc = xwiki.getDocument(item) | ||
74 | def itemdocument = itemdoc.getDocument() | ||
75 | if (migrateDoc(itemdocument, request.confirm=="1")) { | ||
76 | xwiki.getXWiki().saveDocument(itemdocument, "Migrated Meeting Manager code", xcontext.getContext()) | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | {{/groovy}} |