ucs-intranet-magnolia-updates/src/main/java/at/ucs/magnolia/updates/util/VersionUtil.java
2024-11-25 15:04:22 +01:00

43 lines
1.4 KiB
Java

package at.ucs.magnolia.updates.util;
import info.magnolia.jcr.util.NodeTypes;
import info.magnolia.jcr.util.NodeUtil;
import info.magnolia.module.InstallContext;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
public class VersionUtil {
private static Node getVersionsNode(InstallContext installContext) throws RepositoryException {
// make sure we have the /modules node
if (!installContext.hasModulesNode()) {
final Session session = installContext.getConfigJCRSession();
session.getRootNode().addNode("modules", NodeTypes.Content.NAME);
}
final Node moduleNode = installContext.getOrCreateCurrentModuleNode();
if (!moduleNode.hasNode("config/versions")) {
NodeUtil.createPath(moduleNode, "config/versions", "mgnl:content");
}
return moduleNode.getNode("config/versions");
}
public static boolean containsVersion(InstallContext installContext, String version) throws RepositoryException {
Node versionNode = getVersionsNode(installContext);
return versionNode != null && versionNode.hasProperty(version);
}
public static void addVersion(InstallContext installContext, String version, String name) throws RepositoryException {
Node versionsNode = getVersionsNode(installContext);
if (versionsNode != null) {
versionsNode.setProperty(version, name);
}
}
}