A bug linked to editing documents directly from project spaces via Microsoft Office causes data loss when rebuilding live.
The bug has been fixed, but a migration is required to save data that may be more recent in live than in default :
var xpathQuery = "//ametys:plugins/workspaces//element(*, ametys:resource)";
var credentials = new javax.jcr.SimpleCredentials('ametys', []);
var liveSession = repository.login(credentials, 'live');
var qmLive = liveSession.getWorkspace().getQueryManager();
var qmDefault = session.getWorkspace().getQueryManager();
var queryLive = qmLive.createQuery(xpathQuery, javax.jcr.query.Query.XPATH);
var nodes = queryLive.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var node = nodes.nextNode();
if (node.hasNode("jcr:content"))
{
var contentNodeLive = node.getNode("jcr:content");
var id = contentNodeLive.getIdentifier();
try
{
var contentNodeDefault = session.getNodeByIdentifier(id);
if (contentNodeLive.getProperty("jcr:lastModified").getDate().compareTo(contentNodeDefault.getProperty("jcr:lastModified").getDate()) > 0)
{
if (contentNodeLive.isLocked() || contentNodeDefault.isLocked())
{
print("Content locked : " + id);
}
else
{
count++;
var binary = contentNodeLive.getProperty("jcr:data");
contentNodeDefault.setProperty("jcr:data", binary.getValue());
contentNodeDefault.setProperty("jcr:lastModified", contentNodeLive.getProperty("jcr:lastModified").getValue());
session.save();
}
}
}
catch (e)
{
print("Erreur while migrating content : " + id);
}
}
}
print("Number of contents migrated : " + count)
var xpathQuery = "//ametys:plugins/workspaces//element(*, ametys:resource)";
var credentials = new javax.jcr.SimpleCredentials('ametys', []);
var liveSession = repository.login(credentials, 'live');
var qmLive = liveSession.getWorkspace().getQueryManager();
var qmDefault = session.getWorkspace().getQueryManager();
var queryLive = qmLive.createQuery(xpathQuery, javax.jcr.query.Query.XPATH);
var nodes = queryLive.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var node = nodes.nextNode();
if (node.hasNode("jcr:content"))
{
var contentNodeLive = node.getNode("jcr:content");
var id = contentNodeLive.getIdentifier();
try
{
var contentNodeDefault = session.getNodeByIdentifier(id);
if (contentNodeLive.getProperty("jcr:lastModified").getDate().compareTo(contentNodeDefault.getProperty("jcr:lastModified").getDate()) > 0)
{
if (contentNodeLive.isLocked() || contentNodeDefault.isLocked())
{
print("Content locked : " + id);
}
else
{
count++;
var binary = contentNodeLive.getProperty("jcr:data");
contentNodeDefault.setProperty("jcr:data", binary.getValue());
contentNodeDefault.setProperty("jcr:lastModified", contentNodeLive.getProperty("jcr:lastModified").getValue());
session.save();
}
}
}
catch (e)
{
print("Erreur while migrating content : " + id);
}
}
}
print("Number of contents migrated : " + count)
var xpathQuery = "//ametys:plugins/workspaces//element(*, ametys:resource)";
var credentials = new javax.jcr.SimpleCredentials('ametys', []);
var liveSession = repository.login(credentials, 'live');
var qmLive = liveSession.getWorkspace().getQueryManager();
var qmDefault = session.getWorkspace().getQueryManager();
var queryLive = qmLive.createQuery(xpathQuery, javax.jcr.query.Query.XPATH);
var nodes = queryLive.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var node = nodes.nextNode();
if (node.hasNode("jcr:content"))
{
var contentNodeLive = node.getNode("jcr:content");
var id = contentNodeLive.getIdentifier();
try
{
var contentNodeDefault = session.getNodeByIdentifier(id);
if (contentNodeLive.getProperty("jcr:lastModified").getDate().compareTo(contentNodeDefault.getProperty("jcr:lastModified").getDate()) > 0)
{
if (contentNodeLive.isLocked() || contentNodeDefault.isLocked())
{
print("Content locked : " + id);
}
else
{
count++;
var binary = contentNodeLive.getProperty("jcr:data");
contentNodeDefault.setProperty("jcr:data", binary.getValue());
contentNodeDefault.setProperty("jcr:lastModified", contentNodeLive.getProperty("jcr:lastModified").getValue());
session.save();
}
}
}
catch (e)
{
print("Erreur while migrating content : " + id);
}
}
}
print("Number of contents migrated : " + count)