Moodle
  1. Moodle
  2. MDL-11752

Add ability to mass/bulk upload user profile images

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9
    • Fix Version/s: 1.9
    • Component/s: Administration
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE
    • Rank:
      36782

      Description

      Since Moodle development is looking at user images I thought it might be a convenient time to add a feature request for administrators to be able to mass or bulk upload user profile images. This is particularly helpful in schools that receive school pictures from a photographer. The admins would be able to copy the files to a particular directory and have Moodle process those images into the user profile. A previous hack that I did accomplished this by modifying the /lib/gdlib file and creating a second save_profile_image function that took the filename as input for a filename rather than using the upload manager. I would think that the function could be fairly easily modified to detect file or upload manager. I am attaching a patch that Iñaki submitted for Moodle 1.8.2 (prior to the change in the location of files as related to MDL-8605). An updated patch file is to follow for 1.8+ and 1.9. For increased flexibility, it might be worth considering creating a CFG->uploadprofilepath to the path the the user profile images are stored (I had hardcoded mine to be /userpix/jpg but something like /userpix/import could work as well) and an option for CFG->uploadprofilename to determine whether to use the user's username, Moodle id, or idnumber as the name of the file (or any other field that could uniquely identify the user).

      See http://moodle.org/mod/forum/discuss.php?d=36405 for the discussion.

      I have also included my patch of the /lib/gdlib.php file (also 1.8.2, i.e. pre MDL-8605) that shows the changes I made to use a filename. This can be a real time saver for system administrators at schools and hopefully is fairly easy to accomplish. Peace - Anthony

      1. gdlib.php.diff
        4 kB
        Anthony Borrow
      2. mass-upload-user-pictures-1.8.2.tar.gz
        5 kB
        Anthony Borrow
      3. mass-upload-user-pictures-1.8.3.diff
        18 kB
        Iñaki Arenaza
      4. mass-upload-user-pictures-1.8.3.diff
        17 kB
        Iñaki Arenaza
      5. mass-upload-user-pictures-1.8.3.tar.gz
        8 kB
        Iñaki Arenaza
      6. mass-upload-user-pictures-1.8.3.tar.gz
        8 kB
        Iñaki Arenaza
      7. mass-upload-user-pictures-1.8.7.diff
        19 kB
        Iñaki Arenaza
      8. mass-upload-user-pictures-1.9beta2.diff
        16 kB
        Iñaki Arenaza
      9. mass-upload-user-pictures-1.9beta2.tar.gz
        8 kB
        Iñaki Arenaza
      10. mass-upload-user-pictures-1.9beta3.diff
        17 kB
        Iñaki Arenaza
      11. mass-upload-user-pictures-1.9beta3.tar.gz
        9 kB
        Iñaki Arenaza
      12. mass-upload-user-pictures-1.9beta4.diff
        17 kB
        Iñaki Arenaza

        Issue Links

          Activity

          Hide
          Anthony Borrow added a comment - - edited

          MDL-4520 requests that the /lib/gdlib.php save_profile_image function be able to accept a URL of an image and is another possible improvement related to improving the ability and ease of which images can be added. It may be good to work on these issues together.

          Show
          Anthony Borrow added a comment - - edited MDL-4520 requests that the /lib/gdlib.php save_profile_image function be able to accept a URL of an image and is another possible improvement related to improving the ability and ease of which images can be added. It may be good to work on these issues together.
          Hide
          Iñaki Arenaza added a comment -

          Here are updated patches for both 1.8.3+ and 1.9Beta2 (current as of today). The patch allows the admin to:

          • upload a zip file containing the user images.
          • specify which user profile field to use to match images: username, idnumber or id. Adding new fields is trivial (see the $userfields array at the top of uploadpicture.php).

          The code assumes the image files are named 'chosen-profile-field.extension'. Extensive checks are made to ensure everythings ok before using the picture files. Also, the proposed changes allow authentication plugin to easily set user images from external sources (ldap, database, etc.).

          I'm attaching two files: the big patch ready to be applied, and a patch series with broken down changes and comments (so it's easier to review).

          Saludos. Iñaki.

          Show
          Iñaki Arenaza added a comment - Here are updated patches for both 1.8.3+ and 1.9Beta2 (current as of today). The patch allows the admin to: upload a zip file containing the user images. specify which user profile field to use to match images: username, idnumber or id. Adding new fields is trivial (see the $userfields array at the top of uploadpicture.php). The code assumes the image files are named 'chosen-profile-field.extension'. Extensive checks are made to ensure everythings ok before using the picture files. Also, the proposed changes allow authentication plugin to easily set user images from external sources (ldap, database, etc.). I'm attaching two files: the big patch ready to be applied, and a patch series with broken down changes and comments (so it's easier to review). Saludos. Iñaki.
          Hide
          Anthony Borrow added a comment -

          Iñaki - Thanks for the patches. I will give them a shot and see what happens but what you describe sounds wonderful. A tweak or check that I can see some admins requesting is the ability to choose whether to overwrite an existing image if it exists. I can imagine where the admin may want to assign an image regardless of whether the user had previously uploaded one or not and also wanting to say here is a default image; however, if the user already uploaded one let them use it. Does that make sense and seem practical? Peace - Anthony

          Show
          Anthony Borrow added a comment - Iñaki - Thanks for the patches. I will give them a shot and see what happens but what you describe sounds wonderful. A tweak or check that I can see some admins requesting is the ability to choose whether to overwrite an existing image if it exists. I can imagine where the admin may want to assign an image regardless of whether the user had previously uploaded one or not and also wanting to say here is a default image; however, if the user already uploaded one let them use it. Does that make sense and seem practical? Peace - Anthony
          Hide
          Iñaki Arenaza added a comment -

          > A tweak or check that I can see some admins requesting is the ability to choose whether to overwrite an existing image if it exists.

          That should be really easy to add. I'll give it a go

          Saludos. Iñaki.

          Show
          Iñaki Arenaza added a comment - > A tweak or check that I can see some admins requesting is the ability to choose whether to overwrite an existing image if it exists. That should be really easy to add. I'll give it a go Saludos. Iñaki.
          Hide
          Anthony Borrow added a comment -

          Martin - Does adding the ability to upload user pics en masse (by the Moodle administrator) seem like something that you would like to see in HEAD? I think it would make a nice addition to Moodle 2.0. Peace - Anthony

          Show
          Anthony Borrow added a comment - Martin - Does adding the ability to upload user pics en masse (by the Moodle administrator) seem like something that you would like to see in HEAD? I think it would make a nice addition to Moodle 2.0. Peace - Anthony
          Hide
          Iñaki Arenaza added a comment -

          By the way, I added the ability to choose whether to overwrite an existing image if it exists, but I forgot to upload the patches here. They have been sitting at my laptop nearly 2 weeks :-o. So here they go.

          Saludos. Iñaki.

          Show
          Iñaki Arenaza added a comment - By the way, I added the ability to choose whether to overwrite an existing image if it exists, but I forgot to upload the patches here. They have been sitting at my laptop nearly 2 weeks :-o. So here they go. Saludos. Iñaki.
          Hide
          Anthony Borrow added a comment -

          Excellent - I'll put it on my desktop and hopefully get to testing it soon. Peace - Anthony

          Show
          Anthony Borrow added a comment - Excellent - I'll put it on my desktop and hopefully get to testing it soon. Peace - Anthony
          Hide
          Anthony Borrow added a comment -

          Iñaki - I've tested this on my test server (Moodle 1.8) with production data and it worked like a champ. I wonder if Martin might consider allowing these patches into 1.9 as they go along nicely with the improved user management features from the GSoC work. Peace - Anthony

          Show
          Anthony Borrow added a comment - Iñaki - I've tested this on my test server (Moodle 1.8) with production data and it worked like a champ. I wonder if Martin might consider allowing these patches into 1.9 as they go along nicely with the improved user management features from the GSoC work. Peace - Anthony
          Hide
          Iñaki Arenaza added a comment -

          I see the upload users form has been converted to moodleforms. Before adding this to 1.9 I think we should convert uploadpicture.php to use moodleforms too. I'll be a bit busy the following days, but will give it a go as time permits.

          Saludos. Iñaki.

          Show
          Iñaki Arenaza added a comment - I see the upload users form has been converted to moodleforms. Before adding this to 1.9 I think we should convert uploadpicture.php to use moodleforms too. I'll be a bit busy the following days, but will give it a go as time permits. Saludos. Iñaki.
          Hide
          Iñaki Arenaza added a comment -

          It was easier than I expected, so I'm attaching a full patch against 1.9beta4 (current as of today). If Martin or anybody else needs the broken down patch series (to better analyze the changes) I can upload them on request.

          Saludos. Iñaki.

          Show
          Iñaki Arenaza added a comment - It was easier than I expected, so I'm attaching a full patch against 1.9beta4 (current as of today). If Martin or anybody else needs the broken down patch series (to better analyze the changes) I can upload them on request. Saludos. Iñaki.
          Hide
          Anthony Borrow added a comment -

          Iñaki - Thanks for the great work. My +1 for getting this into Moodle 1.9 (hopefully). Administratively it is a huge time saver. Peace - Anthony

          Show
          Anthony Borrow added a comment - Iñaki - Thanks for the great work. My +1 for getting this into Moodle 1.9 (hopefully). Administratively it is a huge time saver. Peace - Anthony
          Hide
          Anthony Borrow added a comment -

          Martin - I did some testing of uploading a bunch of user pics using the patch here on 1.9 and it looks pretty good. As mentioned, I think this goes along nicely with some of the other 1.9 improvements for dealing with importing users en masse. I applied the 1.8 patch to my Dallas production server and it was a big time saver. Iñaki's patch for 1.9 should make this pretty easy to drop in to 1.9 if you are interested. Peace - Anthony

          Show
          Anthony Borrow added a comment - Martin - I did some testing of uploading a bunch of user pics using the patch here on 1.9 and it looks pretty good. As mentioned, I think this goes along nicely with some of the other 1.9 improvements for dealing with importing users en masse. I applied the 1.8 patch to my Dallas production server and it was a big time saver. Iñaki's patch for 1.9 should make this pretty easy to drop in to 1.9 if you are interested. Peace - Anthony
          Hide
          Martin Dougiamas added a comment -

          Great, nice little timesaver! I've checked it out and checked it in.

          Show
          Martin Dougiamas added a comment - Great, nice little timesaver! I've checked it out and checked it in.
          Hide
          Helen Foster added a comment -

          Thanks for this nice little feature

          Documentation here: http://docs.moodle.org/en/Upload_user_pictures

          Show
          Helen Foster added a comment - Thanks for this nice little feature Documentation here: http://docs.moodle.org/en/Upload_user_pictures
          Hide
          Ray Lawrence added a comment -

          Just tested. Works like a charm. Nice one, cheers.

          Show
          Ray Lawrence added a comment - Just tested. Works like a charm. Nice one, cheers.
          Hide
          Anthony Borrow added a comment -

          Resolving as fixed!

          Show
          Anthony Borrow added a comment - Resolving as fixed!
          Hide
          Iñaki Arenaza added a comment -

          Upload an updated version of the patch for 1.8 (current as of today), so interested people can use it (the previous patch was missing the ability to process zip files with nested directories).

          Saludos. Iñaki.

          Show
          Iñaki Arenaza added a comment - Upload an updated version of the patch for 1.8 (current as of today), so interested people can use it (the previous patch was missing the ability to process zip files with nested directories). Saludos. Iñaki.
          Hide
          David Banach added a comment -

          Hi,
          Thanks so much for this great feature.

          I applied the patch for 1.8.7 and it was unable to add pictures via idnumber. When I uploaded the zip file I got lots of messages saying that there was no username that fit that number (the idnumber).

          When I edited the uploadpicture.php and eliminated id and username from the $userfields array I was able to upload the zip file fine.

          It works wonderfully for me now, but I imagine others may have the same problem I did.

          Thanks again for the cool patch!

          David

          Show
          David Banach added a comment - Hi, Thanks so much for this great feature. I applied the patch for 1.8.7 and it was unable to add pictures via idnumber. When I uploaded the zip file I got lots of messages saying that there was no username that fit that number (the idnumber). When I edited the uploadpicture.php and eliminated id and username from the $userfields array I was able to upload the zip file fine. It works wonderfully for me now, but I imagine others may have the same problem I did. Thanks again for the cool patch! David
          Hide
          Nicolas Connault added a comment -

          Tested, works well. Thanks!

          Show
          Nicolas Connault added a comment - Tested, works well. Thanks!

            People

            • Votes:
              5 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: