private void fixLostComponents() throws FrameworkException {
Page hiddenDoc = getOrCreateHiddenDocument();
SecurityContext securityContext = SecurityContext.getSuperUserInstance();
Result<DOMNode> result = StructrApp.getInstance(securityContext).nodeQuery(DOMNode.class).getResult();
final CreateRelationshipCommand createRel = StructrApp.getInstance(securityContext).command(CreateRelationshipCommand.class);
for (DOMNode node : result.getResults()) {
if (node.hasChildNodes()
&& (node.hasIncomingRelationships(Sync.class) || node.hasRelationship(Sync.class))
&& (!hiddenDoc.equals(node.getOwnerDocument()))
) {
try {
DOMNode clonedNode = (DOMNode) node.cloneNode(false);
moveChildNodes(node, clonedNode);
clonedNode.setProperty(DOMNode.ownerDocument, hiddenDoc);
createRel.execute((DOMNode) node, clonedNode, Sync.class);
createRel.execute(clonedNode, (DOMNode) node, Sync.class);
} catch (Exception ex) {
logger.log(Level.SEVERE, "Could not fix component " + node, ex);