Before starting the migration, please make sure that you have done the following migration: plugin-contentIO
User synchronization action :
We've added a new parameter for entity synchronization (Source SQL entities).
This parameter is: 'User synchronization action'. The default setting is 800. In most cases, leave 800.
For each synchronization of content of type "Source SQL of entities", click on "Modify" and then on "Save and close" to take this new parameter into account.
We recommend that you run all your user content through this lifecycle. View documentation
Next, define the associated i18n key and give it a name in WEB-INF/i18n/applications.xml :
Oops!
Copy to clipboard failed. Open the code and copy it manually.
<message key="WORKFLOW_user">Cycle de vie des utilisateurs</message>
<message key="WORKFLOW_user">Cycle de vie des utilisateurs</message>
<message key="WORKFLOW_user">Cycle de vie des utilisateurs</message>
Then go to script to migrate:
Warning: if you have already defined a different lifecycle for users (other than the 'contentio' lifecycle), you must adapt this script and change the worfklow name (defaultWorkflowName variable).
Oops!
Copy to clipboard failed. Open the code and copy it manually.
var defaultWorkflowName = "contentio";
var contentTypeEP = serviceManager.lookup('org.ametys.cms.contenttype.ContentTypeExtensionPoint');
var request = "@ametys-internal:contentType='org.ametys.plugins.userdirectory.Content.user'";
contentTypeEP.getSubTypes('org.ametys.plugins.userdirectory.Content.user').forEach(function(contentTypeId) {
request += " or @ametys-internal:contentType='" + contentTypeId + "'"
});
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:content)[" + request + "]", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var nbUserChanged = 0;
while (nodes.hasNext())
{
var content = nodes.next();
if (content.hasNode("ametys-internal:workflows"))
{
var workflows = content.getNode("ametys-internal:workflows");
var workflowNodes = workflows.getNodes();
var hasChanged = false;
while (workflowNodes.hasNext())
{
var workflowNode = workflowNodes.next();
var workflowName = workflowNode.getProperty("oswf:workflowName").getString();
if (workflowName == defaultWorkflowName)
{
workflowNode.setProperty("oswf:workflowName", "user");
hasChanged = true;
}
}
if (hasChanged)
{
content.save();
nbUserChanged++;
}
}
}
print(nbUserChanged + " contenu(s) 'utilisateur' changé(s)");
var defaultWorkflowName = "contentio";
var contentTypeEP = serviceManager.lookup('org.ametys.cms.contenttype.ContentTypeExtensionPoint');
var request = "@ametys-internal:contentType='org.ametys.plugins.userdirectory.Content.user'";
contentTypeEP.getSubTypes('org.ametys.plugins.userdirectory.Content.user').forEach(function(contentTypeId) {
request += " or @ametys-internal:contentType='" + contentTypeId + "'"
});
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:content)[" + request + "]", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var nbUserChanged = 0;
while (nodes.hasNext())
{
var content = nodes.next();
if (content.hasNode("ametys-internal:workflows"))
{
var workflows = content.getNode("ametys-internal:workflows");
var workflowNodes = workflows.getNodes();
var hasChanged = false;
while (workflowNodes.hasNext())
{
var workflowNode = workflowNodes.next();
var workflowName = workflowNode.getProperty("oswf:workflowName").getString();
if (workflowName == defaultWorkflowName)
{
workflowNode.setProperty("oswf:workflowName", "user");
hasChanged = true;
}
}
if (hasChanged)
{
content.save();
nbUserChanged++;
}
}
}
print(nbUserChanged + " contenu(s) 'utilisateur' changé(s)");
var defaultWorkflowName = "contentio";
var contentTypeEP = serviceManager.lookup('org.ametys.cms.contenttype.ContentTypeExtensionPoint');
var request = "@ametys-internal:contentType='org.ametys.plugins.userdirectory.Content.user'";
contentTypeEP.getSubTypes('org.ametys.plugins.userdirectory.Content.user').forEach(function(contentTypeId) {
request += " or @ametys-internal:contentType='" + contentTypeId + "'"
});
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:content)[" + request + "]", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var nbUserChanged = 0;
while (nodes.hasNext())
{
var content = nodes.next();
if (content.hasNode("ametys-internal:workflows"))
{
var workflows = content.getNode("ametys-internal:workflows");
var workflowNodes = workflows.getNodes();
var hasChanged = false;
while (workflowNodes.hasNext())
{
var workflowNode = workflowNodes.next();
var workflowName = workflowNode.getProperty("oswf:workflowName").getString();
if (workflowName == defaultWorkflowName)
{
workflowNode.setProperty("oswf:workflowName", "user");
hasChanged = true;
}
}
if (hasChanged)
{
content.save();
nbUserChanged++;
}
}
}
print(nbUserChanged + " contenu(s) 'utilisateur' changé(s)");
All that's left is to modify the synchronization of your users' content by defining the right associated life cycle:
Lifecycle for entities :
You can delete action 22 from your workflow file (WEB-INF/param/workflows/udorgunit.xml).
New fields for 'user' content:
We now have a bi-directional link between entities and users. To achieve this, we have added an "orgunits" data item to the content type org.ametys.plugins.userdirectory.Content.user.xml :
Oops!
Copy to clipboard failed. Open the code and copy it manually.