From 1d9738006acae051cbffafdfc11b22dc7a1f0c2d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Oct 2016 10:55:50 +0200 Subject: [PATCH] Only trigger postDelete hooks when the user was deleted... Signed-off-by: Joas Schilling --- lib/private/user/user.php | 6 +++--- tests/lib/user/user.php | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/private/user/user.php b/lib/private/user/user.php index ea0ebf3d910..a395e02ad28 100644 --- a/lib/private/user/user.php +++ b/lib/private/user/user.php @@ -216,10 +216,10 @@ class User implements IUser { $notification = \OC::$server->getNotificationManager()->createNotification(); $notification->setUser($this->uid); \OC::$server->getNotificationManager()->markProcessed($notification); - } - if ($this->emitter) { - $this->emitter->emit('\OC\User', 'postDelete', array($this)); + if ($this->emitter) { + $this->emitter->emit('\OC\User', 'postDelete', array($this)); + } } return !($result === false); } diff --git a/tests/lib/user/user.php b/tests/lib/user/user.php index 31b2f6769bc..01ba960ba48 100644 --- a/tests/lib/user/user.php +++ b/tests/lib/user/user.php @@ -437,16 +437,17 @@ class User extends \Test\TestCase { public function dataDeleteHooks() { return [ - [true], - [false], + [true, 2], + [false, 1], ]; } /** * @dataProvider dataDeleteHooks * @param bool $result + * @param int $expectedHooks */ - public function testDeleteHooks($result) { + public function testDeleteHooks($result, $expectedHooks) { $hooksCalled = 0; $test = $this; @@ -523,7 +524,7 @@ class User extends \Test\TestCase { $this->restoreService('CommentsManager'); $this->restoreService('NotificationManager'); - $this->assertEquals(2, $hooksCalled); + $this->assertEquals($expectedHooks, $hooksCalled); } public function testGetCloudId() {