summaryrefslogtreecommitdiffstats
path: root/lib/private/Server.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2017-09-27 13:17:34 +0200
committerRobin Appelman <robin@icewind.nl>2017-12-11 16:07:06 +0100
commit10aa287463b6888d2e418ad31fa3a390fbea359e (patch)
tree788658be352da0ab732fd33037f9c339b4e22b78 /lib/private/Server.php
parent949fc50cc5c2927c08c35ab7e0987ceceb708013 (diff)
downloadnextcloud-server-10aa287463b6888d2e418ad31fa3a390fbea359e.tar.gz
nextcloud-server-10aa287463b6888d2e418ad31fa3a390fbea359e.zip
Remove avatar on user deletion
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Server.php')
-rw-r--r--lib/private/Server.php23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 0886dfd4413..3f26f975f0f 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -124,6 +124,7 @@ use OCP\IL10N;
use OCP\IServerContainer;
use OCP\ITempManager;
use OCP\Contacts\ContactsMenu\IActionFactory;
+use OCP\IUser;
use OCP\Lock\ILockingProvider;
use OCP\Remote\Api\IApiFactory;
use OCP\Remote\IInstanceFactory;
@@ -1126,6 +1127,8 @@ class Server extends ServerContainer implements IServerContainer {
$memcacheFactory = $c->getMemCacheFactory();
return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
});
+
+ $this->connectDispatcher();
}
/**
@@ -1135,6 +1138,26 @@ class Server extends ServerContainer implements IServerContainer {
return $this->query('CalendarManager');
}
+ private function connectDispatcher() {
+ $dispatcher = $this->getEventDispatcher();
+
+ // Delete avatar on user deletion
+ $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
+ $logger = $this->getLogger();
+ $manager = $this->getAvatarManager();
+ /** @var IUser $user */
+ $user = $e->getSubject();
+
+ try {
+ $avatar = $manager->getAvatar($user->getUID());
+ $avatar->remove();
+ } catch (\Exception $e) {
+ // Ignore exceptions
+ $logger->info('Could not cleanup avatar of ' . $user->getUID());
+ }
+ });
+ }
+
/**
* @return \OCP\Contacts\IManager
*/