Dernière publication:23/02/2018à 15:00DavidCartier-Michaud
Dans vos fichiers modèles associés à chaque gabarit de newsletter qui se trouvent dans skins/<nom de la skin>/newsletter/<nom du gabarit NL>/models/model.xml , procéder aux modifications suivantes :
Remplacer ametys_src par data-ametys-src
Remplacer ametys_type par data-ametys-type
Exécutez le script suivant pour migrer vos contenus newsletter :
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
importClass(java.io.ByteArrayInputStream);
importClass(org.apache.commons.io.IOUtils);
session.refresh(true);
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:content)[@ametys-internal:contentType='org.ametys.plugins.newsletter.Content.newsletter']", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var i = 0;
while (nodes.hasNext())
{
var node = nodes.nextNode();
if (node.hasNode("ametys:content"))
{
var bis = null;
var stream = null;
try
{
var contentNode = node.getNode("ametys:content");
stream = contentNode.getProperty("jcr:data").getBinary().getStream();
var contentString = IOUtils.toString(stream, "UTF-8");
contentString = contentString.replaceAll("ametys_", "data-ametys-");
bis = new ByteArrayInputStream(contentString.getBytes("UTF-8"));
var binary = contentNode.getSession().getValueFactory().createBinary(bis);
contentNode.setProperty("jcr:data", binary);
contentNode.save();
if (contentNode.hasProperty("ametys-internal:currentStepId") && contentNode.getProperty("ametys-internal:currentStepId").getLong() == 3)
{
contentNode.checkin();
contentNode.checkout();
var versionName = contentNode.getBaseVersion().getName();
contentNode.getVersionHistory().addVersionLabel(versionName, "Live", true);
}
println(node.getIdentifier());
i++;
}
finally
{
if (bis != null)
{
bis.close();
}
if (stream != null)
{
stream.close();
}
}
}
}
session.save();
println(i + " contenus corrigés.");
importClass(java.io.ByteArrayInputStream);
importClass(org.apache.commons.io.IOUtils);
session.refresh(true);
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:content)[@ametys-internal:contentType='org.ametys.plugins.newsletter.Content.newsletter']", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var i = 0;
while (nodes.hasNext())
{
var node = nodes.nextNode();
if (node.hasNode("ametys:content"))
{
var bis = null;
var stream = null;
try
{
var contentNode = node.getNode("ametys:content");
stream = contentNode.getProperty("jcr:data").getBinary().getStream();
var contentString = IOUtils.toString(stream, "UTF-8");
contentString = contentString.replaceAll("ametys_", "data-ametys-");
bis = new ByteArrayInputStream(contentString.getBytes("UTF-8"));
var binary = contentNode.getSession().getValueFactory().createBinary(bis);
contentNode.setProperty("jcr:data", binary);
contentNode.save();
if (contentNode.hasProperty("ametys-internal:currentStepId") && contentNode.getProperty("ametys-internal:currentStepId").getLong() == 3)
{
contentNode.checkin();
contentNode.checkout();
var versionName = contentNode.getBaseVersion().getName();
contentNode.getVersionHistory().addVersionLabel(versionName, "Live", true);
}
println(node.getIdentifier());
i++;
}
finally
{
if (bis != null)
{
bis.close();
}
if (stream != null)
{
stream.close();
}
}
}
}
session.save();
println(i + " contenus corrigés.");
importClass(java.io.ByteArrayInputStream);
importClass(org.apache.commons.io.IOUtils);
session.refresh(true);
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:content)[@ametys-internal:contentType='org.ametys.plugins.newsletter.Content.newsletter']", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var i = 0;
while (nodes.hasNext())
{
var node = nodes.nextNode();
if (node.hasNode("ametys:content"))
{
var bis = null;
var stream = null;
try
{
var contentNode = node.getNode("ametys:content");
stream = contentNode.getProperty("jcr:data").getBinary().getStream();
var contentString = IOUtils.toString(stream, "UTF-8");
contentString = contentString.replaceAll("ametys_", "data-ametys-");
bis = new ByteArrayInputStream(contentString.getBytes("UTF-8"));
var binary = contentNode.getSession().getValueFactory().createBinary(bis);
contentNode.setProperty("jcr:data", binary);
contentNode.save();
if (contentNode.hasProperty("ametys-internal:currentStepId") && contentNode.getProperty("ametys-internal:currentStepId").getLong() == 3)
{
contentNode.checkin();
contentNode.checkout();
var versionName = contentNode.getBaseVersion().getName();
contentNode.getVersionHistory().addVersionLabel(versionName, "Live", true);
}
println(node.getIdentifier());
i++;
}
finally
{
if (bis != null)
{
bis.close();
}
if (stream != null)
{
stream.close();
}
}
}
}
session.save();
println(i + " contenus corrigés.");