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.
This commit is contained in:
parent
2ce2de0ae5
commit
e3dbc3d40c
|
@ -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());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,6 @@ class ManagerFactory implements ICommentsManagerFactory {
|
|||
public function getManager() {
|
||||
return new Manager(
|
||||
\oc::$server->getDatabaseConnection(),
|
||||
\oc::$server->getUserManager(),
|
||||
\oc::$server->getLogger()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue