UpgradeDamAssetContent.java
2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Node
* javax.jcr.NodeIterator
* javax.jcr.Property
* javax.jcr.Session
* javax.jcr.Workspace
* javax.jcr.query.Query
* javax.jcr.query.QueryManager
* javax.jcr.query.QueryResult
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.compat.codeupgrade.impl.cq53;
import com.day.cq.compat.codeupgrade.internal.api.ProgressInfoProvider;
import java.util.Calendar;
import java.util.Date;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.Session;
import javax.jcr.Workspace;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class UpgradeDamAssetContent
implements ProgressInfoProvider {
private final Logger log;
private String progressInfo;
public static final String JCR_LAST_MODIFIED = "jcr:lastModified";
UpgradeDamAssetContent() {
this.log = LoggerFactory.getLogger(this.getClass());
}
void doUpgrade(Session s) throws Exception {
String nodetype = "dam:AssetContent";
Calendar now = Calendar.getInstance();
this.log.info("Adding jcr:lastModified property to dam:AssetContent nodes where it's missing, using value " + now.getTime());
int totalNodes = 0;
int changedNodes = 0;
String statement = "select * from [dam:AssetContent]";
Query q = s.getWorkspace().getQueryManager().createQuery("select * from [dam:AssetContent]", "JCR-SQL2");
NodeIterator it = q.execute().getNodes();
while (it.hasNext()) {
this.progressInfo = "" + totalNodes + " nodes checked, " + changedNodes + " nodes modified";
++totalNodes;
Node content = it.nextNode();
if (!content.hasProperty("jcr:lastModified")) {
++changedNodes;
content.setProperty("jcr:lastModified", now);
this.log.info("Adding {} property to node {}", (Object)"jcr:lastModified", (Object)content.getPath());
}
if (changedNodes % 100 == 0) {
s.save();
}
s.save();
}
this.progressInfo = "All done - " + totalNodes + " nodes checked, " + changedNodes + " nodes modified";
}
@Override
public String getProgressInfo() {
return this.progressInfo;
}
void setProgressInfo(String info) {
this.progressInfo = info;
this.log.info(this.progressInfo);
}
}