Exécutez le script suivant pour migrer l'ensemble de vos services.

Réconstruisez le workspace Live ensuite.

Télécharger le script (32.9 KB)

var ConsoleHelper = Java.type('org.ametys.workspaces.repository.ConsoleHelper');     
function __getServicesNodes(serviceId)                            
{                            
    var query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:type = 'SERVICE' and @ametys-internal:service = '" + serviceId + "']", javax.jcr.query.Query.XPATH);                                    
    return query.execute().getNodes();                              
}                            
                 
function __migrateService(node, params)                            
{                            
    var paramsNode = node.getNode("ametys:service_parameters");                            
    var hasChanges = false;                            
    for (var name in params)                            
    {                                    
      var hasChanges = false;                            
      var type = params[name];                            
      if (type == 'long')                            
      {                            
        hasChanges = __convertStringPropertyToLong(paramsNode, "ametys:" + name) || hasChanges;                            
      }                            
      else if (type == 'boolean')                            
      {                            
        hasChanges = __convertStringPropertyToBoolean(paramsNode, "ametys:" + name) || hasChanges;                            
      }                   
      else if (type == 'user')                   
      {                   
        hasChanges = __convertStringPropertyToUser(paramsNode, "ametys:" + name) || hasChanges;                   
      }                   
    }                            
                             
    return hasChanges;                                  
}                            
                 
function __convertStringPropertyToBoolean(node, propertyName)                                    
{                                   
  var hasChanged = false;                                    
  if (node.hasProperty(propertyName))                                    
  {                                    
    var property = node.getProperty(propertyName);                              
    if (property.getType() == 1) // 1 is for string                                    
    {                                    
      var valueAsString = property.getString();                                    
      property.remove();                                    
                                  
      if (valueAsString == "true")                                    
      {                                    
        node['setProperty(java.lang.String, boolean)'](propertyName, true);                                    
        hasChanged = true;                                    
      }                                    
      else if (valueAsString == "false")                                    
      {                                    
        node['setProperty(java.lang.String, boolean)'](propertyName, false);                                    
        hasChanged = true;                                    
      }                                    
    }                                    
  }                                        
  return hasChanged;                                    
}                            
                 
function __convertStringPropertyToLong(node, propertyName)                                    
{                                    
  var hasChanged = false;                                    
  if (node.hasProperty(propertyName))                                    
  {                                    
    var property = node.getProperty(propertyName);                                    
    if (property.getType() == 1) // 1 is for string                                    
    {                                    
      var valueAsString = property.getString();                                    
      property.remove();                                    
                                  
      if (valueAsString)                                    
      {                                      
        node['setProperty(java.lang.String, long)'](propertyName, Number(valueAsString));                                    
        hasChanged = true;                                    
      }                                    
    }                                    
  }                                          
  return hasChanged;                                    
}                   
                 
function __convertStringPropertyToUser(node, propertyName)                   
{                   
  var hasChanged = false;                   
  if (node.hasProperty(propertyName))                   
  {                   
    var property = node.getProperty(propertyName);                   
    if (property.getType() == 1) // 1 is for string                   
    {                   
      var valueAsString = property.getString();                   
      property.remove();                   
                   
     if (valueAsString)                   
     {                   
       var jsonUtils = serviceManager.lookup('org.ametys.core.util.JSONUtils');                   
       var userMap = jsonUtils.convertJsonToMap(valueAsString);                   
                         
       var userNode = node['addNode(java.lang.String, java.lang.String)'](propertyName, 'ametys:user');                   
       userNode['setProperty(java.lang.String, java.lang.String)']('ametys:login', userMap.get("login"));                   
       userNode['setProperty(java.lang.String, java.lang.String)']('ametys:population', userMap.get("populationId"));                   
                         
       hasChanged = true;                   
     }                   
    }                   
   }                   
   return hasChanged;                   
}        
        
function __convertStringPropertyToMultipleUser(node, propertyName)        
{        
  var hasChanged = false;        
  if (node.hasProperty(propertyName))        
  {        
    var property = node.getProperty(propertyName);        
    if (property.getType() == 1) // 1 is for string        
    {        
      var values = property.getValues();        
      property.remove();        
        
      if (values)        
      {        
        var jsonUtils = serviceManager.lookup('org.ametys.core.util.JSONUtils');        
        var usersNode = node['addNode(java.lang.String, java.lang.String)'](propertyName, 'ametys:multipleItem');        
 usersNode['setProperty(java.lang.String, java.lang.String)']('ametys-internal:typeId', 'user');        
        
        for (var i = 0; i < values.length; i++)        
        {        
          var user = jsonUtils.convertJsonToMap(values[i].getString());        
          var nodeIndex = i + 1;        
          var userNode = usersNode['addNode(java.lang.String, java.lang.String)']('ametys:' + nodeIndex, 'ametys:user');        
          userNode['setProperty(java.lang.String, java.lang.String)']('ametys:login', user.get("login"));        
          userNode['setProperty(java.lang.String, java.lang.String)']('ametys:population', user.get("populationId"));        
        }        
        
        hasChanged = true;        
      }        
    }        
  }        
  return hasChanged;        
}        
        
function __removeStringPropertyIfEmpty(node, propertyName)        
{        
  var hasChanged = false;        
  if (node.hasProperty(propertyName))        
  {        
    var property = node.getProperty(propertyName);        
    if (property.getType() == 1) // 1 is for string        
    {        
      var valueAsString = property.getString();        
        
      if (!valueAsString)        
      {        
        property.remove();        
        hasChanged = true;        
      }        
    }        
  }        
  return hasChanged;        
}        
        
function migrateGoogleCalendarService()                            
{                            
    var params = {'iframe-height': 'long', 'iframe-border': 'boolean', 'showTitle': 'boolean', 'showNav': 'boolean', 'showDate': 'boolean', 'showPrint': 'boolean', 'showTabs': 'boolean', 'showCalendars': 'boolean', 'showTz': 'boolean'};                            
    var nodes = __getServicesNodes('org.ametys.plugins.google-calendar.service.Calendar');                            
    var count = 0;                               
    while (nodes.hasNext())                               
    {                            
        if (__migrateService(nodes.nextNode(), params))                            
        {                            
          count++;                            
        }                            
    }                            
                             
    if (count > 0)                            
    {                            
        session.save();                            
        print(count + " google calendar services have been migrated.");                            
    }                              
}                               
                 
function migrateFilteredContentsService()                            
{                            
    var params = {'nb-max': 'long', 'pagination': 'long', 'mask-orphan': 'boolean', 'handle-user-access': 'boolean', 'rss': 'boolean'};                            
    var nodes = __getServicesNodes('org.ametys.web.service.FilteredContentsService');                            
    var count = 0;                               
    while (nodes.hasNext())                               
    {                            
        var node = nodes.nextNode();                            
        var hasChanges = __migrateService(node, params);                            
                                    
        var paramsNode = node.getNode("ametys:service_parameters");                            
        var repeaterEntries = paramsNode.getNode("ametys:search").getNodes();                                    
        while (repeaterEntries.hasNext())                                    
        {                                    
          var repeaterEntry = repeaterEntries.nextNode();                                    
          hasChanges = __convertStringPropertyToBoolean(repeaterEntry, "ametys:strict-search-on-tags") || hasChanges;                                    
        }                               
                                
        if (hasChanges)                            
        {                            
          count++;                            
        }                            
    }                            
                             
    if (count > 0)                            
    {                            
        session.save();                            
        print(count + " filtered contents services have been migrated.");                            
    }                               
}                                
                 
function migratePostsService()                            
{                            
    var params = {'year': 'long', 'month': 'long'};                            
    var nodes = __getServicesNodes('org.ametys.blog.service.PostsService');                            
    var count = 0;                               
    while (nodes.hasNext())                               
    {                            
        if (__migrateService(nodes.nextNode(), params))                            
        {                            
          count++;                            
        }                            
    }                            
                             
    if (count > 0)                            
    {                            
        session.save();                            
        print(count + " posts services have been migrated.");                            
    }                              
}                              
                 
function migratePostsByTagsService()                            
{                            
    var params = {'excludePrivateTags': 'boolean'};                            
    var nodes = __getServicesNodes('org.ametys.blog.service.PostsByTagsService');                            
    var count = 0;                               
    while (nodes.hasNext())                               
    {                            
        if (__migrateService(nodes.nextNode(), params))                            
        {                            
          count++;                            
        }                            
    }                            
                             
    if (count > 0)                            
    {                            
        session.save();                            
        print(count + " posts services have been migrated.");                            
    }                              
}                            
                             
function migrateLinkDirectoryService()                            
{                            
    var params = {'displayUserLinks': 'boolean', 'configurable': 'boolean', 'showUrl': 'boolean', 'showThemes': 'boolean'};                            
    var nodes = __getServicesNodes('org.ametys.plugins.linkdirectory.DirectoryService');                            
    var count = 0;                               
    while (nodes.hasNext())                               
    {                            
        if (__migrateService(nodes.nextNode(), params))                            
        {                            
          count++;                            
        }                            
    }                            
                             
    if (count > 0)                            
    {                            
        session.save();                            
        print(count + " link directory services have been migrated.");                            
    }                              
}                              
                 
function migrateExternalSearchService()                            
{                            
    var params = {'limit': 'long'};                            
    var nodes = __getServicesNodes('org.ametys.plugins.external.data.search.service');                            
    var count = 0;                               
    while (nodes.hasNext())                               
    {                            
        if (__migrateService(nodes.nextNode(), params))                            
        {                            
          count++;                            
        }                            
    }                            
                             
    if (count > 0)                            
    {                            
      session.save();                            
      print(count + " external search services have been migrated.");                            
    }                              
}                            
                 
function migrateCalendarService()                            
{                            
    var params = {'months-before': 'long', 'months-after': 'long', 'contents-on-same-page': 'boolean', 'handle-user-access': 'boolean'};                            
    var nodes = __getServicesNodes('org.ametys.plugins.calendar.Calendar');                            
    var count = 0;                               
    while (nodes.hasNext())                               
    {                            
        if (__migrateService(nodes.nextNode(), params))                            
        {                            
          count++;                            
        }                            
    }                            
                             
    if (count > 0)                            
    {                            
      session.save();                            
      print(count + " calendar services have been migrated.");                            
    }                              
}                            
                 
function migrateAgendaService()                            
{                            
    var params = {'months-before': 'long', 'months-after': 'long', 'mask-orphan': 'boolean', 'handle-user-access': 'boolean', 'pdf-download': 'boolean', 'ical-download': 'boolean', 'rss': 'boolean'};                            
    var nodes = __getServicesNodes('org.ametys.plugins.calendar.Agenda');                            
    var count = 0;                               
    while (nodes.hasNext())                               
    {                            
        if (__migrateService(nodes.nextNode(), params))                            
        {                            
          count++;                            
        }                            
    }                            
                             
    if (count > 0)                            
    {                            
      session.save();                            
      print(count + " agenda services have been migrated.");                            
    }                              
}                           
                 
function migrateFilteredPagesService()                           
{                           
    var params = {'nb-max': 'long', 'pagination': 'long'};                           
    var nodes = __getServicesNodes('org.ametys.web.service.FilteredPagesService');                           
    var count = 0;                              
    while (nodes.hasNext())                              
    {                           
        if (__migrateService(nodes.nextNode(), params))                           
        {                           
          count++;                           
        }                           
    }                           
                            
    if (count > 0)                           
    {                           
      session.save();                           
      print(count + " filtered pages services have been migrated.");                           
    }                             
}                        
                 
function migrateNewsletterListService()                        
{                        
    var params = {'length': 'long', 'rss': 'boolean'};                        
    var nodes = __getServicesNodes('org.ametys.newsletter.service.ListService');                        
    var count = 0;                        
    while (nodes.hasNext())                        
    {                        
        if (__migrateService(nodes.nextNode(), params))                        
        {                        
            count++;                        
        }                        
    }                        
                        
    if (count > 0)                        
    {                        
        session.save();                        
        print(count + " newsletter list services have been migrated.");                        
    }                        
}                        
                 
function migrateSitemapService()                        
{                        
    var params = {'depth': 'long', 'includeInvisiblePage': 'boolean'};                        
    var nodes = __getServicesNodes('org.ametys.web.service.SitemapService');                        
    var count = 0;                        
    while (nodes.hasNext())                        
    {                        
        if (__migrateService(nodes.nextNode(), params))                        
        {                        
            count++;                        
        }                        
    }                        
                        
    if (count > 0)                        
    {                        
        session.save();                        
        print(count + " sitemap services have been migrated.");                        
    }                        
}                        
                 
function migrateIframeService()                        
{                        
    var params = {'iframe-height': 'long', 'iframe-border': 'boolean', 'transparancy': 'boolean'};                        
    var nodes = __getServicesNodes('org.ametys.web.service.IframeService');                        
    var count = 0;                        
    while (nodes.hasNext())                        
    {                        
        if (__migrateService(nodes.nextNode(), params))                        
        {                        
            count++;                        
        }                        
    }                        
                        
    if (count > 0)                        
    {                        
        session.save();                        
        print(count + " iframe services have been migrated.");                        
    }                        
}                        
                 
function migrateProgramListService()                       
{                       
    var params = {'alphaOrderOnFirstLevel': 'boolean', 'alphaOrderOnSecondLevel': 'boolean', 'displaySubProgram': 'boolean'};                       
    var nodes = __getServicesNodes('org.ametys.odf.service.ProgramList');                       
    var count = 0;                       
    while (nodes.hasNext())                       
    {                       
        if (__migrateService(nodes.nextNode(), params))                       
        {                       
            count++;                       
        }                       
    }                       
                       
    if (count > 0)                       
    {                       
        session.save();                       
        print(count + " program list services have been migrated.");                       
    }                       
}                       
                 
function migrateServerDirectoryService()                       
{                       
    var params = {'enableDynamicPaths': 'boolean'};                       
    var nodes = __getServicesNodes('org.ametys.plugins.server.directory');                       
    var count = 0;                       
    while (nodes.hasNext())                       
    {                       
        if (__migrateService(nodes.nextNode(), params))                       
        {                       
            count++;                       
        }                       
    }                       
                       
    if (count > 0)                       
    {                       
        session.save();                       
        print(count + " server directory services have been migrated.");                       
    }                       
}                       
                 
function migrateWordsService()                       
{                       
    var params = {'limit': 'long'};                       
    var nodes = __getServicesNodes('org.ametys.plugins.tagcloud.services.Words');                       
    var count = 0;                       
    while (nodes.hasNext())                       
    {                       
        if (__migrateService(nodes.nextNode(), params))                       
        {                       
            count++;                       
        }                       
    }                       
                       
    if (count > 0)                       
    {                       
        session.save();                       
        print(count + " words services have been migrated.");                       
    }                       
}                       
                 
function migrateTagsService()                       
{                       
    var params = {'limit': 'long'};                       
    var nodes = __getServicesNodes('org.ametys.plugins.tagcloud.services.Tags');                       
    var count = 0;                       
    while (nodes.hasNext())                       
    {                       
        if (__migrateService(nodes.nextNode(), params))                       
        {                       
            count++;                       
        }                       
    }                       
                       
    if (count > 0)                       
    {                       
        session.save();                       
        print(count + " tags services have been migrated.");                       
    }                       
}                   
                 
function migrateUGCService()                   
{                   
  var params = {'user': 'user'};                   
  var nodes = __getServicesNodes('org.ametys.plugin.ugc.service.UGC');                   
  var count = 0;                   
  while (nodes.hasNext())                   
  {                   
    if (__migrateService(nodes.nextNode(), params))                   
    {                   
      count++;                   
    }                   
  }                   
                   
  if (count > 0)                   
  {                   
    session.save();                   
    print(count + " UGC services have been migrated.");                   
  }                   
}                  
                 
function migrateRevampingService()                  
{                  
  var params = {'cas': 'boolean'};                  
  var nodes = __getServicesNodes('org.ametys.proxied-content.service.Revamping');                  
  var count = 0;                  
  while (nodes.hasNext())                  
  {                  
    if (__migrateService(nodes.nextNode(), params))                  
    {                  
      count++;                  
    }                  
  }                  
                 
  if (count > 0)                  
  {                  
    session.save();                  
    print(count + " revamping services have been migrated.");                  
  }                  
}             
        
function migrateFilteredPostsService()                  
{                  
  var params = {'pagination': 'long'};                  
  var nodes = __getServicesNodes('org.ametys.plugins.blog.service.FilteredPostsService');                  
  var count = 0;                  
  while (nodes.hasNext())                  
  {                  
    if (__migrateService(nodes.nextNode(), params))                  
    {                  
      count++;                  
    }                  
  }                  
                 
  if (count > 0)                  
  {                  
    session.save();                  
    print(count + " filtered posts services have been migrated.");                  
  }                  
}            
        
function migrateShowTweetsService()            
{            
  var params = {'max': 'long'};            
  var nodes = __getServicesNodes('org.ametys.plugins.socialnetworking.twitter.showtweets');            
  var count = 0;            
  while (nodes.hasNext())            
  {            
    if (__migrateService(nodes.nextNode(), params))            
    {            
      count++;            
    }            
  }            
        
  if (count > 0)            
  {            
    session.save();            
    print(count + " swhow tweets services have been migrated.");            
  }            
}           
        
function migrateSearchService()          
{          
  var params = {'advanced-search': 'boolean', 'strict-search-on-tags': 'boolean', 'search-multisite': 'boolean', 'facets': 'boolean', 'offset': 'long', 'withWorkspaces': 'boolean'};          
  var nodes = __getServicesNodes('org.ametys.web.service.FrontSearchService');          
  var count = 0;          
  while (nodes.hasNext())          
  {          
    if (__migrateService(nodes.nextNode(), params))          
    {          
      count++;          
    }          
  }          
          
  if (count > 0)          
  {          
    session.save();          
    print(count + " search services have been migrated.");          
  }          
}          
        
function migrateResourcesSearchService()          
{          
  var params = {'offset': 'long', 'search-by-format': 'boolean', 'search-by-creator': 'boolean', 'search-by-publisher': 'boolean', 'search-by-rights': 'boolean', 'search-multisite': 'boolean', 'on-same-page': 'boolean'};          
  var nodes = __getServicesNodes('org.ametys.web.service.ResourcesSearchService');          
  var count = 0;          
  while (nodes.hasNext())          
  {          
    if (__migrateService(nodes.nextNode(), params))          
    {          
      count++;          
    }          
  }          
          
  if (count > 0)          
  {          
    session.save();          
    print(count + " resources search services have been migrated.");          
  }          
}          
        
function migrateODFSearchService()          
{          
  var params = {'advanced-search': 'boolean', 'subprogram-search': 'boolean', 'facets': 'boolean', 'offset': 'long'};          
  var nodes = __getServicesNodes('org.ametys.odf.service.SearchService');          
  var count = 0;          
  while (nodes.hasNext())          
  {          
    if (__migrateService(nodes.nextNode(), params))          
    {          
      count++;          
    }          
  }          
          
  if (count > 0)          
  {          
    session.save();          
    print(count + " (ODF) search services have been migrated.");          
  }          
}          
        
function migrateSearchCourseService()          
{          
  var params = {'advanced-search': 'boolean', 'facets': 'boolean', 'displayProgramReferences': 'boolean', 'offset': 'long'};          
  var nodes = __getServicesNodes('org.ametys.odf.service.SearchCourseService');          
  var count = 0;          
  while (nodes.hasNext())          
  {          
    if (__migrateService(nodes.nextNode(), params))          
    {          
       count++;          
    }          
  }          
          
  if (count > 0)          
  {          
    session.save();          
    print(count + " search courses services have been migrated.");          
  }          
}        
        
function migrateSyndicationService()        
{        
  var params = {'length': 'long', 'nb-feed-user': 'long', 'nb-feed-max': 'long'};        
  var nodes = __getServicesNodes('org.ametys.plugins.syndication.service.RSS');        
  var count = 0;        
  while (nodes.hasNext())        
  {        
    var node = nodes.nextNode();        
    var hasChanges = __migrateService(node, params);        
        
    var paramsNode = node.getNode("ametys:service_parameters");        
    var repeaterEntries = paramsNode.getNode("ametys:feeds").getNodes();        
    while (repeaterEntries.hasNext())        
    {        
      var repeaterEntry = repeaterEntries.nextNode();        
      hasChanges = __convertStringPropertyToLong(repeaterEntry, "ametys:length") || hasChanges;        
      hasChanges = __convertStringPropertyToBoolean(repeaterEntry, "ametys:limited") || hasChanges;        
   hasChanges = ConsoleHelper.convertSingleToMultipleProperty(repeaterEntry, "ametys:fo-user") || hasChanges;      
 hasChanges = ConsoleHelper.convertSingleToMultipleProperty(repeaterEntry, "ametys:fo-group") || hasChanges;      
 hasChanges = __convertStringPropertyToMultipleUser(repeaterEntry, "ametys:fo-user") || hasChanges;        
      hasChanges = __removeStringPropertyIfEmpty(repeaterEntry, "ametys:cache") || hasChanges;        
    }        
        
    if (hasChanges)        
    {        
      count++;        
    }        
  }        
        
  if (count > 0)        
  {        
    session.save();        
    print(count + " syndication RSS services have been migrated.");        
  }        
}      

function migrateOrganizationChartService()   
{   
 var nodes = __getServicesNodes('org.ametys.plugins.userdirectory.service.OrganizationChart');   
 var count = 0; 
   
 while (nodes.hasNext())   
 {   
 var node = nodes.nextNode();   
 var paramsNode = node.getNode("ametys:service_parameters");   
   
 if (node.hasProperty("ametys:maxLevel"))   
 {   
 var property = node.getProperty("ametys:maxLevel");   
   
 var property = node.getProperty(propertyName);   
 if (property.getType() == 1) // 1 is for string   
 {   
 count++;   
 var value = Number(property.getString());   
 property.remove();   
   
 if (value >= 1) // If the property is not filled, then value == 0   
 {   
 node['setProperty(java.lang.String, long)']("ametys:maxLevel", value);   
 }   
 }   
 }   
 }   
   
 if (count > 0)   
 {   
 session.save();   
 print(count + " organization chart services have been migrated.");   
 }   
}   
                 
var qm = session.getWorkspace().getQueryManager();                              
                                         
migrateOrganizationChartService();   
migrateGoogleCalendarService();                              
migrateLinkDirectoryService();                                                
migrateServerDirectoryService();                        
migrateWordsService();                        
migrateTagsService();                                    
migrateRevampingService();                            
migrateSitemapService();                        
migrateIframeService();                
migrateExternalSearchService();                
migrateUGCService();                                        
migratePostsService();               
migratePostsByTagsService();               
migrateCalendarService();               
migrateAgendaService();               
migrateProgramListService();                        
migrateNewsletterListService();                 
migrateShowTweetsService();                   
migrateSearchService();          
migrateResourcesSearchService();          
migrateODFSearchService();          
migrateSearchCourseService();          
migrateFilteredContentsService();                           
migrateFilteredPagesService();             
migrateFilteredPostsService();            
migrateSyndicationService();        
                 
print("End of migration, you can rebuild the Live workspace");                            
Retour en haut