Last active
February 6, 2017 19:05
-
-
Save AFaust/6722303 to your computer and use it in GitHub Desktop.
Example: JavaScript batch process to clear user homes using the Alfresco Enhanced Script Environment and its batch processing capabilities. See https://github.com/AFaust/alfresco-enhanced-script-environment and https://github.com/AFaust/alfresco-enhanced-script-environment/wiki/Batch-Processing
This file contains hidden or 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
| // character codes for 'a' to 'z' | |
| var charCode = 97, max = 122; | |
| // userProvider provides batches of users based on first name initial character | |
| function userProvider() | |
| { | |
| var results = [], initial; | |
| while(results.length === 0 && charCode <= max) | |
| { | |
| initial = String.fromCharCode(charCode++); | |
| results = people.getPeople('firstName:' + initial + '*'); | |
| } | |
| return results; | |
| } | |
| // userHomeClearer removes all content from the user home of a person | |
| function userHomeClearer(person) | |
| { | |
| var userHomeRef, userHome, children, idx, max; | |
| // we know people only returns NodeRefs, not ScriptNode | |
| person = search.findNode(person.toString()); | |
| userHomeRef = person.properties.homeFolder; | |
| userHome = userHomeRef !== undefined && userHomeRef !== null ? search.findNode(userHomeRef.toString()) : null; | |
| if(userHome !== null) | |
| { | |
| children = userHome.children; | |
| for(idx = 0, max = children.length; idx < max; idx++) | |
| { | |
| children[idx].remove(); | |
| } | |
| } | |
| } | |
| // execute in up to 4 threads (if allowed by Repository) and process each person in individual batch run | |
| executeBatch(userProvider, userHomeClearer, 4, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment