From 9c5bd23cf7fccff8f3dee975cc0502f11f1dd3f3 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 26 Oct 2020 14:00:57 +0100 Subject: [PATCH] fixes determining whether former user is a share owner Signed-off-by: Arthur Schiwon --- apps/user_ldap/lib/User/OfflineUser.php | 15 ++++----------- apps/user_ldap/tests/User/OfflineUserTest.php | 8 +++++--- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/apps/user_ldap/lib/User/OfflineUser.php b/apps/user_ldap/lib/User/OfflineUser.php index 77863da6ac..2f201ca4a4 100644 --- a/apps/user_ldap/lib/User/OfflineUser.php +++ b/apps/user_ldap/lib/User/OfflineUser.php @@ -243,29 +243,22 @@ class OfflineUser { */ protected function determineShares() { $query = $this->db->prepare(' - SELECT COUNT(`uid_owner`) + SELECT `uid_owner` FROM `*PREFIX*share` WHERE `uid_owner` = ? ', 1); $query->execute([$this->ocName]); - $sResult = $query->fetchColumn(0); - if ((int)$sResult === 1) { + if ($query->rowCount() > 0) { $this->hasActiveShares = true; return; } $query = $this->db->prepare(' - SELECT COUNT(`owner`) + SELECT `owner` FROM `*PREFIX*share_external` WHERE `owner` = ? ', 1); $query->execute([$this->ocName]); - $sResult = $query->fetchColumn(0); - if ((int)$sResult === 1) { - $this->hasActiveShares = true; - return; - } - - $this->hasActiveShares = false; + $this->hasActiveShares = $query->rowCount() > 0; } } diff --git a/apps/user_ldap/tests/User/OfflineUserTest.php b/apps/user_ldap/tests/User/OfflineUserTest.php index 8c8835e968..298e1708a5 100644 --- a/apps/user_ldap/tests/User/OfflineUserTest.php +++ b/apps/user_ldap/tests/User/OfflineUserTest.php @@ -78,10 +78,12 @@ class OfflineUserTest extends TestCase { public function testHasActiveShares(int $internalOwnerships, int $externalOwnerships, bool $expected) { $queryMock = $this->createMock(Statement::class); $queryMock->expects($this->atLeastOnce()) - ->method('fetchColumn') + ->method('execute'); + $queryMock->expects($this->atLeastOnce()) + ->method('rowCount') ->willReturnOnConsecutiveCalls( - (string)$internalOwnerships, - (string)$externalOwnerships + $internalOwnerships > 0 ? 1 : 0, + $externalOwnerships > 0 ? 1 : 0 ); $this->dbc->expects($this->atLeastOnce())