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 package info.magnolia.resources.app.setup;
35
36 import info.magnolia.jcr.util.NodeTypes;
37 import info.magnolia.jcr.util.NodeUtil;
38 import info.magnolia.module.InstallContext;
39 import info.magnolia.module.delta.AbstractRepositoryTask;
40 import info.magnolia.module.delta.TaskExecutionException;
41
42 import javax.jcr.RepositoryException;
43 import javax.jcr.Session;
44
45
46
47
48
49
50
51
52 public class UpdateResourcesAppConfigurationTask extends AbstractRepositoryTask {
53
54 private final static String LEGACY_APP_PARENT_PATH = "/modules/resources/apps";
55 private final static String LEGACY_APP_PATH = LEGACY_APP_PARENT_PATH + "/resources";
56 private final static String NEW_APP_PARENT_PATH = "/modules/resources-app/apps";
57
58 public UpdateResourcesAppConfigurationTask() {
59 super("Migrate Resources App", "Migrate Resources App from resource module to resources-app module.");
60 }
61
62 @Override
63 public void doExecute(InstallContext installContext) throws RepositoryException {
64 Session session = installContext.getConfigJCRSession();
65
66
67 moveModuleSubNode(session, "dialogs");
68
69 if (session.nodeExists(LEGACY_APP_PATH)) {
70 if (!session.nodeExists(NEW_APP_PARENT_PATH)) {
71 NodeUtil.createPath(session.getRootNode(), NEW_APP_PARENT_PATH, NodeTypes.Content.NAME);
72 }
73
74 session.move(LEGACY_APP_PATH, NEW_APP_PARENT_PATH + "/resources-legacy");
75
76 if (session.getNode(LEGACY_APP_PARENT_PATH).hasNodes()) {
77 final String errorMsg = String.format("Was not expecting to find more than one app in '%s'", LEGACY_APP_PARENT_PATH);
78 installContext.error(errorMsg, new TaskExecutionException(errorMsg));
79 } else {
80 session.removeItem(LEGACY_APP_PARENT_PATH);
81 }
82 }
83 }
84
85 private void moveModuleSubNode(Session session, String node) throws RepositoryException {
86 if (session.nodeExists("/modules/resources/" + node)) {
87 session.move("/modules/resources/" + node, "/modules/resources-app/" + node);
88 }
89 }
90 }