From 949fc50cc5c2927c08c35ab7e0987ceceb708013 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 27 Sep 2017 12:53:56 +0200 Subject: Dispatch event on User predelete Signed-off-by: Roeland Jago Douma --- lib/private/Server.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/private/Server.php') diff --git a/lib/private/Server.php b/lib/private/Server.php index f4f7cb75ad1..0886dfd4413 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -133,6 +133,7 @@ use OCP\Share; use OCP\Share\IShareHelper; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; /** * Class Server @@ -348,6 +349,8 @@ class Server extends ServerContainer implements IServerContainer { $defaultTokenProvider = null; } + $dispatcher = $c->getEventDispatcher(); + $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); @@ -356,9 +359,10 @@ class Server extends ServerContainer implements IServerContainer { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); }); - $userSession->listen('\OC\User', 'preDelete', function ($user) { + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); + $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); }); $userSession->listen('\OC\User', 'postDelete', function ($user) { /** @var $user \OC\User\User */ -- cgit v1.2.3 From 10aa287463b6888d2e418ad31fa3a390fbea359e Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 27 Sep 2017 13:17:34 +0200 Subject: Remove avatar on user deletion Signed-off-by: Roeland Jago Douma --- lib/private/Server.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib/private/Server.php') 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 */ -- cgit v1.2.3 From 05d2f61a592861ecbd517307de2b868d35566300 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 Dec 2017 16:39:44 +0100 Subject: handle not found mounts when cleaning avatars Signed-off-by: Robin Appelman --- lib/private/Files/View.php | 6 ++++++ lib/private/Server.php | 3 +++ 2 files changed, 9 insertions(+) (limited to 'lib/private/Server.php') diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 58552be2609..592d4b717ce 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -1362,6 +1362,9 @@ class View { $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path); $mount = Filesystem::getMountManager()->find($path); + if (!$mount) { + return false; + } $storage = $mount->getStorage(); $internalPath = $mount->getInternalPath($path); if ($storage) { @@ -1411,6 +1414,9 @@ class View { $path = $this->getAbsolutePath($directory); $path = Filesystem::normalizePath($path); $mount = $this->getMount($directory); + if (!$mount) { + return []; + } $storage = $mount->getStorage(); $internalPath = $mount->getInternalPath($path); if ($storage) { diff --git a/lib/private/Server.php b/lib/private/Server.php index 3f26f975f0f..0dfbcbb75ec 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -118,6 +118,7 @@ use OCP\Defaults; use OCA\Theming\Util; use OCP\Federation\ICloudIdManager; use OCP\Authentication\LoginCredentials\IStore; +use OCP\Files\NotFoundException; use OCP\ICacheFactory; use OCP\IDBConnection; use OCP\IL10N; @@ -1151,6 +1152,8 @@ class Server extends ServerContainer implements IServerContainer { try { $avatar = $manager->getAvatar($user->getUID()); $avatar->remove(); + } catch (NotFoundException $e) { + // no avatar to remove } catch (\Exception $e) { // Ignore exceptions $logger->info('Could not cleanup avatar of ' . $user->getUID()); -- cgit v1.2.3