Created
January 28, 2015 15:12
-
-
Save flox1an/2a726224e23381fa41f9 to your computer and use it in GitHub Desktop.
Change username for cm:owner cm:creator cm:modifier in Alfresco Javascript Console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ctx = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext(); | |
var behaviourFilter = ctx.getBean("policyBehaviourFilter"); | |
// ----------------------------------------------------------------- | |
function findAndReplaceAttribute(query, attribute, value) { | |
nodes = search.luceneSearch(query); | |
for each(var node in nodes) { | |
logger.log("Changing property "+attribute+" from value '"+ node.properties[attribute]+"' of node " + node.nodeRef + " to value '"+value+"'"); | |
behaviourFilter.disableBehaviour(node.nodeRef); | |
node.properties[attribute] = value; | |
node.save(); | |
} | |
} | |
// ----------------------------------------------------------------- | |
var oldUser = "oldusername", newUser = "newusername"; | |
findAndReplaceAttribute("+@cm\\:modifier:" + oldUser, "cm:modifier", newUser); | |
findAndReplaceAttribute("+@cm\\:creator:" + oldUser, "cm:creator", newUser); | |
findAndReplaceAttribute("+@cm\\:owner:" + oldUser, "cm:owner", newUser); |
This should work on Alfresco 5.x:
var ctx = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
var cls = org.alfresco.repo.policy.BehaviourFilterImpl;
var behaviourFilters = ctx.getBeansOfType(cls);
var filter = null;
for (var i in behaviourFilters) {
if (i === "policyBehaviourFilter") {
filter = behaviourFilters[i];;
break;
}
}
print(filter);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Florian.
In Alfresco One 5.1 i have this error :
org.springframework.extensions.webscripts.WebScriptException: 00180057 Wrapped Exception (with status template): 001815817 Failed to execute script 'Javascript Console Script': Invalid bean definition with name 'policyBehaviourFilter' defined in class path resource [alfresco/policy-context.xml]: Can only specify arguments for the getBean method when referring to a prototype bean definition
I'll try to fix it or another solution
Jérémie