1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.platform.blog.internal; |
21 |
|
|
22 |
|
import java.util.Collection; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.slf4j.Logger; |
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.extension.InstalledExtension; |
31 |
|
import org.xwiki.extension.event.ExtensionUpgradedEvent; |
32 |
|
import org.xwiki.extension.version.Version; |
33 |
|
import org.xwiki.extension.version.VersionConstraint; |
34 |
|
import org.xwiki.extension.version.internal.DefaultVersionConstraint; |
35 |
|
import org.xwiki.model.reference.WikiReference; |
36 |
|
import org.xwiki.observation.AbstractEventListener; |
37 |
|
import org.xwiki.observation.event.Event; |
38 |
|
import org.xwiki.platform.blog.BlogVisibilityMigration; |
39 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
40 |
|
import org.xwiki.wiki.manager.WikiManagerException; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
|
47 |
|
@since |
48 |
|
@since |
49 |
|
@since |
50 |
|
|
51 |
|
@Component |
52 |
|
@Singleton |
53 |
|
@Named(BlogUpgradeEventListener.NAME) |
|
|
| 90.9% |
Uncovered Elements: 3 (33) |
Complexity: 12 |
Complexity Density: 0.6 |
|
54 |
|
public class BlogUpgradeEventListener extends AbstractEventListener |
55 |
|
{ |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
public static final String NAME = "Blog Upgrade Listener"; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
private static final String EXTENSION_ID = "org.xwiki.platform:xwiki-platform-blog-ui"; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
private static final VersionConstraint VERSION_CONSTRAINT = new DefaultVersionConstraint("(,7.4.6),[8.0,8.4.3)"); |
71 |
|
|
72 |
|
@Inject |
73 |
|
private BlogVisibilityMigration blogVisibilityMigration; |
74 |
|
|
75 |
|
@Inject |
76 |
|
private WikiDescriptorManager wikiDescriptorManager; |
77 |
|
|
78 |
|
@Inject |
79 |
|
private Logger logger; |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
8 |
public BlogUpgradeEventListener()... |
85 |
|
{ |
86 |
8 |
super(NAME, new ExtensionUpgradedEvent(EXTENSION_ID)); |
87 |
|
} |
88 |
|
|
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
89 |
7 |
@Override... |
90 |
|
public void onEvent(Event event, Object installedExtension, Object previousExtensions) |
91 |
|
{ |
92 |
7 |
ExtensionUpgradedEvent extensionUpgradedEvent = (ExtensionUpgradedEvent) event; |
93 |
|
|
94 |
7 |
Version previousVersion = getPreviousVersion((Collection<InstalledExtension>) previousExtensions); |
95 |
|
|
96 |
7 |
if (previousVersion != null && VERSION_CONSTRAINT.containsVersion(previousVersion)) { |
97 |
3 |
String namespace = extensionUpgradedEvent.getNamespace(); |
98 |
3 |
if (namespace == null) { |
99 |
|
|
100 |
|
|
101 |
1 |
migrateAllWikis(); |
102 |
2 |
} else if (namespace.startsWith("wiki:")) { |
103 |
2 |
migrateWiki(new WikiReference(namespace.substring(5))); |
104 |
|
} |
105 |
|
} |
106 |
|
} |
107 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
108 |
1 |
private void migrateAllWikis()... |
109 |
|
{ |
110 |
1 |
try { |
111 |
1 |
for (String wikiId : wikiDescriptorManager.getAllIds()) { |
112 |
2 |
migrateWiki(new WikiReference(wikiId)); |
113 |
|
} |
114 |
|
} catch (WikiManagerException e) { |
115 |
0 |
logger.warn("Failed to migrate the visibility of non published blog posts.", e); |
116 |
|
} |
117 |
|
} |
118 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
119 |
4 |
private void migrateWiki(WikiReference wikiReference)... |
120 |
|
{ |
121 |
4 |
try { |
122 |
4 |
blogVisibilityMigration.execute(wikiReference); |
123 |
|
} catch (Exception e) { |
124 |
0 |
logger.warn("Failed to migrate the visibility of non published blog posts on the wiki [{}].", |
125 |
|
wikiReference.getName(), e); |
126 |
|
} |
127 |
|
} |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
129 |
7 |
private Version getPreviousVersion(Collection<InstalledExtension> previousExtensions)... |
130 |
|
{ |
131 |
7 |
for (InstalledExtension extension : previousExtensions) { |
132 |
12 |
if (extension.getId().getId().equals(EXTENSION_ID)) { |
133 |
6 |
return extension.getId().getVersion(); |
134 |
|
} |
135 |
|
} |
136 |
|
|
137 |
1 |
return null; |
138 |
|
} |
139 |
|
} |