ElggBatch : Create upt to 1000 users

Hi everyone,

How can I use ElggBatch to create up to 1000 new user?

Regards,

 

  • ElggBatch is a lazy-loading proxy for a result array from a fetching function.

    Use for() loops, e.g.:

    for ($i = 0; $i < 1000; $i++) {
      // do stuff
    }
  • Do you need the users to be created based on actual data, or is testing data enough?

    If you only need testing data, you can use the CLI command 'elgg-cli database:seed -t user -l 1000' this will generate 1000 testing users with random profile data.

    https://learn.elgg.org/en/stable/intro/elgg-cli.html

  • Thanks a lot, @jeabakker!

    That’s exactly what I was looking for.

    I do have one more question: I developed my own custom seeder for user creation.

    When using the "Seeder Inspect" in developer tools, I see two available seeders for users:

    Seed Handler: Piwal\Piwal\Seeder

    How can I execute my custom seeder for user creation from the command line?

    Regards,

     

  • make sure your handler has it's own seeder type (with the function getType(), see https://github.com/Elgg/Elgg/blob/2137ec9dca0f354f2b1943c508a846d442ff4385/engine/classes/Elgg/Database/Seeds/Users.php#L141-L143). For example 'user2' or 'myusers'.

    you can call the seeder with the cli 'elgg-cli database:seed -t user2 -l <number of users>'.

    if you don't want all your users to be created in the same second you can add the params '--create_since=<date>' and '--create_until=<later date>'.

    if you want your users to have icons you can add '--image_folder=<path to your Elgg installation>\.scripts\seeder\images\'

  • I’ve integrated the Gravatar third-party libraries with PHP Faker, and it's working as expected. Now, I’m trying to generate a fake user avatar using Gravatar, but I’ve encountered an issue.

    Here's how I retrieve the avatar path from the temp directory (/tmp/e3395a721f569696dd6e9509dd20c8bb.jpg), and it works fine:

    $profile_icon_url = $this->faker()->gravatar(sys_get_temp_dir(), 'wavatar');

    After that, I set the user’s avatar using the following method:

    $user->saveIconFromLocalFile($profile_icon_url);

    When trying to see the user profile the avatar is not displayed, and I have the following error in the log file

    ELGG.ERROR: ErrorException: imagewebp(/var/data/elgg-6.x.x/5000/5667/profile/5667medium.webp): Failed to open stream: Permission denied in /home/pessek/WEB/elgg-6.0.0/vendor/imagine/imagine/src/Gd/Image.php:648\nStack trace

    After investigation 

    The directory  /var/data/elgg-6.x.x/5000/5667/profile/ does not contain a file named 5667medium.webp. It only contains a file named 5667master.jpg
     

    So 5667medium.webp has not been generated.

    Could someone help me ?

    Regards,

     

     

  • can it be that the cli uses a different user than the webserver?

    In your seeding (cli) only a master icon is created. Then on the website when you view a user the thumbnails are created which are needed. If the webserver can write the thumbnail (like it says in the error log) you won't see a thumbnail.

    So check the permissions on the dataroot folder.

  • I found the issue. I was not running the cli as apache user.

    Thanks a lot

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking