Dernière publication:06/09/2018à 09:17RaphaëlFranchet
Migration des liens de l'annuaire
Arrêtez le serveur, supprimez le custom-nodetypes.xml, puis redémarrez le serveur (si vous l'avez déjà fait cette procédure une fois, ce n'est pas la peine de la refaire)
Exécutez le script suivant en modifier la valeur des variables populationId et groupDirectory selon vos propres données.
Script de migration des liens
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
var populationId = "ametys_demo_users"; // value of the id of the population your users belong to
var groupDirectoryId= "groupes-sql"; // value of the id of the group directory your groups belong to
function convertGrantedUsers(node)
{
if (node.hasProperty("ametys-internal:granted-users"))
{
var logins = node.getProperty("ametys-internal:granted-users").getValues();
node.getProperty("ametys-internal:granted-users").remove();
var rootNode = node.addNode("ametys-internal:granted-users", "ametys:linkGrantedUsers");
for (var i=0; i < logins.length; i++)
{
var userNode = rootNode.addNode("ametys-internal:granted-user", "ametys:user");
userNode.setProperty("ametys:login", logins[i].getString());
userNode.setProperty("ametys:population", populationId);
}
return true;
}
return false;
}
function convertGrantedGroups(node)
{
if (node.hasProperty("ametys-internal:granted-groups"))
{
var ids = node.getProperty("ametys-internal:granted-groups").getValues();
node.getProperty("ametys-internal:granted-groups").remove();
var rootNode = node.addNode("ametys-internal:granted-groups", "ametys:linkGrantedGroups");
for (var i=0; i < ids.length; i++)
{
var gpNode = grantedGroups.addNode("ametys-internal:granted-group", "ametys:group");
gpNode.setProperty("ametys:groupId", logins[i].getString());
gpNode.setProperty("ametys:groupDirectory", groupDirectoryId);
}
return true;
}
return false;
}
// Migrate link directory
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:directoryLink)", javax.jcr.query.Query.XPATH);
var links = query.execute().getNodes();
var count = 0;
while (links.hasNext())
{
var link = links.next();
try
{
if (convertGrantedUsers(link) || convertGrantedGroups(link))
{
link.save();
count++;
}
}
catch (e)
{
print("Exception for link '" + link + "'.\n" + e);
}
}
print(count + " links have been migrated");
var populationId = "ametys_demo_users"; // value of the id of the population your users belong to
var groupDirectoryId= "groupes-sql"; // value of the id of the group directory your groups belong to
function convertGrantedUsers(node)
{
if (node.hasProperty("ametys-internal:granted-users"))
{
var logins = node.getProperty("ametys-internal:granted-users").getValues();
node.getProperty("ametys-internal:granted-users").remove();
var rootNode = node.addNode("ametys-internal:granted-users", "ametys:linkGrantedUsers");
for (var i=0; i < logins.length; i++)
{
var userNode = rootNode.addNode("ametys-internal:granted-user", "ametys:user");
userNode.setProperty("ametys:login", logins[i].getString());
userNode.setProperty("ametys:population", populationId);
}
return true;
}
return false;
}
function convertGrantedGroups(node)
{
if (node.hasProperty("ametys-internal:granted-groups"))
{
var ids = node.getProperty("ametys-internal:granted-groups").getValues();
node.getProperty("ametys-internal:granted-groups").remove();
var rootNode = node.addNode("ametys-internal:granted-groups", "ametys:linkGrantedGroups");
for (var i=0; i < ids.length; i++)
{
var gpNode = grantedGroups.addNode("ametys-internal:granted-group", "ametys:group");
gpNode.setProperty("ametys:groupId", logins[i].getString());
gpNode.setProperty("ametys:groupDirectory", groupDirectoryId);
}
return true;
}
return false;
}
// Migrate link directory
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:directoryLink)", javax.jcr.query.Query.XPATH);
var links = query.execute().getNodes();
var count = 0;
while (links.hasNext())
{
var link = links.next();
try
{
if (convertGrantedUsers(link) || convertGrantedGroups(link))
{
link.save();
count++;
}
}
catch (e)
{
print("Exception for link '" + link + "'.\n" + e);
}
}
print(count + " links have been migrated");
var populationId = "ametys_demo_users"; // value of the id of the population your users belong to
var groupDirectoryId= "groupes-sql"; // value of the id of the group directory your groups belong to
function convertGrantedUsers(node)
{
if (node.hasProperty("ametys-internal:granted-users"))
{
var logins = node.getProperty("ametys-internal:granted-users").getValues();
node.getProperty("ametys-internal:granted-users").remove();
var rootNode = node.addNode("ametys-internal:granted-users", "ametys:linkGrantedUsers");
for (var i=0; i < logins.length; i++)
{
var userNode = rootNode.addNode("ametys-internal:granted-user", "ametys:user");
userNode.setProperty("ametys:login", logins[i].getString());
userNode.setProperty("ametys:population", populationId);
}
return true;
}
return false;
}
function convertGrantedGroups(node)
{
if (node.hasProperty("ametys-internal:granted-groups"))
{
var ids = node.getProperty("ametys-internal:granted-groups").getValues();
node.getProperty("ametys-internal:granted-groups").remove();
var rootNode = node.addNode("ametys-internal:granted-groups", "ametys:linkGrantedGroups");
for (var i=0; i < ids.length; i++)
{
var gpNode = grantedGroups.addNode("ametys-internal:granted-group", "ametys:group");
gpNode.setProperty("ametys:groupId", logins[i].getString());
gpNode.setProperty("ametys:groupDirectory", groupDirectoryId);
}
return true;
}
return false;
}
// Migrate link directory
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:directoryLink)", javax.jcr.query.Query.XPATH);
var links = query.execute().getNodes();
var count = 0;
while (links.hasNext())
{
var link = links.next();
try
{
if (convertGrantedUsers(link) || convertGrantedGroups(link))
{
link.save();
count++;
}
}
catch (e)
{
print("Exception for link '" + link + "'.\n" + e);
}
}
print(count + " links have been migrated");
Exécutez le script suivant pour migrer vos services Annuaire de liens
Script de migration des services
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
var ConsoleHelper = Java.type('org.ametys.workspaces.repository.ConsoleHelper');
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.next();
var paramsNode = node.getNode('ametys:service_parameters');
if (ConsoleHelper.convertSingleToMultipleProperty(paramsNode, "ametys:themes"))
{
paramsNode.save();
count++
}
}
print(count + " link services have been migrated");
var ConsoleHelper = Java.type('org.ametys.workspaces.repository.ConsoleHelper');
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.next();
var paramsNode = node.getNode('ametys:service_parameters');
if (ConsoleHelper.convertSingleToMultipleProperty(paramsNode, "ametys:themes"))
{
paramsNode.save();
count++
}
}
print(count + " link services have been migrated");
var ConsoleHelper = Java.type('org.ametys.workspaces.repository.ConsoleHelper');
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.next();
var paramsNode = node.getNode('ametys:service_parameters');
if (ConsoleHelper.convertSingleToMultipleProperty(paramsNode, "ametys:themes"))
{
paramsNode.save();
count++
}
}
print(count + " link services have been migrated");