]> BookStack Code Mirror - bookstack/blobdiff - app/Repos/UserRepo.php
#630: Deleting user's profile pics on deleting of user account (#646)
[bookstack] / app / Repos / UserRepo.php
index 52ad2e47e9a3390dd5ed3665a714fe2d361bcee2..a159606da74ca48ba41c0559839fcf1dd50f05f7 100644 (file)
@@ -3,6 +3,7 @@
 use BookStack\Role;
 use BookStack\User;
 use Exception;
+use BookStack\Services\ImageService;
 
 class UserRepo
 {
@@ -10,6 +11,7 @@ class UserRepo
     protected $user;
     protected $role;
     protected $entityRepo;
+    protected $imageService;
 
     /**
      * UserRepo constructor.
@@ -17,11 +19,12 @@ class UserRepo
      * @param Role $role
      * @param EntityRepo $entityRepo
      */
-    public function __construct(User $user, Role $role, EntityRepo $entityRepo)
+    public function __construct(User $user, Role $role, EntityRepo $entityRepo, ImageService $imageService)
     {
         $this->user = $user;
         $this->role = $role;
         $this->entityRepo = $entityRepo;
+        $this->imageService = $imageService;
     }
 
     /**
@@ -145,6 +148,12 @@ class UserRepo
     {
         $user->socialAccounts()->delete();
         $user->delete();
+        
+        // Deleting User profile pics
+        $profilePic = $user->image_id ? $user->avatar->findOrFail($user->image_id) : FALSE;
+        if ($profilePic) {
+            $this->imageService->destroyImage($profilePic);
+        }
     }
 
     /**