From e3dbc3d40ccd9874dadb32b59633cb159afddc48 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 3 Dec 2015 16:35:57 +0100 Subject: [PATCH] different strategy in cleaning up after user was deleted we do not listen to deletion hooks anymore, because there is no guarantee that they will be heard - requires that something fetches the CommentsManager first. Instead, in the user deletion routine the clean up method will be called directly. Same way as it happens for files, group memberships, config values. --- lib/private/comments/manager.php | 5 ----- lib/private/comments/managerfactory.php | 1 - lib/private/server.php | 3 +++ lib/private/user/user.php | 2 ++ tests/lib/comments/fakefactory.php | 19 +++++++++++++------ tests/lib/comments/manager.php | 19 +++---------------- 6 files changed, 21 insertions(+), 28 deletions(-) diff --git a/lib/private/comments/manager.php b/lib/private/comments/manager.php index 78b2b71c8d..bb0782c77f 100644 --- a/lib/private/comments/manager.php +++ b/lib/private/comments/manager.php @@ -23,15 +23,10 @@ class Manager implements ICommentsManager { public function __construct( IDBConnection $dbConn, - Emitter $userManager, ILogger $logger ) { $this->dbConn = $dbConn; $this->logger = $logger; - $userManager->listen('\OC\User', 'postDelete', function($user) { - /** @var \OCP\IUser $user */ - $this->deleteReferencesOfActor('user', $user->getUid()); - }); } /** diff --git a/lib/private/comments/managerfactory.php b/lib/private/comments/managerfactory.php index 71d73571b1..0c9fce3e64 100644 --- a/lib/private/comments/managerfactory.php +++ b/lib/private/comments/managerfactory.php @@ -17,7 +17,6 @@ class ManagerFactory implements ICommentsManagerFactory { public function getManager() { return new Manager( \oc::$server->getDatabaseConnection(), - \oc::$server->getUserManager(), \oc::$server->getLogger() ); } diff --git a/lib/private/server.php b/lib/private/server.php index ecac18d6a9..8439500706 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -1128,6 +1128,9 @@ class Server extends SimpleContainer implements IServerContainer { return $this->query('NotificationManager'); } + /** + * @return \OCP\Comments\ICommentsManager + */ public function getCommentsManager() { return $this->query('CommentsManager'); } diff --git a/lib/private/user/user.php b/lib/private/user/user.php index d827097ee3..6c89dd06f7 100644 --- a/lib/private/user/user.php +++ b/lib/private/user/user.php @@ -189,6 +189,8 @@ class User implements IUser { // Delete the users entry in the storage table \OC\Files\Cache\Storage::remove('home::' . $this->uid); + + \OC::$server->getCommentsManager()->deleteReferencesOfActor('user', $this->uid); } if ($this->emitter) { diff --git a/tests/lib/comments/fakefactory.php b/tests/lib/comments/fakefactory.php index 202b02f641..cd85a4f34c 100644 --- a/tests/lib/comments/fakefactory.php +++ b/tests/lib/comments/fakefactory.php @@ -10,13 +10,20 @@ */ class Test_Comments_FakeFactory extends Test\TestCase implements \OCP\Comments\ICommentsManagerFactory { - public function testNothing() { - // If there would not be at least one test, phpunit would scream failure - // So we have one and skip it. - $this->markTestSkipped(); - } - public function getManager() { return $this->getMock('\OCP\Comments\ICommentsManager'); } + + public function testOverwriteDefaultManager() { + $config = \oc::$server->getConfig(); + $defaultManagerFactory = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); + + $managerMock = $this->getMock('\OCP\Comments\ICommentsManager'); + + $config->setSystemValue('comments.managerFactory', 'Test_Comments_FakeFactory'); + $manager = \oc::$server->getCommentsManager(); + $this->assertEquals($managerMock, $manager); + + $config->setSystemValue('comments.managerFactory', $defaultManagerFactory); + } } diff --git a/tests/lib/comments/manager.php b/tests/lib/comments/manager.php index 610dfe51a4..35a1c8a2af 100644 --- a/tests/lib/comments/manager.php +++ b/tests/lib/comments/manager.php @@ -475,10 +475,10 @@ class Test_Comments_Manager extends Test\TestCase } public function testDeleteReferencesOfActorWithUserManagement() { - $user = \oc::$server->getUserManager()->createUser('xenia', '123456'); + $user = \OC::$server->getUserManager()->createUser('xenia', '123456'); $this->assertTrue($user instanceof \OCP\IUser); - $manager = $this->getManager(); + $manager = \OC::$server->getCommentsManager(); $comment = $manager->create('user', $user->getUID(), 'file', 'file64'); $comment ->setMessage('Most important comment I ever left on the Internet.') @@ -489,7 +489,7 @@ class Test_Comments_Manager extends Test\TestCase $commentID = $comment->getId(); $user->delete(); - $comment =$manager->get($commentID); + $comment = $manager->get($commentID); $this->assertSame($comment->getActorType(), \OCP\Comments\ICommentsManager::DELETED_USER); $this->assertSame($comment->getActorId(), \OCP\Comments\ICommentsManager::DELETED_USER); } @@ -544,17 +544,4 @@ class Test_Comments_Manager extends Test\TestCase $this->assertTrue($wasSuccessful); } - public function testOverwriteDefaultManager() { - $config = \oc::$server->getConfig(); - $defaultManagerFactory = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); - - $managerMock = $this->getMock('\OCP\Comments\ICommentsManager'); - - $config->setSystemValue('comments.managerFactory', 'Test_Comments_FakeFactory'); - $manager = \oc::$server->getCommentsManager(); - $this->assertEquals($managerMock, $manager); - - $config->setSystemValue('comments.managerFactory', $defaultManagerFactory); - } - }