summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2015-12-03 16:35:57 +0100
committerArthur Schiwon <blizzz@owncloud.com>2015-12-09 14:34:23 +0100
commite3dbc3d40ccd9874dadb32b59633cb159afddc48 (patch)
tree84495c8990e907cde07185c716afba91fc54a517
parent2ce2de0ae523e91b90c39a91fdcc975f06a7674a (diff)
downloadnextcloud-server-e3dbc3d40ccd9874dadb32b59633cb159afddc48.tar.gz
nextcloud-server-e3dbc3d40ccd9874dadb32b59633cb159afddc48.zip
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.
-rw-r--r--lib/private/comments/manager.php5
-rw-r--r--lib/private/comments/managerfactory.php1
-rw-r--r--lib/private/server.php3
-rw-r--r--lib/private/user/user.php2
-rw-r--r--tests/lib/comments/fakefactory.php19
-rw-r--r--tests/lib/comments/manager.php19
6 files changed, 21 insertions, 28 deletions
diff --git a/lib/private/comments/manager.php b/lib/private/comments/manager.php
index 78b2b71c8dd..bb0782c77fd 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 71d73571b10..0c9fce3e640 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 ecac18d6a9b..8439500706d 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 d827097ee39..6c89dd06f77 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 202b02f6411..cd85a4f34ca 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 610dfe51a47..35a1c8a2af5 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);
- }
-
}