clear mount cache when deleting user

This commit is contained in:
Robin Appelman 2015-12-03 14:10:05 +01:00
parent 99415a9f7f
commit be380accb9
4 changed files with 101 additions and 18 deletions

View File

@ -195,4 +195,17 @@ class UserMountCache implements IUserMountCache {
return array_map([$this, 'dbRowToMountInfo'], $rows);
}
/**
* Remove all cached mounts for a user
*
* @param IUser $user
*/
public function removeUserMounts(IUser $user) {
$builder = $this->connection->getQueryBuilder();
$query = $builder->delete('mounts')
->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID())));
$query->execute();
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* @author Robin Appelman <icewind@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Files\Config;
use OC\User\Manager;
use OCP\Files\Config\IUserMountCache;
/**
* Listen to hooks and update the mount cache as needed
*/
class UserMountCacheListener {
/**
* @var IUserMountCache
*/
private $userMountCache;
/**
* UserMountCacheListener constructor.
*
* @param IUserMountCache $userMountCache
*/
public function __construct(IUserMountCache $userMountCache) {
$this->userMountCache = $userMountCache;
}
public function listen(Manager $manager) {
$manager->listen('\OC\User', 'postDelete', [$this->userMountCache, 'removeUserMounts']);
}
}

View File

@ -48,6 +48,7 @@ use OC\Diagnostics\NullEventLogger;
use OC\Diagnostics\NullQueryLogger;
use OC\Diagnostics\QueryLogger;
use OC\Files\Config\UserMountCache;
use OC\Files\Config\UserMountCacheListener;
use OC\Files\Node\HookConnector;
use OC\Files\Node\Root;
use OC\Files\View;
@ -405,9 +406,15 @@ class Server extends ServerContainer implements IServerContainer {
$c->getL10N('lib', $language)
);
});
$this->registerService('UserMountCache', function (Server $c) {
$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
$listener = new UserMountCacheListener($mountCache);
$listener->listen($c->getUserManager());
return $mountCache;
});
$this->registerService('MountConfigManager', function (Server $c) {
$loader = \OC\Files\Filesystem::getLoader();
$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
$mountCache = $c->query('UserMountCache');
return new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
});
$this->registerService('IniWrapper', function ($c) {
@ -923,6 +930,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* Returns an instance of the db facade
*
* @deprecated use getDatabaseConnection, will be removed in ownCloud 10
* @return \OCP\IDb
*/
@ -932,6 +940,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* Returns an instance of the HTTP helper class
*
* @deprecated Use getHTTPClientService()
* @return \OC\HTTPHelper
*/
@ -1173,6 +1182,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* Not a public API as of 8.2, wait for 9.0
*
* @return \OCA\Files_External\Service\BackendService
*/
public function getStoragesBackendService() {
@ -1181,6 +1191,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* Not a public API as of 8.2, wait for 9.0
*
* @return \OCA\Files_External\Service\GlobalStoragesService
*/
public function getGlobalStoragesService() {
@ -1189,6 +1200,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* Not a public API as of 8.2, wait for 9.0
*
* @return \OCA\Files_External\Service\UserGlobalStoragesService
*/
public function getUserGlobalStoragesService() {
@ -1197,6 +1209,7 @@ class Server extends ServerContainer implements IServerContainer {
/**
* Not a public API as of 8.2, wait for 9.0
*
* @return \OCA\Files_External\Service\UserStoragesService
*/
public function getUserStoragesService() {
@ -1210,4 +1223,5 @@ class Server extends ServerContainer implements IServerContainer {
public function getShareManager() {
return $this->query('ShareManager');
}
}

View File

@ -31,7 +31,7 @@ use OCP\IUser;
*/
interface IUserMountCache {
/**
* Register a mount for a user to the cache
* Register mounts for a user to the cache
*
* @param IUser $user
* @param IMountPoint[] $mounts
@ -59,4 +59,12 @@ interface IUserMountCache {
* @since 9.0.0
*/
public function getMountsForRootId($rootFileId);
/**
* Remove all cached mounts for a user
*
* @param IUser $user
* @since 9.0.0
*/
public function removeUserMounts(IUser $user);
}