Skip to content

Instantly share code, notes, and snippets.

@paulrohrbeck
Last active June 18, 2024 17:58
Show Gist options
  • Save paulrohrbeck/574a59ad3887705f2f13e0a64f48da68 to your computer and use it in GitHub Desktop.
Save paulrohrbeck/574a59ad3887705f2f13e0a64f48da68 to your computer and use it in GitHub Desktop.
AEM: delete all translation projects and associated data (to be executed in Groovy console)
import com.adobe.cq.projects.api.*;
import org.apache.jackrabbit.api.security.user.*;
ProjectFilter pf = new ProjectFilter();
Boolean dryRun = true;
List<String> templates = Arrays.asList("/libs/cq/core/content/projects/templates/create-translation-project");
pf.setProjectTemplates(templates);
ProjectManager pm = resourceResolver.adaptTo(ProjectManager.class);
Iterator<Project> projects = pm.getProjects(pf, 0, 0);
while (projects.hasNext()) {
Project project = projects.next();
// also delete project assets folder:
Resource assetFolder = project.getAssetFolder();
if (assetFolder != null && !assetFolder.getPath().startsWith("/content/dam/projects")) {
log.error("Deleting project assets folder: {}", assetFolder.getPath());
if (!dryRun) {
resourceResolver.delete(assetFolder);
}
}
// also delete user goup
UserManager userManager = resourceResolver.adaptTo(UserManager.class);
Resource projectResource = project.adaptTo(Resource.class);
if (projectResource != null) {
log.error("Project Resource: {}", projectResource.getPath());
ValueMap resourceProperties = projectResource.getValueMap();
Iterator<String> propertyKeys = resourceProperties.keySet().iterator();
while (propertyKeys.hasNext()) {
String key = propertyKeys.next();
if (key.startsWith("role_")) {
String groupName = resourceProperties.get(key, String.class);
Authorizable authorizable = userManager.getAuthorizable(groupName);
log.error("Authorizable: {}", authorizable);
if (authorizable != null && !dryRun) {
authorizable.remove();
}
}
}
}
// todo: also delete all associated launches:
// finally, delete project:
log.error("Deleting project: {}, {}", project.getTitle(), project.adaptTo(Resource.class).getPath());
if (!dryRun) {
pm.deleteProject(project);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment