Here a groovy script to use when you have broken item states in some nodes on your magnolia public instance and you can't delete / republish / move / ... the content node.
WARNING: Use it and your own risk!
Download and install the openutils-mgnlgroovy module in your magnolia instance (see http://lab.openmindonline.it/lab/products/groovy.html ).
In admin central go to Tools > Groovy shell
Copy the following groovy script and paste in "Groovy script" code area.
package net.sourceforge.openutils.mgnlgroovy.scripts; import info.magnolia.cms.beans.config.ContentRepository import info.magnolia.cms.core.Content import info.magnolia.cms.core.HierarchyManager import info.magnolia.cms.core.ItemType import info.magnolia.cms.core.NodeData import info.magnolia.cms.core.Path import info.magnolia.cms.security.AccessManager import info.magnolia.cms.security.Permission import info.magnolia.cms.util.ContentUtil import info.magnolia.cms.util.NodeDataUtil import info.magnolia.context.MgnlContext import org.slf4j.Logger import org.slf4j.LoggerFactory import javax.jcr.AccessDeniedException import javax.jcr.RepositoryException import java.io.StringWriter import java.io.PrintWriter import org.apache.jackrabbit.core.ItemImpl import org.apache.jackrabbit.core.WorkspaceImpl import org.apache.jackrabbit.core.state.NodeState import java.util.ArrayList str = "" repo = "YOUR_REPO" nodeUUID = "NODE_UUID" brokenStateUUID = "ITEM_STATE_UUID" hm = MgnlContext.getSystemContext().getHierarchyManager(YOUR_REPO) try { c = hm.getContentByUUID(nodeUUID) itemid = c.getJCRNode().getId() ns = hm.getWorkspace().getItemStateManager().getItemState(itemid) if (ns.hasChildNodeEntries()) { // use temp array to avoid ConcurrentModificationException tmp = new ArrayList(ns.getChildNodeEntries()); for (int i = tmp.size() - 1; i >= 0; i--) { entry = tmp.get(i); // recursively remove child node if (entry.getId().getUUID().toString().equals(brokenStateUUID)) { ns.removeChildNodeEntry(entry.getId()) } } } c.delete() hm.save() } catch(Throwable t) { StringWriter sw = new StringWriter() PrintWriter pw = new PrintWriter(sw) t.printStackTrace(pw) str = sw.toString() } return str
Replace
- YOUR_REPO with your repo string
- NODE_UUID with the uuid of the node holding broken item state
- ITEM_STATE_UUID with the broken item state UUID
And now click run (...)
For the love of God, keep writnig these articles.
gWBBpi <a href="http://rhnenpyakmzy.com/">rhnenpyakmzy</a>
WRf4ye , [url=http://bdvrrvfjvdca.com/]bdvrrvfjvdca[/url], [link=http://gaerymgzrcwq.com/]gaerymgzrcwq[/link], http://porlyjxtrwxs.com/
V2RrOL <a href="http://eniggcrqptwi.com/">eniggcrqptwi</a>
2lyiRK , [url=http://qiebjykfwwed.com/]qiebjykfwwed[/url], [link=http://ehewambbqytk.com/]ehewambbqytk[/link], http://ygvhjifdmiqm.com/
A new script version that find all broken state, create a little report and erase the node (if you want...).
It's useful run the script with
check(c.getJCRNode(), hm, false)
in order to have a report for broken nodes.When you're sure to run the script and delete all nodes, switch third param to true.
Before run script, set the two variables repo and path with your repository and your path.
package net.sourceforge.openutils.mgnlgroovy.scripts; import info.magnolia.cms.core.HierarchyManager import info.magnolia.context.MgnlContext import org.apache.jackrabbit.core.ItemImpl import org.apache.jackrabbit.core.WorkspaceImpl import org.apache.jackrabbit.core.state.NodeState import org.apache.jackrabbit.uuid.UUID import org.apache.jackrabbit.core.NodeId import info.magnolia.cms.util.* import java.util.ArrayList repo = "YOUR_REPO" path = "YOUR_PATH" str = "" def check(node, hm, fix){ node.getNodes().each({ check(it, hm, fix) }) itemid = node.getId() ns = hm.getWorkspace().getItemStateManager().getItemState(itemid) def isbroken = false if (ns.hasChildNodeEntries()) { // use temp array to avoid ConcurrentModificationException tmp = new ArrayList(ns.getChildNodeEntries()); for (int i = tmp.size() - 1; i >= 0; i--) { entry = tmp.get(i); try { // if a state is broken, this call will throw a NoSuchItemStateException hm.getWorkspace().getItemStateManager().getItemState(entry.getId()) } catch(Exception ex) { str += "Broken state on node ${node.getPath()} with UUID: ${node.getUUID().toString()} (broken state id: ${entry.getId().getUUID().toString()})" if (fix) { str += "... broken state removed" ns.removeChildNodeEntry(entry.getId()) isbroken = true } str += "\n" } } } if (fix && isbroken) { node.remove() hm.save() } } hm = MgnlContext.getSystemContext().getHierarchyManager(repo) try { c = hm.getContent(path) str = "Started broken item states seeker on node ${c.getHandle()}" check(c.getJCRNode(), hm, false) } catch(Throwable t) { StringWriter sw = new StringWriter() PrintWriter pw = new PrintWriter(sw) t.printStackTrace(pw) str = sw.toString() } return str
Enjoy.
- Special thanks to Manuel, his groovy kung-fu it's stronger than my. -
Walking in the presence of giants here. Cool thinking all aronud!
BROasN <a href="http://reypsfdjvizw.com/">reypsfdjvizw</a>
vmckb8 , [url=http://sljqjyfdgjda.com/]sljqjyfdgjda[/url], [link=http://bafjghzjstsq.com/]bafjghzjstsq[/link], http://eaozbtqzdycd.com/
1f9vts <a href="http://pkodgstfjlfr.com/">pkodgstfjlfr</a>
RodsQL , [url=http://esdjjewiirlb.com/]esdjjewiirlb[/url], [link=http://myfqyrsnreyu.com/]myfqyrsnreyu[/link], http://newozontwhwh.com/
I'm quite pleased with the infortamion in this one. TY!
vx3Aur <a href="http://flmjhbtfuatx.com/">flmjhbtfuatx</a>
onvoPp , [url=http://ykvtzsvphjvp.com/]ykvtzsvphjvp[/url], [link=http://kjuzmkjacvoy.com/]kjuzmkjacvoy[/link], http://osglmovarbkc.com/
WA9rOU <a href="http://ivhoayjfnqwp.com/">ivhoayjfnqwp</a>
OcR2KL , [url=http://uzlqypzolnsw.com/]uzlqypzolnsw[/url], [link=http://avmfhbxxmmid.com/]avmfhbxxmmid[/link], http://mwaemnqwqmkq.com/

Sorry but...
hm = MgnlContext.getSystemContext().getHierarchyManager(YOUR_REPO)
shuld be:
hm = MgnlContext.getSystemContext().getHierarchyManager(repo)
Strap