diff --git a/magnolia-core/src/main/java/info/magnolia/cms/core/version/BaseVersionManager.java b/magnolia-core/src/main/java/info/magnolia/cms/core/version/BaseVersionManager.java index a8a6322..1d6ee03 100644 --- a/magnolia-core/src/main/java/info/magnolia/cms/core/version/BaseVersionManager.java +++ b/magnolia-core/src/main/java/info/magnolia/cms/core/version/BaseVersionManager.java @@ -430,20 +430,30 @@ public abstract class BaseVersionManager { systemVersionedNode.save(); try { + // using system context here is forced by the fact that JR will use same context to also check source (mgnlVersion) repo READ permission and ordinary user has no rights in this workspace + Session sysDestinationSession = MgnlContext.getJCRSession(node.getSession().getWorkspace().getName()); + log.debug("restoring ino:{}:{}", sysDestinationSession.getWorkspace().getName(), node.getPath()); + Node destinationNode = sysDestinationSession.getNode(node.getPath()); // if restored, update original node with the restored node and its subtree Rule rule = getUsedFilter(versionedNode); try { synchronized (ExclusiveWrite.getInstance()) { - CopyUtil.getInstance().copyFromVersion(versionedNode, node, new RuleBasedNodePredicate(rule)); - if (NodeUtil.hasMixin(node, ItemType.DELETED_NODE_MIXIN)) { - node.removeMixin(ItemType.DELETED_NODE_MIXIN); + CopyUtil.getInstance().copyFromVersion(versionedNode, destinationNode, new RuleBasedNodePredicate(rule)); + if (NodeUtil.hasMixin(destinationNode, ItemType.DELETED_NODE_MIXIN)) { + destinationNode.removeMixin(ItemType.DELETED_NODE_MIXIN); } - node.save(); + destinationNode.save(); } + // node was updated in system context and we should make sure it is notified of the changes + node.refresh(false); } catch (RepositoryException re) { - log.error("failed to restore versioned node, reverting all changes make to this node"); - node.refresh(false); + if (log.isDebugEnabled()) { + log.debug("error during restore: " + re.getMessage(), re); + } else { + log.error("failed to restore versioned node, reverting all changes make to this node"); + } + destinationNode.refresh(false); throw re; } } diff --git a/magnolia-core/src/main/java/info/magnolia/cms/core/version/CopyUtil.java b/magnolia-core/src/main/java/info/magnolia/cms/core/version/CopyUtil.java index 8e3cb45..c41663c 100644 --- a/magnolia-core/src/main/java/info/magnolia/cms/core/version/CopyUtil.java +++ b/magnolia-core/src/main/java/info/magnolia/cms/core/version/CopyUtil.java @@ -188,7 +188,7 @@ public final class CopyUtil { * Recursively removes all child nodes from node using specified filter. */ private void removeNonExistingChildNodes(Node source, Node destination, Predicate filter) - throws RepositoryException { + throws RepositoryException { // collect all uuids from the source node hierarchy using the given filter NodeIterator children = new FilteringNodeIterator(destination.getNodes(), filter); while (children.hasNext()) { @@ -220,7 +220,7 @@ public final class CopyUtil { * Copy all child nodes from node1 to node2. */ private void copyAllChildNodes(Node node1, Node node2, Predicate filter) - throws RepositoryException { + throws RepositoryException { NodeIterator children = new FilteringNodeIterator(node1.getNodes(), filter); while (children.hasNext()) { Node child = children.nextNode(); @@ -229,7 +229,7 @@ public final class CopyUtil { } public void clone(Node node, Node parent, Predicate filter, boolean removeExisting) - throws RepositoryException { + throws RepositoryException { try { // it seems to be a bug in jackrabbit - cloning does not work if the node with the same uuid // exist, "removeExisting" has no effect @@ -263,6 +263,7 @@ public final class CopyUtil { } else { String parH = parent.getPath(); + log.debug("workspace level clone from {}:{} to {}:{}", new Object[] { node.getSession().getWorkspace().getName(), node.getPath(), parent.getSession().getWorkspace().getName(), parent.getPath() }); parent.getSession().getWorkspace().clone( node.getSession().getWorkspace().getName(), node.getPath(),