This page should only be used if the application asks you to manually migrate plugin.workspaces.jcr.v20210702T0000-WORKSPACES-858

Deleting old jobs

Here's script to delete tasks from the old module. First, set the saveChanges variable to false at script to list the tasks to be deleted.

Then set saveChanges to true to delete the tasks.

let saveChanges = false;
let logger = Ametys.getLogger("org.ametys.core.migration.MigrationExtensionPoint.workspaces");  
let projectManager = Ametys.serviceManager.lookup(org.ametys.plugins.workspaces.project.ProjectManager.ROLE);
let workspaceModuleExtensionPoint = Ametys.serviceManager.lookup(org.ametys.plugins.workspaces.project.modules.WorkspaceModuleExtensionPoint.ROLE);

projectManager.getProjects().forEach(function (project) 
{
    let module = workspaceModuleExtensionPoint.getModule('org.ametys.plugins.workspaces.tasks.TasksWorkspaceModule');
    let pages = projectManager.getModulePages(project, module);
    for (let page of pages)
    {
        migratePage(project, page);
        
        try 
        {
            let liveProject = Repository.resolver.resolveById(project.getId(), Repository.liveSession);
            let livePage = Repository.resolver.resolveById(page.getId(), Repository.liveSession);
            migratePage(liveProject, livePage);
        }
      catch (e) {/* No page live */}
        
    }
});

function migratePage(project, page)
{
    if (page.getNode().hasNode("ametys-internal:zones/default/ametys-internal:zoneItems/ametys:zoneItem/ametys:service_parameters"))
    {
        let serviceNode = page.getNode().getNode("ametys-internal:zones/default/ametys-internal:zoneItems/ametys:zoneItem/ametys:service_parameters");   
        if (serviceNode.getProperty("ametys:xslt").getString() == "pages/services/modules/taskslist/task-default.xsl")
        {
            let projectRootNode = project.getExplorerRootNode();
            let taskNode = projectRootNode.getChild("tasks");
          if (taskNode.hasChild("default"))
            {
                logger.info("Delete tasks for project '" + project.getTitle() + "'");
                logger.info("Delete section default");   
              let taskNode = projectRootNode.getChild("tasks");
                let tasksList = taskNode.getChild("default");
    
              for (let task of tasksList.getChildren())
              { 
                  logger.info("Delete task " + task.getLabel()); 
                }
     
              if (saveChanges)
                {
                    tasksList.remove();
                    projectRootNode.saveChanges();
              }
            }
        }
    }
}
Back to top