Repository: hydroshare/hydroshare

Issue:
blank user profile images
**Description of the bug**
I noted that there are some users for whom our templates attempt to load a profile picture that no longer exists.
Examples:
https://www.hydroshare.org/user/11139/
https://www.hydroshare.org/user/741/
https://www.hydroshare.org/user/4138/
https://www.hydroshare.org/user/4733/

![image](https://user-images.githubusercontent.com/17934193/174645178-e9f32fa6-dba0-4335-af9e-46867697491d.png)


Steps to reproduce the bug:
1. Click on one of the above
2. See the blank profile picture
3. Note the 404 in your network tab

**Expected behavior**
A placeholder image should load when there is a missing image. Ideally missing image refs should be cleared out of the db.



Discussion:
related to #2637 and PR #4672
@hyi do you think these dangling images could be caused by [cleanup_profile_media_files](https://github.com/hydroshare/hydroshare/blob/develop/theme/management/commands/cleanup_profile_media_files.py)?

Or potentially related to recent collectstatic modifications...
@Castronova have you noticed that [your profile image](https://www.hydroshare.org/user/11/) is blank before, or is this a recent development?

@ClaraCogswell I already asked you but LMK if you think [this changed ](https://www.hydroshare.org/user/11139/)recently...thanks!
I've had several issues with my profile picture over the last couple of years. First it was rotated upside down. I replaced it with a different image, then one day it was just blank. I kind of just gave up on it because I figured the issue was only isolated to me. I'll replace my image again and let you know if something else happens.
Sorry to hear the image woes @Castronova, almost sounds like someone was pranking. Appreciate the info, good to know that this has been an ongoing issue
```
from theme.models import UserProfile
query = UserProfile.objects.only("picture").all()
for profile in query:
    if profile.user.is_active and (not profile.picture.storage.exists(profile.picture.name) and profile.picture):
        print(f"{profile.user.id}, {profile.user.username}, {profile.website}, {profile.user.date_joined}")
```
Gives a list of **380** profiles that have a profile ImageField in the django db that doesn't actually exist in our static files
The vast majority of them appear to be spam accounts
@martinseul ^^^
@devincowan Thanks, so seems no urgent need for a hotfix we'll role it out in a regular release 


Resolving patch:
diff --git a/theme/management/commands/remove_missing_profile_imgs_from_db.py b/theme/management/commands/remove_missing_profile_imgs_from_db.py
new file mode 100644
--- /dev/null
+++ b/theme/management/commands/remove_missing_profile_imgs_from_db.py
@@ -0,0 +1,15 @@
+from django.core.management.base import BaseCommand
+
+from theme.models import UserProfile
+
+
+class Command(BaseCommand):
+    help = "This command can be run to clear image references from the db for profile media that no longer exist"
+
+    def handle(self, *args, **options):
+        ups = UserProfile.objects.only("picture", "user").all()
+        for profile in ups:
+            if profile.user.is_active:
+                if profile.picture and not profile.picture.storage.exists(profile.picture.name):
+                    profile.picture.delete()
+                    print(f"Removed profile picture reference for user {profile.user.id}: {profile.user.username}")


Test patch: