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.sql.Connection; |
24 |
|
import java.sql.SQLException; |
25 |
|
import java.sql.Statement; |
26 |
|
|
27 |
|
import javax.inject.Named; |
28 |
|
import javax.inject.Singleton; |
29 |
|
|
30 |
|
import org.hibernate.HibernateException; |
31 |
|
import org.hibernate.Session; |
32 |
|
import org.hibernate.jdbc.Work; |
33 |
|
import org.xwiki.component.annotation.Component; |
34 |
|
|
35 |
|
import com.xpn.xwiki.XWikiException; |
36 |
|
import com.xpn.xwiki.store.XWikiHibernateBaseStore.HibernateCallback; |
37 |
|
import com.xpn.xwiki.store.migration.DataMigrationException; |
38 |
|
import com.xpn.xwiki.store.migration.XWikiDBVersion; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
|
48 |
|
@Component |
49 |
|
@Named("R54600Translation") |
50 |
|
@Singleton |
|
|
| 22.2% |
Uncovered Elements: 7 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
51 |
|
public class R54600TranslationDataMigration extends AbstractHibernateDataMigration |
52 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
53 |
0 |
@Override... |
54 |
|
public String getDescription() |
55 |
|
{ |
56 |
0 |
return "Fix any existing mistake with document translation field"; |
57 |
|
} |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
206 |
@Override... |
60 |
|
public XWikiDBVersion getVersion() |
61 |
|
{ |
62 |
206 |
return new XWikiDBVersion(54600); |
63 |
|
} |
64 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
0 |
@Override... |
66 |
|
public void hibernateMigrate() throws DataMigrationException, XWikiException |
67 |
|
{ |
68 |
0 |
getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>() |
69 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
70 |
0 |
@Override... |
71 |
|
public Object doInHibernate(Session session) throws HibernateException, XWikiException |
72 |
|
{ |
73 |
0 |
session.doWork(new R54600Work()); |
74 |
0 |
return Boolean.TRUE; |
75 |
|
} |
76 |
|
}); |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 0.75 |
|
79 |
|
private static class R54600Work implements Work |
80 |
|
{ |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 0.75 |
|
81 |
0 |
@Override... |
82 |
|
public void execute(Connection connection) throws SQLException |
83 |
|
{ |
84 |
0 |
try (Statement statement = connection.createStatement()) { |
85 |
0 |
statement.execute("UPDATE xwikidoc set XWD_TRANSLATION = 1" |
86 |
|
+ " where XWD_TRANSLATION = 0 and (XWD_LANGUAGE is not null and XWD_LANGUAGE <> '')"); |
87 |
0 |
statement.execute("UPDATE xwikidoc set XWD_TRANSLATION = 0" |
88 |
|
+ " where XWD_TRANSLATION = 1 and (XWD_LANGUAGE is null or XWD_LANGUAGE = '')"); |
89 |
|
} |
90 |
|
} |
91 |
|
} |
92 |
|
} |