parent
7373961cd8
commit
b362d92fe2
@ -1,38 +1,61 @@ |
|||||||
<?php //$id$
|
<?php |
||||||
/** |
/** |
||||||
* This script contains a data filling procedure for users |
* This script contains a data filling procedure for users |
||||||
* @author Yannick Warnier <yannick.warnier@beeznest.com> |
* @author Yannick Warnier <yannick.warnier@beeznest.com> |
||||||
* |
* |
||||||
*/ |
*/ |
||||||
/** |
|
||||||
* Initialisation section |
|
||||||
*/ |
|
||||||
require '../../main/inc/global.inc.php'; |
require '../../main/inc/global.inc.php'; |
||||||
|
|
||||||
/** |
/** |
||||||
* Executing |
* Executing |
||||||
*/ |
*/ |
||||||
fill_many_users(100000); |
//fill_many_users(100000); |
||||||
|
|
||||||
/** |
/** |
||||||
* Loads the data and injects it into the Chamilo database, using the Chamilo |
* Loads the data and injects it into the Chamilo database, using the Chamilo |
||||||
* internal functions. |
* internal functions. |
||||||
* @return array List of user IDs for the users that have just been inserted |
* @return array List of user IDs for the users that have just been inserted |
||||||
*/ |
*/ |
||||||
function fill_many_users($num) { |
function fill_many_users($num) |
||||||
$eol = PHP_EOL; |
{ |
||||||
$users = array(); //declare only to avoid parsing notice |
$users = array(); //declare only to avoid parsing notice |
||||||
require_once 'data_users.php'; //fill the $users array |
require_once 'data_users.php'; //fill the $users array |
||||||
$i = 1; |
$i = 1; |
||||||
|
$output = []; |
||||||
|
|
||||||
|
$batchSize = 20; |
||||||
|
$em = Database::getManager(); |
||||||
|
|
||||||
while ($i < $num) { |
while ($i < $num) { |
||||||
$output = array(); |
$output[] = array('title' => 'Users Filling Report:'); |
||||||
$output[] = array('title'=>'Users Filling Report:'); |
|
||||||
foreach ($users as $j => $user) { |
foreach ($users as $j => $user) { |
||||||
//first check that the first item doesn't exist already |
//first check that the first item doesn't exist already |
||||||
$output[$i]['line-init'] = $user['firstname']; |
$output[$i]['line-init'] = $user['firstname']; |
||||||
$res = UserManager::create_user($user['firstname'],$user['lastname'],$user['status'],$user['email'],$user['username'].$i,$user['pass'],null,null,null,null,$user['auth_source'],null,$user['active']); |
$res = UserManager::create_user( |
||||||
|
$user['firstname'], |
||||||
|
$user['lastname'], |
||||||
|
$user['status'], |
||||||
|
$i.'_'.$user['email'], |
||||||
|
$i.'_'.$user['username'], |
||||||
|
$user['pass'], |
||||||
|
null, |
||||||
|
null, |
||||||
|
null, |
||||||
|
null, |
||||||
|
$user['auth_source'], |
||||||
|
null, |
||||||
|
$user['active'] |
||||||
|
); |
||||||
$output[$i]['line-info'] = ($res ? get_lang('Inserted') : get_lang('NotInserted')).' '.$user['username'].$i; |
$output[$i]['line-info'] = ($res ? get_lang('Inserted') : get_lang('NotInserted')).' '.$user['username'].$i; |
||||||
$i++; |
$i++; |
||||||
|
|
||||||
|
if (($i % $batchSize) === 0) { |
||||||
|
$em->flush(); |
||||||
|
$em->clear(); // Detaches all objects from Doctrine! |
||||||
|
} |
||||||
} |
} |
||||||
print_r($output); |
|
||||||
} |
} |
||||||
//return $output; |
|
||||||
|
return $output; |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue