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 javax.inject.Inject; |
23 |
|
import javax.inject.Provider; |
24 |
|
import javax.inject.Singleton; |
25 |
|
|
26 |
|
import org.slf4j.Logger; |
27 |
|
import org.xwiki.component.annotation.Component; |
28 |
|
import org.xwiki.model.reference.DocumentReference; |
29 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
30 |
|
import org.xwiki.model.reference.WikiReference; |
31 |
|
import org.xwiki.platform.blog.BlogVisibilityMigration; |
32 |
|
import org.xwiki.platform.blog.BlogVisibilityUpdater; |
33 |
|
import org.xwiki.query.Query; |
34 |
|
import org.xwiki.query.QueryManager; |
35 |
|
|
36 |
|
import com.xpn.xwiki.XWiki; |
37 |
|
import com.xpn.xwiki.XWikiContext; |
38 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
@version |
44 |
|
|
45 |
|
@since |
46 |
|
@since |
47 |
|
@since |
48 |
|
|
49 |
|
@Component |
50 |
|
@Singleton |
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 2 |
Complexity Density: 0.17 |
|
51 |
|
public class DefaultBlogVisibilityMigration implements BlogVisibilityMigration |
52 |
|
{ |
53 |
|
@Inject |
54 |
|
private QueryManager queryManager; |
55 |
|
|
56 |
|
@Inject |
57 |
|
private DocumentReferenceResolver<String> referenceResolver; |
58 |
|
|
59 |
|
@Inject |
60 |
|
private Provider<XWikiContext> contextProvider; |
61 |
|
|
62 |
|
@Inject |
63 |
|
private BlogVisibilityUpdater blogVisibilityUpdater; |
64 |
|
|
65 |
|
@Inject |
66 |
|
private Logger logger; |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.17 |
|
68 |
0 |
@Override... |
69 |
|
public void execute(WikiReference wikiReference) throws Exception |
70 |
|
{ |
71 |
0 |
try { |
72 |
0 |
XWikiContext context = contextProvider.get(); |
73 |
0 |
XWiki xwiki = context.getWiki(); |
74 |
|
|
75 |
|
|
76 |
0 |
final String xwql = |
77 |
|
"from doc.object(Blog.BlogPostClass) obj where " |
78 |
|
+ "((obj.published = 0 or obj.hidden = 1) and doc.hidden <> 1)" |
79 |
|
+ " or " |
80 |
|
+ "(obj.published = 1 and obj.hidden = 0 and doc.hidden <> 0)"; |
81 |
|
|
82 |
0 |
Query query = queryManager.createQuery(xwql, Query.XWQL).setWiki(wikiReference.getName()); |
83 |
0 |
for (String docName : query.<String>execute()) { |
84 |
0 |
DocumentReference documentReference = referenceResolver.resolve(docName, wikiReference); |
85 |
0 |
XWikiDocument document = xwiki.getDocument(documentReference, context); |
86 |
|
|
87 |
|
|
88 |
0 |
blogVisibilityUpdater.synchronizeHiddenMetadata(document); |
89 |
|
|
90 |
0 |
xwiki.saveDocument(document, "Change the page's visibility according to the blog post.", context); |
91 |
|
} |
92 |
|
|
93 |
0 |
logger.info("Migration of blog posts' visibility has been successfully executed on the wiki [{}].", |
94 |
|
wikiReference.getName()); |
95 |
|
} catch (Exception e) { |
96 |
0 |
throw new Exception("Failed to migrate the blog posts' visibility.", e); |
97 |
|
} |
98 |
|
} |
99 |
|
} |