1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package com.xpn.xwiki.store.migration.hibernate; |
22 |
|
|
23 |
|
import java.util.Iterator; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.hibernate.HibernateException; |
30 |
|
import org.hibernate.Query; |
31 |
|
import org.hibernate.Session; |
32 |
|
import org.hibernate.Transaction; |
33 |
|
import org.slf4j.Logger; |
34 |
|
import org.xwiki.component.annotation.Component; |
35 |
|
import org.xwiki.component.manager.ComponentLookupException; |
36 |
|
|
37 |
|
import com.xpn.xwiki.XWikiContext; |
38 |
|
import com.xpn.xwiki.XWikiException; |
39 |
|
import com.xpn.xwiki.doc.rcs.XWikiPatch; |
40 |
|
import com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent; |
41 |
|
import com.xpn.xwiki.doc.rcs.XWikiRCSNodeId; |
42 |
|
import com.xpn.xwiki.store.XWikiHibernateBaseStore; |
43 |
|
import com.xpn.xwiki.store.XWikiHibernateVersioningStore; |
44 |
|
import com.xpn.xwiki.store.XWikiVersioningStoreInterface; |
45 |
|
import com.xpn.xwiki.store.migration.DataMigrationException; |
46 |
|
import com.xpn.xwiki.store.migration.XWikiDBVersion; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@version |
55 |
|
|
56 |
|
@Component |
57 |
|
@Named("R6079XWIKI1878") |
58 |
|
@Singleton |
|
|
| 5.1% |
Uncovered Elements: 37 (39) |
Complexity: 10 |
Complexity Density: 0.34 |
|
59 |
|
public class R6079XWIKI1878DataMigration extends AbstractHibernateDataMigration |
60 |
|
{ |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@Inject |
65 |
|
private Logger logger; |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
0 |
@Override... |
68 |
|
public String getDescription() |
69 |
|
{ |
70 |
0 |
return "See http://jira.xwiki.org/jira/browse/XWIKI-1878"; |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
206 |
@Override... |
74 |
|
public XWikiDBVersion getVersion() |
75 |
|
{ |
76 |
206 |
return new XWikiDBVersion(6079); |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0 |
@Override... |
80 |
|
public boolean shouldExecute(XWikiDBVersion startupVersion) |
81 |
|
{ |
82 |
0 |
return (startupVersion.getVersion() >= 4360); |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
@return |
87 |
|
@throws |
88 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
89 |
0 |
private XWikiHibernateVersioningStore getVersioningStore() throws XWikiException... |
90 |
|
{ |
91 |
0 |
try { |
92 |
0 |
return (XWikiHibernateVersioningStore) this.componentManager |
93 |
|
.getInstance(XWikiVersioningStoreInterface.class, "hibernate"); |
94 |
|
} catch (ComponentLookupException e) { |
95 |
0 |
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, |
96 |
|
XWikiException.ERROR_XWIKI_STORE_MIGRATION, |
97 |
|
String.format("Unable to reach the versioning store for database %s", getXWikiContext().getWikiId()), |
98 |
|
e); |
99 |
|
} |
100 |
|
} |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
0 |
@Override... |
103 |
|
public void hibernateMigrate() throws DataMigrationException, XWikiException |
104 |
|
{ |
105 |
|
|
106 |
0 |
getStore().executeWrite(getXWikiContext(), true, |
107 |
|
new XWikiHibernateBaseStore.HibernateCallback<Object>() |
108 |
|
{ |
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 4 |
Complexity Density: 0.18 |
|
109 |
0 |
@Override... |
110 |
|
public Object doInHibernate(Session session) throws HibernateException, XWikiException |
111 |
|
{ |
112 |
0 |
try { |
113 |
0 |
Query query = session.createQuery("select rcs.id, rcs.patch, doc.fullName " |
114 |
|
+ "from XWikiDocument as doc, XWikiRCSNodeContent as rcs where " |
115 |
|
+ "doc.id = rcs.id.docId and rcs.patch.diff = true and rcs.patch.content like '<?xml%'"); |
116 |
0 |
Iterator it = query.list().iterator(); |
117 |
|
|
118 |
0 |
XWikiContext context = getXWikiContext(); |
119 |
0 |
XWikiHibernateVersioningStore versioningStore = getVersioningStore(); |
120 |
0 |
Transaction originalTransaction = versioningStore.getTransaction(context); |
121 |
0 |
versioningStore.setSession(null, context); |
122 |
0 |
versioningStore.setTransaction(null, context); |
123 |
|
|
124 |
0 |
while (it.hasNext()) { |
125 |
0 |
Object[] result = (Object[]) it.next(); |
126 |
0 |
if (R6079XWIKI1878DataMigration.this.logger.isInfoEnabled()) { |
127 |
0 |
R6079XWIKI1878DataMigration.this.logger.info("Fixing document [{}]...", result[2]); |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
0 |
XWikiRCSNodeId nodeId = (XWikiRCSNodeId) result[0]; |
132 |
0 |
XWikiRCSNodeContent fixedNodeContent = new XWikiRCSNodeContent(nodeId); |
133 |
0 |
XWikiPatch patch = (XWikiPatch) result[1]; |
134 |
0 |
patch.setDiff(false); |
135 |
0 |
fixedNodeContent.setPatch(patch); |
136 |
|
|
137 |
0 |
session.update(fixedNodeContent); |
138 |
|
} |
139 |
|
|
140 |
0 |
versioningStore.setSession(session, context); |
141 |
0 |
versioningStore.setTransaction(originalTransaction, context); |
142 |
|
} catch (Exception e) { |
143 |
0 |
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, |
144 |
|
XWikiException.ERROR_XWIKI_STORE_MIGRATION, getName() + " migration failed", e); |
145 |
|
} |
146 |
0 |
return Boolean.TRUE; |
147 |
|
} |
148 |
|
}); |
149 |
|
} |
150 |
|
} |