Remove avatar on user deletion

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2017-09-27 13:17:34 +02:00 committed by Robin Appelman
parent 949fc50cc5
commit 10aa287463
No known key found for this signature in database
GPG Key ID: CBCA68FBAEBF98C9
1 changed files with 23 additions and 0 deletions

View File

@ -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
*/