Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-65451

User upload via CLI

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      If you want, create your own CSV file and follow documentation to https://docs.moodle.org/39/en/Upload_users

      Test 1. Basic scenarios

      1. In the command line from the moodle directory run

        php admin/tool/uploaduser/cli/uploaduser.php --help
        

      2. Observe the generated help and make sure it makes sense (i.e. information about the script, its supported parameters and how to use it should be printed)
      3. Try to run CLI script without arguments

        php admin/tool/uploaduser/cli/uploaduser.php
        

      4. Check the "Argument --file is required" message is displayed
      5. Try to run CLI script specifying non-existing file. The script should fail and exit code should be 1

        php admin/tool/uploaduser/cli/uploaduser.php --file=PATHTONONEXISTINGFILE
        

      6. Check the "File xxxxxxx does not exist or is not readable" message is displayed
      7. Take attached examplecohorts.csv file, copy it to the Moodle root directory and run:

        php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv
        

      8. Make sure users are created and added to the cohorts. There will be errors about non existing course
      9. Create the course with shortname "math102"
      10. Run the same script again - it should say that users already exist. Make sure users are not enrolled in the course.
      11. Run the same script with the same file but with additional argument

        php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv --uutype=2
        

      12. Make sure users are now enrolled into the course and groups are created and the users are added to the groups groupA and groupB (as in the file)
      13. Run the command (this will use semicolon as delimiter):

        php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv --delimiter_name=semicolon
        

      14. Check the errors "Not enough columns" is displayed
      15. Replace all commas in the file with semicolons and run the same command again.
      16. Check script completes correctly (in this case there will be no changes because users already exist)

      Test 2 . Error testing

      1. Download a fresh examplecohorts.csv.
      2. Edit it and remove the "cohort1" text in the first row.
      3. Run the script with the file:

        php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv
        

      4. Make sure CLI script prints the message error '"" is not a valid field name'.
      5. Download a fresh examplecohorts.csv.
      6. Edit it and add a "x" colum after "cohort1".
      7. Run the script with the file:

        php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv
        

      8. Make sure CLI script prints the message error ' "x" is not a valid field name'.
      9. Download a fresh examplecohorts.csv.
      10. Run the script with the file:

        php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv --uutype=5
        

      11. Make sure CLI script prints the message error "Value for argument --uutype is not valid. Allowed values: 0, 1, 2, 3"
      12. Run the script with the file:

        php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv --country=Australia
        

      13. Make sure CLI script prints the message error "Value for argument --country is not valid. Allowed values: , AF, AX, [...]"

       

      Test 3. Colors in the UI

      1. Go to "Site administration > Users > Accounts > Upload users"
      2. Upload the same file, submit again leave all default values
      3. Make sure the status column displays warnings with yellow-ish background
      4. Upload the same file, submit and then change the upload type to "update existing users"
      5. On the next screen, make sure the enrolment actions are displayed with green-ish background
      6. In the CSV file change one of the users' names, upload it and submit the second form with the default values
      7. Check the error message about the duplicate email address is displayed with the red-ish background

       

      Show
      If you want, create your own CSV file and follow documentation to https://docs.moodle.org/39/en/Upload_users Test 1. Basic scenarios In the command line from the moodle directory run php admin/tool/uploaduser/cli/uploaduser.php --help Observe the generated help and make sure it makes sense (i.e. information about the script, its supported parameters and how to use it should be printed) Try to run CLI script without arguments php admin/tool/uploaduser/cli/uploaduser.php Check the "Argument --file is required" message is displayed Try to run CLI script specifying non-existing file. The script should fail and exit code should be 1 php admin/tool/uploaduser/cli/uploaduser.php --file=PATHTONONEXISTINGFILE Check the "File xxxxxxx does not exist or is not readable" message is displayed Take attached examplecohorts.csv file, copy it to the Moodle root directory and run: php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv Make sure users are created and added to the cohorts. There will be errors about non existing course Create the course with shortname "math102" Run the same script again - it should say that users already exist. Make sure users are not enrolled in the course. Run the same script with the same file but with additional argument php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv --uutype=2 Make sure users are now enrolled into the course and groups are created and the users are added to the groups groupA and groupB (as in the file) Run the command (this will use semicolon as delimiter): php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv --delimiter_name=semicolon Check the errors "Not enough columns" is displayed Replace all commas in the file with semicolons and run the same command again. Check script completes correctly (in this case there will be no changes because users already exist) Test 2 . Error testing Download a fresh examplecohorts.csv. Edit it and remove the "cohort1" text in the first row. Run the script with the file: php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv Make sure CLI script prints the message error '"" is not a valid field name'. Download a fresh examplecohorts.csv. Edit it and add a "x" colum after "cohort1". Run the script with the file: php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv Make sure CLI script prints the message error ' "x" is not a valid field name'. Download a fresh examplecohorts.csv. Run the script with the file: php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv --uutype=5 Make sure CLI script prints the message error "Value for argument --uutype is not valid. Allowed values: 0, 1, 2, 3" Run the script with the file: php admin/tool/uploaduser/cli/uploaduser.php --file=../../../../examplecohorts.csv --country=Australia Make sure CLI script prints the message error "Value for argument --country is not valid. Allowed values: , AF, AX, [...] "   Test 3. Colors in the UI Go to "Site administration > Users > Accounts > Upload users" Upload the same file, submit again leave all default values Make sure the status column displays warnings with yellow-ish background Upload the same file, submit and then change the upload type to "update existing users" On the next screen, make sure the enrolment actions are displayed with green-ish background In the CSV file change one of the users' names, upload it and submit the second form with the default values Check the error message about the duplicate email address is displayed with the red-ish background  
    • Affected Branches:
      MOODLE_36_STABLE
    • Fixed Branches:
      MOODLE_310_STABLE
    • Pull 3.10 Branch:
      MDL-65451-310
    • Pull Master Branch:

      Description

      I would like to upload users from command line and also enrolling them to courses. Currently I generate a CSV and use the web interface to perform this, which takes a long and I would like to automate this, as data source is a special database with daily updates.

      So I would like to have something like this:

      php admin/tool/uploaduser/cli/uploaduser.php userlist.csv

        Attachments

        1. examplecohorts.csv
          0.2 kB
        2. Screenshot_1.jpg
          Screenshot_1.jpg
          101 kB
        3. Screenshot_2.jpg
          Screenshot_2.jpg
          106 kB
        4. Screenshot_3.jpg
          Screenshot_3.jpg
          75 kB
        5. Screenshot_4.jpg
          Screenshot_4.jpg
          105 kB
        6. Screenshot_5.jpg
          Screenshot_5.jpg
          51 kB
        7. upload_users.csv
          0.1 kB

          Issue Links

            Activity

              People

              Assignee:
              marina Marina Glancy
              Reporter:
              epititk Bence Molnar
              Integrator:
              Sara Arjona (@sarjona) Sara Arjona (@sarjona)
              Tester:
              Janelle Barcega Janelle Barcega
              Participants:
              Component watchers:
              Andrew Lyons, Dongsheng Cai, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              4 Vote for this issue
              Watchers:
              12 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                9/Nov/20

                  Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 4 days, 2 hours, 31 minutes
                  4d 2h 31m