[PR #4560] [MERGED] Artisan command for updating avatars for existing users #6374

Closed
opened 2026-02-05 10:30:37 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/BookStackApp/BookStack/pull/4560
Author: @MarcHagen
Created: 9/18/2023
Status: Merged
Merged: 9/19/2023
Merged by: @ssddanbrown

Base: developmentHead: issue-1893


📝 Commits (2)

  • ea75925 feat: Artisan command for updating avatars for existing users
  • ca98155 fix: Actually check if we have correct data

📊 Changes

3 files changed (+479 additions, -5 deletions)

View changed files

app/Console/Commands/RefreshAvatarCommand.php (+155 -0)
📝 app/Uploads/UserAvatars.php (+7 -5)
tests/Commands/RefreshAvatarCommandTest.php (+317 -0)

📄 Description


Adding a console command to:

  • Update one user's avatar, searching the user by id or email (--email= or --id=)
  • Updating all users that do not have an avatar (--users-without-avatars)
    • Default behavior is dry-run
  • Updating all users' avatars (--all)
    • Default behavior is dry-run

Adding check for avatar fetching if the response code is OK.

Having the https://github.com/BookStackApp/BookStack/pull/3232#issuecomment-1028884677 in mind.

Please let me know if any changes or refactoring is needed!


Console outputs:
# php artisan bookstack:refresh-avatar
Either a --id=<number> or --email=<email> option must be provided.
Run with `--help` to more options
# php artisan bookstack:refresh-avatar --id=123
A user where id=123 could not be found.
# php artisan bookstack:refresh-avatar --id=1
This will refresh the avatar for user:
- ID: 1
- Name: Admin
- Email: admin@admin.com

 Are you sure you want to proceed? (yes/no) [no]:
 > yes

User avatar has been updated.
# php artisan bookstack:refresh-avatar --users-without-avatars
2 user(s) found without avatars.
ID 1 - Not updated
ID 2 - Not updated

Dry run, no avatars have been updated
Run with -f or --force to perform the update
# php artisan bookstack:refresh-avatar --users-without-avatars -f
2 user(s) found without avatars.

 Are you sure you want to refresh avatars of users that do not have one? (yes/no) [no]:
 > yes

ID 1 - Updated
ID 2 - Updated
# php artisan bookstack:refresh-avatar --all
2 user(s) found.
ID 1 - Not updated
ID 2 - Not updated

Dry run, no avatars have been updated
Run with -f or --force to perform the update
# php artisan bookstack:refresh-avatar --all -f
2 user(s) found.

 Are you sure you want to refresh avatars for ALL USERS? (yes/no) [no]:
 > yes

ID 1 - Updated
ID 2 - Updated

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/BookStackApp/BookStack/pull/4560 **Author:** [@MarcHagen](https://github.com/MarcHagen) **Created:** 9/18/2023 **Status:** ✅ Merged **Merged:** 9/19/2023 **Merged by:** [@ssddanbrown](https://github.com/ssddanbrown) **Base:** `development` ← **Head:** `issue-1893` --- ### 📝 Commits (2) - [`ea75925`](https://github.com/BookStackApp/BookStack/commit/ea7592509f61605b84959d39d74757e962501609) feat: Artisan command for updating avatars for existing users - [`ca98155`](https://github.com/BookStackApp/BookStack/commit/ca98155373e759b65d2e62558c97a68f7158c704) fix: Actually check if we have correct data ### 📊 Changes **3 files changed** (+479 additions, -5 deletions) <details> <summary>View changed files</summary> ➕ `app/Console/Commands/RefreshAvatarCommand.php` (+155 -0) 📝 `app/Uploads/UserAvatars.php` (+7 -5) ➕ `tests/Commands/RefreshAvatarCommandTest.php` (+317 -0) </details> ### 📄 Description - Related: https://github.com/BookStackApp/BookStack/pull/3232 - Solves: https://github.com/BookStackApp/BookStack/issues/1893 --- Adding a console command to: - Update one user's avatar, searching the user by id or email (--email= or --id=) - Updating all users that do not have an avatar (--users-without-avatars) - Default behavior is dry-run - Updating all users' avatars (--all) - Default behavior is dry-run Adding check for avatar fetching if the response code is OK. Having the https://github.com/BookStackApp/BookStack/pull/3232#issuecomment-1028884677 in mind. Please let me know if any changes or refactoring is needed! --- <details> <summary>Console outputs:</summary> ```bash # php artisan bookstack:refresh-avatar Either a --id=<number> or --email=<email> option must be provided. Run with `--help` to more options ``` ```bash # php artisan bookstack:refresh-avatar --id=123 A user where id=123 could not be found. ``` ```bash # php artisan bookstack:refresh-avatar --id=1 This will refresh the avatar for user: - ID: 1 - Name: Admin - Email: admin@admin.com Are you sure you want to proceed? (yes/no) [no]: > yes User avatar has been updated. ``` ```bash # php artisan bookstack:refresh-avatar --users-without-avatars 2 user(s) found without avatars. ID 1 - Not updated ID 2 - Not updated Dry run, no avatars have been updated Run with -f or --force to perform the update ``` ```bash # php artisan bookstack:refresh-avatar --users-without-avatars -f 2 user(s) found without avatars. Are you sure you want to refresh avatars of users that do not have one? (yes/no) [no]: > yes ID 1 - Updated ID 2 - Updated ``` ```bash # php artisan bookstack:refresh-avatar --all 2 user(s) found. ID 1 - Not updated ID 2 - Not updated Dry run, no avatars have been updated Run with -f or --force to perform the update ``` ```bash # php artisan bookstack:refresh-avatar --all -f 2 user(s) found. Are you sure you want to refresh avatars for ALL USERS? (yes/no) [no]: > yes ID 1 - Updated ID 2 - Updated ``` </details> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2026-02-05 10:30:37 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#6374