Remove avatar on user deletion
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
949fc50cc5
commit
10aa287463
|
@ -124,6 +124,7 @@ use OCP\IL10N;
|
||||||
use OCP\IServerContainer;
|
use OCP\IServerContainer;
|
||||||
use OCP\ITempManager;
|
use OCP\ITempManager;
|
||||||
use OCP\Contacts\ContactsMenu\IActionFactory;
|
use OCP\Contacts\ContactsMenu\IActionFactory;
|
||||||
|
use OCP\IUser;
|
||||||
use OCP\Lock\ILockingProvider;
|
use OCP\Lock\ILockingProvider;
|
||||||
use OCP\Remote\Api\IApiFactory;
|
use OCP\Remote\Api\IApiFactory;
|
||||||
use OCP\Remote\IInstanceFactory;
|
use OCP\Remote\IInstanceFactory;
|
||||||
|
@ -1126,6 +1127,8 @@ class Server extends ServerContainer implements IServerContainer {
|
||||||
$memcacheFactory = $c->getMemCacheFactory();
|
$memcacheFactory = $c->getMemCacheFactory();
|
||||||
return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
|
return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->connectDispatcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1135,6 +1138,26 @@ class Server extends ServerContainer implements IServerContainer {
|
||||||
return $this->query('CalendarManager');
|
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
|
* @return \OCP\Contacts\IManager
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue