DevOps System Administrator Jahia 7.3 Jahia 8

Howto remove mixin in a subtree

Question

After a wrong manipulation, all nodes of a subtree have the mixin jmix:markedForDeletion. Is there a way to remove this mixin (or any mixin) from a subtree?

Answer

You can do it by manually using the JCR repository browser from the tools at http://localhost:8080/modules/tools/jcrBrowser.jsp

First, you need to click on the show action checkbox then click on the small [x] after the mixin name.

remove-mixin.png

If you want to do it on a whole subtree, you may prefer to play a groovy script from the Groovy console http://localhost:8080/tools/groovyConsole.jsp that could look like this:

import org.jahia.api.Constants
import org.jahia.services.content.*
import org.jahia.services.sites.JahiaSite

import javax.jcr.NodeIterator
import javax.jcr.RepositoryException
import javax.jcr.query.Query
boolean doIt = false;
def logger = log;
String mixin = "jmix:markedForDeletion";
def JahiaSite site = org.jahia.services.sites.JahiaSitesService.getInstance().getSiteByKey("bostik_global");

for (Locale locale : site.getLanguagesAsLocales()) {
    JCRTemplate.getInstance().doExecuteWithSystemSession(null, Constants.EDIT_WORKSPACE, locale, new JCRCallback() {
        @Override
        Object doInJCR(JCRSessionWrapper session) throws RepositoryException {
            def q = "SELECT * FROM [" + mixin + "] where isdescendantnode('/sites/my-site/home/footer')";

            NodeIterator iterator = session.getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2).execute().getNodes();
            while (iterator.hasNext()) {
                final JCRNodeWrapper node = (JCRNodeWrapper) iterator.nextNode();
                logger.info("Remove mixin " + mixin + " for " + node.getPath());
                node.removeMixin(mixin);
            }
            if (doIt) {
                session.save();
            }
            return null;
        }
    }
    );
}


This script simply searches the all nodes of the mixin type, under a certain path.

So, you may need to alter the mixin to search for, as the descendant path (in the query)