]> source.dussan.org Git - nextcloud-server.git/commitdiff
fixes determining whether former user is a share owner 23702/head
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Mon, 26 Oct 2020 13:00:57 +0000 (14:00 +0100)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Mon, 26 Oct 2020 13:00:57 +0000 (14:00 +0100)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
apps/user_ldap/lib/User/OfflineUser.php
apps/user_ldap/tests/User/OfflineUserTest.php

index 77863da6ac9e02d3019b67fcc3afae807ac88ec3..2f201ca4a46fb8b10c507cbcee86bdcfe2063ee1 100644 (file)
@@ -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;
        }
 }
index 8c8835e96820472412a8b31953da2e14dc8ce443..298e1708a58bcfedfbcfb6d81fab1a3e2230a10f 100644 (file)
@@ -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())