in Alfresco

Alfresco export users from one server to the other

Introduction

Exporting users in alfresco can be a problem, there are multiple solutions for this like using alfrescos export tool. We just want to export users and some of the properties from one server to the other and we want it to work on any alfresco version.

Solution

Solution is fairly simple, lets create a script that will generate code that we are going to run on other server and recreate the users. (what?? (: ) Ok lets see the code:

createUsersGenerator.js

var peopleCollection = search.luceneSearch("TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" ");

var output = "";
for (var i = 0; i < peopleCollection.length; i++) {
 var pers = peopleCollection[i];

 output += (" if(people.getPerson('" + pers.properties["cm:userName"] + "')==null){\n");
 output += (" user = people.createPerson('" + pers.properties["cm:userName"] + "',
              '" + pers.properties["cm:firstName"] + "',
              '" + pers.properties["cm:lastName"] + "',
              '" + pers.properties["cm:email"] + "',
              'password' ,true);\n");


 if (pers.properties["cm:organization"] != null)
     output += (" user.properties['cm:organization']='" 
                      + pers.properties["cm:organization"] + "';\n");

 if (pers.properties["cm:jobtitle"] != null)
     output += (" user.properties['cm:jobtitle']='" 
                 + pers.properties["cm:jobtitle"] + "';\n");

 if (pers.properties["cm:location"] != null)
     output += (" user.properties['cm:location']='" 
        + pers.properties["cm:location"] + "';\n");

     output += (" user.save();\n");
     output += ("}\n");
 }


var article = companyhome.createNode("createUsers.js", "cm:content");
article.content = output;
article.save();

What does this do?

It creates a file createUsers.js,  when this file is executed alfresco will create users with properties in this case first and last name, email, organization, jobtitle and location. You can add other if you desire.

Lets see the createUsers.js

 if(people.getPerson('prvoslav')==null){
 user = people.createPerson('prvoslav','Prvoslav', 'Savic','prvoslav.savic@alfrescoblog.com',                              'password' ,true);
 user.properties['cm:organization']='AlfrescoBlog';
 user.properties['cm:jobtitle']='Blogger';
 user.properties['cm:location']='Serbia';
 user.save();
}

Execute createUsers.js script in other alfresco and you will get the same users, with same properties on the other server.

Summary

Here we have shown you how to “copy” users from one server to the other without using the alfresco export tool.

 

Don't be shellfish...Tweet about this on TwitterShare on LinkedInShare on Google+Share on RedditShare on Facebook

Was this helpful ?

  1. Hi,

    Is this script going to do the job if I’m going to try exporting Alfresco 4.x Users and import them into Alfresco 5.2.0d

    Cheers,
    Tony

    • Hi,
      script should be ok. In case it is not minor adjustments should be added.

      You can try the export script out it can not do any harm to your system. When you try import script ( import script is generated after export script finishes) just add throw “Rollback”; in the end.

      Cheers .