Wiki source code of CKEditor configuration
Last modified by Ricardo Julio Rodríguez Fernández on 2024/02/09 13:32
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{groovy}} | ||
2 | import org.xwiki.text.StringUtils; | ||
3 | import java.util.Arrays; | ||
4 | |||
5 | def DEFAULT_CONTENT = "// Define changes to default configuration here. For example:\n" + | ||
6 | "// config.uiColor = '#AADC6E';\n" + | ||
7 | "// config.linkShowTargetTab = true;"; | ||
8 | def DEFAULT_CONTENT_2 = "// Define changes to default configuration here. For example:\n" + | ||
9 | "// config.language = 'fr';\n" + | ||
10 | "// config.uiColor = '#AADC6E';" | ||
11 | def DEFAULT_CONTENT_ARRAY = Arrays.asList(DEFAULT_CONTENT, DEFAULT_CONTENT_2); | ||
12 | |||
13 | for (def wiki : services.wiki.getAll()) { | ||
14 | println("* Handling wiki [$wiki.id]"); | ||
15 | xcontext.getContext().setDatabase(wiki.getId()); | ||
16 | |||
17 | def configDocument = xwiki.getDocument('CKEditor.Config'); | ||
18 | boolean needSave = false; | ||
19 | if (!configDocument.isHidden()) { | ||
20 | needSave = true; | ||
21 | } | ||
22 | def configObject = configDocument.getObject('CKEditor.ConfigClass', true); | ||
23 | def existingContent = configObject.getValue('advanced'); | ||
24 | |||
25 | if (!configDocument.isNew() && StringUtils.isNotBlank(existingContent) | ||
26 | && !existingContent.contains('config.versionCheck') | ||
27 | && !DEFAULT_CONTENT_ARRAY.contains(existingContent.replaceAll("\\r\\n", "\\n"))) { | ||
28 | // The "Failed to execute the [groovy] macro:" message is to trigger an exception in | ||
29 | // InstanceScriptExecutor#executeGroovyScript() | ||
30 | println ('Failed to execute the [groovy] macro: there is already a custom configuration.'); | ||
31 | // Print debug infos | ||
32 | println ('{{code}}' + existingContent + '{{/code}}'); | ||
33 | } else { | ||
34 | existingContent = StringUtils.isNotBlank(existingContent) ? existingContent + '\r\n' : ''; | ||
35 | if (!existingContent.contains('config.versionCheck')) { | ||
36 | existingContent += 'config.versionCheck = false;' | ||
37 | configObject.set('advanced', existingContent); | ||
38 | needSave = true; | ||
39 | } else { | ||
40 | println('Configuration has already been updated!'); | ||
41 | } | ||
42 | } | ||
43 | if (needSave) { | ||
44 | configDocument.setHidden(true); | ||
45 | configDocument.setMinorEdit(true); | ||
46 | configDocument.save(); | ||
47 | println('Configuration has been updated!'); | ||
48 | } | ||
49 | } | ||
50 | {{/groovy}} |