diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-03-13 14:16:43 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2020-04-24 16:27:17 +0200 |
commit | d74e9045ac5856c728e7b325ca0cfc22c92674bd (patch) | |
tree | afa5415fad3195c9e969636b9531b0854c9fec61 /lib/private/Avatar/AvatarManager.php | |
parent | 84a35361599640d838815a4127eab58e49f052fc (diff) | |
download | nextcloud-server-d74e9045ac5856c728e7b325ca0cfc22c92674bd.tar.gz nextcloud-server-d74e9045ac5856c728e7b325ca0cfc22c92674bd.zip |
Delete avatar if a user is deleted
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/private/Avatar/AvatarManager.php')
-rw-r--r-- | lib/private/Avatar/AvatarManager.php | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/private/Avatar/AvatarManager.php b/lib/private/Avatar/AvatarManager.php index 3bb0c4077e2..37f57c90769 100644 --- a/lib/private/Avatar/AvatarManager.php +++ b/lib/private/Avatar/AvatarManager.php @@ -33,8 +33,10 @@ declare(strict_types=1); namespace OC\Avatar; use OC\User\Manager; +use OC\User\NoUserException; use OCP\Files\IAppData; use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; use OCP\IAvatar; use OCP\IAvatarManager; use OCP\IConfig; @@ -125,6 +127,20 @@ class AvatarManager implements IAvatarManager { } } + public function deleteUserAvatar(string $userId): void { + try { + $folder = $this->appData->getFolder($userId); + $folder->delete(); + } catch (NotFoundException $e) { + $this->logger->debug("No cache for the user $userId. Ignoring avatar deletion"); + } catch (NotPermittedException $e) { + $this->logger->error("Unable to delete user avatars for $userId. gnoring avatar deletion"); + } catch (NoUserException $e) { + $this->logger->debug("User $userId not found. gnoring avatar deletion"); + } + $this->config->deleteUserValue($userId, 'avatar', 'generated'); + } + /** * Returns a GuestAvatar. * |