fill_many_users.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * This script contains a data filling procedure for users
  4. * @author Yannick Warnier <yannick.warnier@beeznest.com>
  5. *
  6. */
  7. require '../../main/inc/global.inc.php';
  8. /**
  9. * Executing
  10. */
  11. //fill_many_users(100000);
  12. /**
  13. * Loads the data and injects it into the Chamilo database, using the Chamilo
  14. * internal functions.
  15. * @return array List of user IDs for the users that have just been inserted
  16. */
  17. function fill_many_users($num)
  18. {
  19. $users = array(); //declare only to avoid parsing notice
  20. require_once 'data_users.php'; //fill the $users array
  21. $i = 1;
  22. $output = [];
  23. $batchSize = 20;
  24. $em = Database::getManager();
  25. while ($i < $num) {
  26. $output[] = array('title' => 'Users Filling Report:');
  27. foreach ($users as $j => $user) {
  28. //first check that the first item doesn't exist already
  29. $output[$i]['line-init'] = $user['firstname'];
  30. $res = UserManager::create_user(
  31. $user['firstname'],
  32. $user['lastname'],
  33. $user['status'],
  34. $i.'_'.$user['email'],
  35. $i.'_'.$user['username'],
  36. $user['pass'],
  37. null,
  38. null,
  39. null,
  40. null,
  41. $user['auth_source'],
  42. null,
  43. $user['active']
  44. );
  45. $output[$i]['line-info'] = ($res ? get_lang('Inserted') : get_lang('NotInserted')).' '.$user['username'].$i;
  46. $i++;
  47. if (($i % $batchSize) === 0) {
  48. $em->flush();
  49. $em->clear(); // Detaches all objects from Doctrine!
  50. }
  51. }
  52. }
  53. return $output;
  54. }