First of all:

  • Shut down the server
  • Delete custom-nodetypes.xml
  • Restart the server

Link directory service

The service has been migrated, so the parameters are typed and the following script must be passed:

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" || valueAsString == "false")                 
             {                 
                 ConsoleHelper.setProperty(node, propertyName, valueAsString == "true");                
             }                 
             hasChanged = true;                 
         }                     
     }                 
                 
     return hasChanged;                 
 }                 
                 
 var qm = session.getWorkspace().getQueryManager();                 
 var query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:type = 'SERVICE' and @ametys-internal:service = 'org.ametys.plugins.linkdirectory.DirectoryService']", javax.jcr.query.Query.XPATH);                 
 var nodes = query.execute().getNodes();                 
 var count = 0;                 
 while (nodes.hasNext())                 
 {                 
     var node = nodes.nextNode().getNode("ametys:service_parameters");                 
     var hasChanges = convertStringPropertyToBoolean(node, "ametys:displayUserLinks");                 
     hasChanges = convertStringPropertyToBoolean(node, "ametys:configurable") || hasChanges;                 
     hasChanges = convertStringPropertyToBoolean(node, "ametys:showUrl") || hasChanges;                 
     hasChanges = convertStringPropertyToBoolean(node, "ametys:showThemes") || hasChanges;                 
                 
     if (hasChanges)                 
     {                 
         count++;                 
     }                    
 }                 
                 
 session.save();                 
 print(count + " updated link directory services.");                    

Rebuild the Live workspace to apply these changes to published pages.

Restricted access

Restricting access to links is now based on the new :

  • A public link is a link for which the "Reader" profile is authorized for Anonymous.
  • A private link is a link for which the "Reader" profile is excluded for Anonymous.


Run the following script to migrate your links:

var ConsoleHelper = Java.type('org.ametys.workspaces.repository.ConsoleHelper');    

// Profil Lecteur    
var readerProfile = Java.to(['READER'], "java.lang.String[]")    

var query = session.getWorkspace().getQueryManager().createQuery("//element(*, ametys:directoryLink)", javax.jcr.query.Query.XPATH);    
var nodes = query.execute().getNodes();    

var count = 0;    
while (nodes.hasNext())    
{    
var node = nodes.next();    
var hasChanged = false;    
if (!node.hasProperty("ametys-internal:status"))    
{    
node.setProperty("ametys-internal:status", "NORMAL");    
hasChanged = true;    
}    
if (!node.hasNode('ametys-internal:acl'))    
{    
var aclNode = node.addNode("ametys-internal:acl", "ametys:acl");    

var grantAnyUser = node.hasProperty("ametys-internal:grant-any-user") ? node.getProperty("ametys-internal:grant-any-user").getBoolean() : false;    
if (grantAnyUser)    
{    
ConsoleHelper.setProperty(aclNode, "ametys:denied-anonymous-profiles", readerProfile );    
}    
else    
{    
// Set ACL for anonymous    
ConsoleHelper.setProperty(aclNode, "ametys:allowed-anonymous-profiles", readerProfile);    
ConsoleHelper.setProperty(aclNode, "ametys:allowed-any-connected-profiles", readerProfile);    
}    
if (node.hasProperty("ametys-internal:grant-any-user"))    
{    
node.getProperty("ametys-internal:grant-any-user").remove();    
}    

if (node.hasNode('ametys-internal:granted-users'))    
{    
// Migrate ACL for users    
var parentNode = node.getNode("ametys-internal:granted-users");    
var usersNode = aclNode.addNode("users", "nt:unstructured");    

var oldUsersNodes = parentNode.getNodes();    
while (oldUsersNodes.hasNext())    
{    
var oldUserNode = oldUsersNodes.next();    
var userPopulation = oldUserNode.getProperty("ametys:population").getString();    

if (!usersNode.hasNode(userPopulation))    
{    
usersNode.addNode(userPopulation, "nt:unstructured");    
}    

var popNode = usersNode.getNode(userPopulation);    
var login = oldUserNode.getProperty("ametys:login").getString();    
var userNode = popNode.addNode(login, "ametys:acl-user");    
ConsoleHelper.setProperty(userNode, "ametys:allowed-profiles", readerProfile);    
}    
parentNode.remove();    
}    
if (node.hasNode('ametys-internal:granted-groups'))    
{    
// Migrate ACL for groups    
var parentNode = node.getNode("ametys-internal:granted-groups");    
var groupsNode = aclNode.addNode("groups", "nt:unstructured");    
var oldGroupsNodes = parentNode.getNodes();    
while (oldGroupsNodes.hasNext())    
{    
var oldGroupNode = oldGroupsNodes.next();    
var groupDirectory = oldGroupNode.getProperty("ametys:groupDirectory").getString();    

if (!groupsNode.hasNode(groupDirectory))    
{    
groupsNode.addNode(groupDirectory, "nt:unstructured");    
}    

var dirNode = groupsNode.getNode(groupDirectory);    

var groupId = oldGroupNode.getProperty("ametys:groupId").getString();    
var gpNode = dirNode.addNode(groupId, "ametys:acl-group");    
ConsoleHelper.setProperty(gpNode, "ametys:allowed-profiles", readerProfile);    
}    
parentNode.remove();    
}    
hasChanged = true;    
}    
if (hasChanged)    
{    
session.save();    
count++;    
}    
}    
print(count + " links have been updated");    
Back to top