Best way to import bulk users into SocialEngine

Best way to import bulk users into SocialEngine

As an online community owner, there is always possibility to have multiple website with the existing users and the problem arise when an owner wants to migrate those users to the socialengine.

One way is to have a data entry person to add the user data manually in the online community . It is very time consuming and error prone way. Other way is to import users with custom module which can import data from CSV and push it to Social Engine. One of our client  have approximately 90 thousand users in other system and wanted to import those users in the socialengine. So we worked on this solution and sharing some of the basic concept. In this article, we are going to describe the solution to resolve the problem.

Quick Steps to migrate users into SocialEngine

Step 1 : This is the form  where admin can select the CSV to import users.

user-imorter

class Userimporter_Form_Admin_Import extends Engine_Form

{

public function init()

{

........

//upload File

$this->addElement('file', 'csv_file', array(

'label' => 'Upload csv file',

'required' => true,

'destination' => APPLICATION_PATH.'/public/temporary/',

'multiFile' => 1,

'validators' => array(

array('Extension', false, 'csv'),

),
));

........

}

}

Step 2 : inside the IndexAction start your implementation . This part can the CSV data and forward to next process to read and Upload data in to SE.

$userfieldoptiontable = Engine_Api::_ ()->fields ()->getTable ( 'user', 'options' );

$options = $userfieldoptiontable->select();

$optiondata = $userfieldoptiontable->fetchAll($options);

$profileOptions = array();

foreach( $optiondata as $item ) {

$profileOptions[$item->option_id] = $item->label;

}..........

.......................................................

.......................................................

// Uploading a new csv file''

if ($form->csv_file->getValue() !== null)

{

$verified = $values['verify'];

...........

$usercsv = $form->csv_file;

$csvPath = Engine_Api::_()->userimporter()->getCsv($usercsv);

..........................................................

$csv_data = Engine_Api::_()->userimporter()->readCsv($filepath);

$status = Engine_Api::_()->userimporter()->uploadCsv($csv_data,$level_id,$verified,$approved);

}.........

.................

}}

Step 3 : Now it is time for the business logic here we will describe you getCsv , readCsv and finallyUpload csv.

Step 3.1 : we are calling a method which actually get the data from CSV file.

public function getCsv($usercsv) {

if ($usercsv instanceof Zend_Form_Element_File) {

$file = $usercsv->getFileName ();

$fileName = $file;

...................

...................

}

Step 3.2 : Reading the csv file to get data into array finally this function will return an array of the each user.

public function readCsv($filepath) {

ini_set('auto_detect_line_endings',TRUE);

..........

..........

while (($line = fgetcsv($file_handle)) !== FALSE ) {

.....

}

.........

.........

}

Step 3.3 : Get the array returned by the readCsv function and start inserting values into database.

public function uploadCsv(array $csv_data = array(),$level_id,$verified,$approved) {..........

.............

foreach ( $csv_data as $row ) {

$i = 0;

$name_email_Arr = array ();

........

}

........

}

This blog is going to help you in reducing the manual work with User’s Import from existing websites. To save your time and enegry, we already have User’s importer which can import users from many platform using CSV format. This socialengine plugin can help you importing users from other websites based on  WordPress , Oxwall , Magento , PhpFox  etc. Feel free to contact us if you have any further queries.

Best way to import bulk users into SocialEngine was last modified: April 11th, 2016 by Ajay Kumar