Plugin Server directoryMigration manual v1.0.0 to v1.1.0
Last published:23/02/2018à 14:54LaurencePerier
For reasons of conformity with other Ametys services, the property bearing the service title has been renamed "header" instead of "title".
Run the following script in the repository interface console to migrate your existing services:
Oops!
Copy to clipboard failed. Open the code and copy it manually.
importPackage(javax.jcr);
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:service = 'org.ametys.plugins.server.directory']", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var zoneItem = nodes.next();
var paramsNode = zoneItem.getNode('ametys:service_parameters');
if (paramsNode.hasProperty('ametys:title'))
{
var v = paramsNode.getProperty('ametys:title').getString();
paramsNode.setProperty("ametys:header", v);
paramsNode.getProperty('ametys:title').remove();
zoneItem.save();
count++;
}
}
println (count + " services have been migrated");
var credentials = new SimpleCredentials('ametys', []);
var liveSession = repository.login(credentials, 'live');
qm = liveSession.getWorkspace().getQueryManager();
migrated = 0;
query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:service = 'org.ametys.plugins.server.directory']", javax.jcr.query.Query.XPATH);
nodes = query.execute().getNodes();
count = 0;
while (nodes.hasNext())
{
var zoneItem = nodes.next();
var paramsNode = zoneItem.getNode('ametys:service_parameters');
if (paramsNode.hasProperty('ametys:title'))
{
var v = paramsNode.getProperty('ametys:title').getString();
paramsNode.setProperty("ametys:header", v);
paramsNode.getProperty('ametys:title').remove();
zoneItem.save();
count++;
}
}
println (count + " services have been migrated in LIVE");
importPackage(javax.jcr);
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:service = 'org.ametys.plugins.server.directory']", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var zoneItem = nodes.next();
var paramsNode = zoneItem.getNode('ametys:service_parameters');
if (paramsNode.hasProperty('ametys:title'))
{
var v = paramsNode.getProperty('ametys:title').getString();
paramsNode.setProperty("ametys:header", v);
paramsNode.getProperty('ametys:title').remove();
zoneItem.save();
count++;
}
}
println (count + " services have been migrated");
var credentials = new SimpleCredentials('ametys', []);
var liveSession = repository.login(credentials, 'live');
qm = liveSession.getWorkspace().getQueryManager();
migrated = 0;
query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:service = 'org.ametys.plugins.server.directory']", javax.jcr.query.Query.XPATH);
nodes = query.execute().getNodes();
count = 0;
while (nodes.hasNext())
{
var zoneItem = nodes.next();
var paramsNode = zoneItem.getNode('ametys:service_parameters');
if (paramsNode.hasProperty('ametys:title'))
{
var v = paramsNode.getProperty('ametys:title').getString();
paramsNode.setProperty("ametys:header", v);
paramsNode.getProperty('ametys:title').remove();
zoneItem.save();
count++;
}
}
println (count + " services have been migrated in LIVE");
importPackage(javax.jcr);
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:service = 'org.ametys.plugins.server.directory']", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var zoneItem = nodes.next();
var paramsNode = zoneItem.getNode('ametys:service_parameters');
if (paramsNode.hasProperty('ametys:title'))
{
var v = paramsNode.getProperty('ametys:title').getString();
paramsNode.setProperty("ametys:header", v);
paramsNode.getProperty('ametys:title').remove();
zoneItem.save();
count++;
}
}
println (count + " services have been migrated");
var credentials = new SimpleCredentials('ametys', []);
var liveSession = repository.login(credentials, 'live');
qm = liveSession.getWorkspace().getQueryManager();
migrated = 0;
query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:service = 'org.ametys.plugins.server.directory']", javax.jcr.query.Query.XPATH);
nodes = query.execute().getNodes();
count = 0;
while (nodes.hasNext())
{
var zoneItem = nodes.next();
var paramsNode = zoneItem.getNode('ametys:service_parameters');
if (paramsNode.hasProperty('ametys:title'))
{
var v = paramsNode.getProperty('ametys:title').getString();
paramsNode.setProperty("ametys:header", v);
paramsNode.getProperty('ametys:title').remove();
zoneItem.save();
count++;
}
}
println (count + " services have been migrated in LIVE");