From 374e3475c9e2e0220cc8639a1a06f68b7f43fb2b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 21 Jan 2014 23:58:48 +0100 Subject: [PATCH 1/4] Also remove the user's home storage from the storage table when deleting a user --- lib/private/files/cache/storage.php | 13 +++++++++++++ lib/private/user.php | 3 +++ 2 files changed, 16 insertions(+) diff --git a/lib/private/files/cache/storage.php b/lib/private/files/cache/storage.php index 5657cf06e1..6d7a1002c1 100644 --- a/lib/private/files/cache/storage.php +++ b/lib/private/files/cache/storage.php @@ -70,4 +70,17 @@ class Storage { return false; } } + + /** + * remove the entry for the storage + * + * @param string $storageId + */ + public static function remove($storageId) { + if (strlen($storageId) > 64) { + $storageId = md5($storageId); + } + $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'; + \OC_DB::executeAudited($sql, array($storageId)); + } } diff --git a/lib/private/user.php b/lib/private/user.php index 98ebebbe5c..2519200d0f 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -205,6 +205,9 @@ class OC_User { // Delete user files in /data/ OC_Helper::rmdirr(\OC_User::getHome($uid)); + // Delete the users entry in the storage table + \OC\Files\Cache\Storage::remove('home::' . $uid); + // Remove it from the Cache self::getManager()->delete($uid); } From 5a5b6f187e719e6c0bac5e64c411eb74e6d28389 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 22 Jan 2014 13:00:45 +0100 Subject: [PATCH 2/4] Use Cache->clear to cleanup the filecache for removed users --- lib/private/user.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/private/user.php b/lib/private/user.php index 2519200d0f..7932f4aef7 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -205,8 +205,13 @@ class OC_User { // Delete user files in /data/ OC_Helper::rmdirr(\OC_User::getHome($uid)); - // Delete the users entry in the storage table - \OC\Files\Cache\Storage::remove('home::' . $uid); + // Cleanup the filecache + $mount = \OC\Files\Filesystem::getMountByStorageId('home::' . $uid); + if (count($mount) > 0) { + $mount = $mount[0]; + $cache = $mount->getStorage()->getCache(); + $cache->clear(); + } // Remove it from the Cache self::getManager()->delete($uid); @@ -243,15 +248,15 @@ class OC_User { $uid = $backend->getCurrentUserId(); $run = true; - OC_Hook::emit( "OC_User", "pre_login", array( "run" => &$run, "uid" => $uid )); + OC_Hook::emit("OC_User", "pre_login", array("run" => &$run, "uid" => $uid)); - if($uid) { + if ($uid) { session_regenerate_id(true); self::setUserId($uid); self::setDisplayName($uid); self::getUserSession()->setLoginName($uid); - OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>'' )); + OC_Hook::emit("OC_User", "post_login", array("uid" => $uid, 'password' => '')); return true; } return false; From 8d6a3a00b47aa7d034de378f498a7d5e329a8e1d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 3 Feb 2014 16:29:04 +0100 Subject: [PATCH 3/4] Revert "Use Cache->clear to cleanup the filecache for removed users" This reverts commit 5a5b6f187e719e6c0bac5e64c411eb74e6d28389. --- lib/private/user.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/private/user.php b/lib/private/user.php index 7932f4aef7..2519200d0f 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -205,13 +205,8 @@ class OC_User { // Delete user files in /data/ OC_Helper::rmdirr(\OC_User::getHome($uid)); - // Cleanup the filecache - $mount = \OC\Files\Filesystem::getMountByStorageId('home::' . $uid); - if (count($mount) > 0) { - $mount = $mount[0]; - $cache = $mount->getStorage()->getCache(); - $cache->clear(); - } + // Delete the users entry in the storage table + \OC\Files\Cache\Storage::remove('home::' . $uid); // Remove it from the Cache self::getManager()->delete($uid); @@ -248,15 +243,15 @@ class OC_User { $uid = $backend->getCurrentUserId(); $run = true; - OC_Hook::emit("OC_User", "pre_login", array("run" => &$run, "uid" => $uid)); + OC_Hook::emit( "OC_User", "pre_login", array( "run" => &$run, "uid" => $uid )); - if ($uid) { + if($uid) { session_regenerate_id(true); self::setUserId($uid); self::setDisplayName($uid); self::getUserSession()->setLoginName($uid); - OC_Hook::emit("OC_User", "post_login", array("uid" => $uid, 'password' => '')); + OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>'' )); return true; } return false; From 0ae4022fb4fc6ade3ed300205ccdcdd32863dcdc Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 3 Feb 2014 16:36:21 +0100 Subject: [PATCH 4/4] Also clean up the filecache table when deleting a storage entry --- lib/private/files/cache/storage.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/private/files/cache/storage.php b/lib/private/files/cache/storage.php index 6d7a1002c1..5b1b30176e 100644 --- a/lib/private/files/cache/storage.php +++ b/lib/private/files/cache/storage.php @@ -77,10 +77,16 @@ class Storage { * @param string $storageId */ public static function remove($storageId) { + $storageCache = new Storage($storageId); + $numericId = $storageCache->getNumericId(); + if (strlen($storageId) > 64) { $storageId = md5($storageId); } $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'; \OC_DB::executeAudited($sql, array($storageId)); + + $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?'; + \OC_DB::executeAudited($sql, array($numericId)); } }