diff --git a/tests/datafiller/data_courses.php b/tests/datafiller/data_courses.php index 590cc742b6..b0fb3b60ba 100755 --- a/tests/datafiller/data_courses.php +++ b/tests/datafiller/data_courses.php @@ -130,6 +130,6 @@ $courses[] = array( 'course_language' => 'english', 'user_id' => 1, 'expiration_date' => '2020-09-01 00:00:00', - 'exemplary_content' => true, + 'exemplary_content' => true ); diff --git a/tests/datafiller/data_users.php b/tests/datafiller/data_users.php index e754ed2626..e62a0208ac 100755 --- a/tests/datafiller/data_users.php +++ b/tests/datafiller/data_users.php @@ -1,4 +1,4 @@ - * */ -/** - * Initialisation section - */ + $users = array(); $users[] = array( 'username' => 'ywarnier', diff --git a/tests/datafiller/fill_all.php b/tests/datafiller/fill_all.php index 484a003574..0bbc2bd62f 100755 --- a/tests/datafiller/fill_all.php +++ b/tests/datafiller/fill_all.php @@ -1,4 +1,4 @@ - */ - -/** - * Initialisation section - */ -$incdir = dirname(__FILE__).'/../../main/inc/'; + +$incdir = dirname(__FILE__).'/../../main/inc/'; require $incdir.'global.inc.php'; /** @@ -24,23 +21,25 @@ $eol = PHP_EOL; $output = ''; $files = scandir(dirname(__FILE__)); foreach ($files as $file) { - if (substr($file,0,1) == '.' or substr($file,0,5) != 'fill_') { ; } //skip - else { - if ($file == basename(__FILE__)) { - //skip, this is the current file - } else { + if (substr($file, 0, 1) == '.' or substr($file, 0, 5) != 'fill_') { + ; + } else { + if ($file == basename(__FILE__)) { + //skip, this is the current file + } else { $output .= $eol.'Reading file: '.$file.$eol; - require_once $file; - $function = basename($file,'.php'); + require_once $file; + $function = basename($file, '.php'); if (function_exists($function)) { - $output .= $eol.'Executing function '.$function.$eol; + $output .= $eol.'Executing function '.$function.$eol; $function(); } else { //function not found } - } + } } } + /** * Display */ diff --git a/tests/datafiller/fill_many_users.php b/tests/datafiller/fill_many_users.php index ba00185304..d4a745eba6 100755 --- a/tests/datafiller/fill_many_users.php +++ b/tests/datafiller/fill_many_users.php @@ -1,38 +1,61 @@ - * */ -/** - * Initialisation section - */ + require '../../main/inc/global.inc.php'; + /** * Executing */ -fill_many_users(100000); +//fill_many_users(100000); + /** * Loads the data and injects it into the Chamilo database, using the Chamilo * internal functions. * @return array List of user IDs for the users that have just been inserted */ -function fill_many_users($num) { - $eol = PHP_EOL; +function fill_many_users($num) +{ $users = array(); //declare only to avoid parsing notice require_once 'data_users.php'; //fill the $users array $i = 1; + $output = []; + + $batchSize = 20; + $em = Database::getManager(); + while ($i < $num) { - $output = array(); - $output[] = array('title'=>'Users Filling Report:'); - foreach ($users as $j => $user) { - //first check that the first item doesn't exist already - $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']); - $output[$i]['line-info'] = ($res ? get_lang('Inserted') : get_lang('NotInserted')).' '.$user['username'].$i; - $i++; - } - print_r($output); + $output[] = array('title' => 'Users Filling Report:'); + foreach ($users as $j => $user) { + //first check that the first item doesn't exist already + $output[$i]['line-init'] = $user['firstname']; + $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; + $i++; + + if (($i % $batchSize) === 0) { + $em->flush(); + $em->clear(); // Detaches all objects from Doctrine! + } + } } - //return $output; + + return $output; } diff --git a/tests/datafiller/fill_users.php b/tests/datafiller/fill_users.php index 0b32fa97e1..1f086d0cd1 100755 --- a/tests/datafiller/fill_users.php +++ b/tests/datafiller/fill_users.php @@ -1,12 +1,10 @@ - * */ -/** - * Initialisation section - */ /** * Loads the data and injects it into the Chamilo database, using the Chamilo