Advertisement
jlb

generate elgg users

jlb
Nov 4th, 2011
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php
  2.  
  3. // path to Elgg engine's start.php
  4. // (usually in html/engine/start.php or public_html/engine/start.php)
  5. $engineStartPath = '../html/engine/start.php';
  6. require_once($engineStartPath);
  7.  
  8. // the first number to append to the username (will increment peruser)
  9. // ie. user2
  10. $startUserNumber = 2;
  11.  
  12. // the total number of users to create
  13. $totalUsers = 10;
  14.  
  15. // exit after this many failed attempts (ie. attempting to register a user with an existing username)
  16. $failAttempts = 10;
  17.  
  18. while (TRUE)
  19. {
  20.     try
  21.     {
  22.         // generate basic user details
  23.         $username   = 'username' . $startUserNumber;
  24.         $password   = $username;
  25.         $name       = ucfirst($username) . ' Smith';
  26.         $email      = $username . '@example.com';
  27.        
  28.         // increment user number
  29.         $startUserNumber++;
  30.        
  31.         // register, enable and validate this user
  32.         $guid       = register_user($username, $password, $name, $email);
  33.         $user       = get_entity($guid);
  34.         $user->enable();
  35.         elgg_set_user_validation_status($user->getGUID(), true, 'script');
  36.        
  37.         echo "\nAdded username: " . $username . " - name: " . $name . " - e-mail: " . $email . " - password: " . $password;
  38.        
  39.         if (--$totalUsers == 0)
  40.         {
  41.             break;
  42.         }
  43.        
  44.     }
  45.     catch (Exception $e)
  46.     {
  47.         echo "\nERR:\t" . $username . " " . $e->getMessage();
  48.        
  49.         if (--$failAttempts == 0)
  50.         {
  51.             echo 'Too many failed attempts';
  52.             exit(1);
  53.         }
  54.     }
  55. }
  56. ?>
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement