Bulk J! Users creation from existing list

tritongr

New Member
Hi

I have a fabrik list with ~1000 records and among the fields ther are name, username, password already filled with data.
What is the best way to create the equivalent joomla users for all records?

One thought is to 1) export the list to csv, 2) delete all records from the list and 3) import records back using the listcsv pluging using create_client_user.php.

I wonder if there is a better/simpler solution?

Thanks
 
The only solution I can think of is to re-import as a CSV, using the create_client_user.php.

Although I'd break it up into smaller chunks of maybe 100 at a time.

-- hugh
 
Thank you Hugh

I will go the reimport way as you propose and initially I had thought.

However I wonder, academically, if it is possible to run a php script (I will try to write it) which will loop over the existing records of the list and create a new J! user for each record. But I don't know where to put and how to launch such a script. The relevant J! user creation code, I think, will be similar to create_client_user.php.

Thanks again
 
Thanks troester

Really useful extension although I have succeded basic import of csv J! users with fabrik listcsv plugin.
Yes I know I need an additional JuserID field in my list to store the J! userid for each created J! user.

Thanks
 
Just in case someone will find it useful, I managed to create 1021 joomla users from all 1021 records of an existing list (the run took ~2 mins).
First I created a custom button with PHP list plugin with settings: Button in row: No and Required checked : No and the code below.
Fabrik list needs to have been populated with the basic J! user info in its fields like Name, Username, Email, Password. Plus an empty user_id field to host each new J!user's id as the creation progress goes on.
Here is the php code executed on button click:
PHP:
//db object
$app = JFactory::getApplication();
$db = JFactory::getDbo();

//Prepare SQL variable
$sel = $db->getQuery(true);
$sel->select('*');
$sel->from('twMelhpwd'); //list table

// sets up a database query for later execution
$db->setQuery($sel);

// fetch result as an object list
$rows = $db->loadObjectList();

$i = 1; //counter

//Loop over the fetched records
foreach ($rows as $row) {
    //Create J! USER
        $userData = array(
        "name"=>$row->Name,
        "username"=>$row->Username,
        "password"=>$row->Password,
        "password2"=>$row->Password,
        "email"=>$row->Email,
        "block"=>0,
        "sendEmail"=>0,
        "groups"=>array("2") //Registered group
        );

        $user = new JUser;
        //Write to database
        if(!$user->bind($userData)) {
            throw new Exception("Could not bind data. Error: " . $user->getError());
        }
        if (!$user->save()) {
            throw new Exception("Could not save user. Error: " . $user->getError());
        }
  
    //Update current list's userid field with the newly created J!user's id
        $upd = $db->getQuery(true);
        // Fields to update.
        $fields = array(
        $db->quoteName('user_id') . ' = ' . $user->id
        );

        // Conditions for which records should be updated.
        $conditions = array(
            $db->quoteName('MelosID') . ' = ' . $row->MelosID  //this is the PK of the list
        );
  
        //execute query
        $upd->update($db->quoteName('twMelhpwd'))
            ->set($fields)
            ->where($conditions);
        $db->setQuery($upd);
        $result = $db->execute();

        $i++; //increase counter
}//end for

$statusMsg = $i; // display final counter's valye

return true;
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top