]> source.dussan.org Git - nextcloud-server.git/commitdiff
Move new methods to a new interface in OCP
authorCôme Chilliet <come.chilliet@nextcloud.com>
Tue, 5 Sep 2023 09:22:40 +0000 (11:22 +0200)
committerCôme Chilliet <come.chilliet@nextcloud.com>
Tue, 5 Sep 2023 14:56:48 +0000 (16:56 +0200)
This avoids breaking compatibility for group backends not based on
 ABackend abstract class.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
apps/user_ldap/lib/Group_Proxy.php
lib/composer/composer/autoload_classmap.php
lib/composer/composer/autoload_static.php
lib/private/Group/Database.php
lib/private/Group/Manager.php
lib/public/Group/Backend/ABackend.php
lib/public/Group/Backend/IBatchMethodsBackend.php [new file with mode: 0644]
lib/public/Group/Backend/IGroupDetailsBackend.php
lib/public/GroupInterface.php

index 43997a09892d32a78ba1a79917fbffcb3b3904d4..114902ff9bad730b6b5784acfdf03ce8034c623f 100644 (file)
 namespace OCA\User_LDAP;
 
 use OC\ServerNotAvailableException;
+use OCP\Group\Backend\IBatchMethodsBackend;
 use OCP\Group\Backend\IDeleteGroupBackend;
 use OCP\Group\Backend\IGetDisplayNameBackend;
 use OCP\Group\Backend\IGroupDetailsBackend;
 use OCP\Group\Backend\INamedBackend;
 use OCP\GroupInterface;
 
-class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend, IDeleteGroupBackend {
+class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend, IDeleteGroupBackend, IBatchMethodsBackend {
        private $backends = [];
        private ?Group_LDAP $refBackend = null;
        private Helper $helper;
index 9bdd0bdc55ff69c71728ab1d83cbf59107d830ff..8fc2438866f22f55e41b1aef21adac41d159bee6 100644 (file)
@@ -421,6 +421,7 @@ return array(
     'OCP\\GroupInterface' => $baseDir . '/lib/public/GroupInterface.php',
     'OCP\\Group\\Backend\\ABackend' => $baseDir . '/lib/public/Group/Backend/ABackend.php',
     'OCP\\Group\\Backend\\IAddToGroupBackend' => $baseDir . '/lib/public/Group/Backend/IAddToGroupBackend.php',
+    'OCP\\Group\\Backend\\IBatchMethodsBackend' => $baseDir . '/lib/public/Group/Backend/IBatchMethodsBackend.php',
     'OCP\\Group\\Backend\\ICountDisabledInGroup' => $baseDir . '/lib/public/Group/Backend/ICountDisabledInGroup.php',
     'OCP\\Group\\Backend\\ICountUsersBackend' => $baseDir . '/lib/public/Group/Backend/ICountUsersBackend.php',
     'OCP\\Group\\Backend\\ICreateGroupBackend' => $baseDir . '/lib/public/Group/Backend/ICreateGroupBackend.php',
index 2cdd9c8d3ca9cd9233201f58680b33f64b8b9b17..fe306545fe32277dac16bf276e585dc8c21c13be 100644 (file)
@@ -454,6 +454,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
         'OCP\\GroupInterface' => __DIR__ . '/../../..' . '/lib/public/GroupInterface.php',
         'OCP\\Group\\Backend\\ABackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ABackend.php',
         'OCP\\Group\\Backend\\IAddToGroupBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IAddToGroupBackend.php',
+        'OCP\\Group\\Backend\\IBatchMethodsBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IBatchMethodsBackend.php',
         'OCP\\Group\\Backend\\ICountDisabledInGroup' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ICountDisabledInGroup.php',
         'OCP\\Group\\Backend\\ICountUsersBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ICountUsersBackend.php',
         'OCP\\Group\\Backend\\ICreateGroupBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ICreateGroupBackend.php',
index 0fcc151363b71a3b65be2ed6f929dfdb8c08558b..4cfc3c1f45a9c37367e3aefa92edbdff7e570d00 100644 (file)
@@ -33,6 +33,7 @@ use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
 use OCP\DB\QueryBuilder\IQueryBuilder;
 use OCP\Group\Backend\ABackend;
 use OCP\Group\Backend\IAddToGroupBackend;
+use OCP\Group\Backend\IBatchMethodsBackend;
 use OCP\Group\Backend\ICountDisabledInGroup;
 use OCP\Group\Backend\ICountUsersBackend;
 use OCP\Group\Backend\ICreateGroupBackend;
@@ -61,6 +62,7 @@ class Database extends ABackend implements
        IRemoveFromGroupBackend,
        ISetDisplayNameBackend,
        ISearchableGroupBackend,
+       IBatchMethodsBackend,
        INamedBackend {
        /** @var array<string, array{gid: string, displayname: string}> */
        private $groupCache = [];
index 924b9a3b6a6dc701e106e123486a4a135cfe02b1..47475121ea0cf51aeb60d4daa3be22497feacc91 100644 (file)
@@ -42,6 +42,7 @@ namespace OC\Group;
 
 use OC\Hooks\PublicEmitter;
 use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Group\Backend\IBatchMethodsBackend;
 use OCP\Group\Backend\IGroupDetailsBackend;
 use OCP\Group\Events\BeforeGroupCreatedEvent;
 use OCP\Group\Events\GroupCreatedEvent;
@@ -212,7 +213,7 @@ class Manager extends PublicEmitter implements IGroupManager {
         * @param array<string, string> $displayNames Array containing already know display name for a groupId
         * @return array<string, IGroup>
         */
-       protected function getGroupsObject(array $gids, array $displayNames = []): array {
+       protected function getGroupsObjects(array $gids, array $displayNames = []): array {
                $backends = [];
                $groups = [];
                foreach ($gids as $gid) {
@@ -224,7 +225,14 @@ class Manager extends PublicEmitter implements IGroupManager {
                foreach ($this->backends as $backend) {
                        if ($backend instanceof IGroupDetailsBackend || $backend->implementsActions(GroupInterface::GROUP_DETAILS)) {
                                /** @var IGroupDetailsBackend $backend */
-                               $groupDatas = $backend->getGroupsDetails($gids);
+                               if ($backend instanceof IBatchMethodsBackend) {
+                                       $groupDatas = $backend->getGroupsDetails($gids);
+                               } else {
+                                       $groupDatas = [];
+                                       foreach ($gids as $gid) {
+                                               $groupDatas[$gid] = $backend->getGroupDetails($gid);
+                                       }
+                               }
                                foreach ($groupDatas as $gid => $groupData) {
                                        if (!empty($groupData)) {
                                                // take the display name from the last backend that has a non-null one
@@ -235,7 +243,11 @@ class Manager extends PublicEmitter implements IGroupManager {
                                        }
                                }
                        } else {
-                               $existingGroups = $backend->groupsExists($gids);
+                               if ($backend instanceof IBatchMethodsBackend) {
+                                       $existingGroups = $backend->groupsExists($gids);
+                               } else {
+                                       $existingGroups = array_filter($gids, fn (string $gid): bool => $backend->groupExists($gid));
+                               }
                                foreach ($existingGroups as $group) {
                                        $backends[$group][] = $backend;
                                }
@@ -243,7 +255,7 @@ class Manager extends PublicEmitter implements IGroupManager {
                }
                foreach ($gids as $gid) {
                        if (count($backends[$gid]) === 0) {
-                                continue;
+                               continue;
                        }
                        $this->cachedGroups[$gid] = new Group($gid, $backends[$gid], $this->dispatcher, $this->userManager, $this, $displayNames[$gid]);
                        $groups[$gid] = $this->cachedGroups[$gid];
@@ -295,7 +307,7 @@ class Manager extends PublicEmitter implements IGroupManager {
                $groups = [];
                foreach ($this->backends as $backend) {
                        $groupIds = $backend->getGroups($search, $limit ?? -1, $offset ?? 0);
-                       $newGroups = $this->getGroupsObject($groupIds);
+                       $newGroups = $this->getGroupsObjects($groupIds);
                        foreach ($newGroups as $groupId => $group) {
                                $groups[$groupId] = $group;
                        }
index 4ce4e4305592568ec75bfae75921deaddaaf6450..274b98655e465e8ad1410ef2f75839113477d3d8 100644 (file)
@@ -31,7 +31,7 @@ use OCP\GroupInterface;
 /**
  * @since 14.0.0
  */
-abstract class ABackend implements GroupInterface {
+abstract class ABackend implements GroupInterface, IBatchMethodsBackend {
        /**
         * @deprecated 14.0.0
         * @since 14.0.0
@@ -68,7 +68,7 @@ abstract class ABackend implements GroupInterface {
        }
 
        /**
-        * @since 26.0.0
+        * @since 28.0.0
         */
        public function groupsExists(array $gids): array {
                return array_values(array_filter(
@@ -78,7 +78,7 @@ abstract class ABackend implements GroupInterface {
        }
 
        /**
-        * @since 26.0.0
+        * @since 28.0.0
         */
        public function getGroupsDetails(array $gids): array {
                if (!($this instanceof IGroupDetailsBackend || $this->implementsActions(GroupInterface::GROUP_DETAILS))) {
diff --git a/lib/public/Group/Backend/IBatchMethodsBackend.php b/lib/public/Group/Backend/IBatchMethodsBackend.php
new file mode 100644 (file)
index 0000000..109f398
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ * @author Carl Schwan <carl@carlschwan.eu>
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCP\Group\Backend;
+
+/**
+ * @brief Optional interface for group backends
+ * @since 28.0.0
+ */
+interface IBatchMethodsBackend {
+       /**
+        * @brief Batch method to check if a list of groups exists
+        *
+        * The default implementation in ABackend will just call groupExists in
+        * a loop. But a GroupBackend implementation should provides a more optimized
+        * override this method to provide a more optimized way to execute this operation.
+        *
+        * @param list<string> $gids
+        * @return list<string> the list of group that exists
+        * @since 28.0.0
+        */
+       public function groupsExists(array $gids): array;
+
+       /**
+        * @brief Batch method to get the group details of a list of groups
+        *
+        * The default implementation in ABackend will just call getGroupDetail in
+        * a loop. But a GroupBackend implementation should provides a more optimized
+        * override this method to provide a more optimized way to execute this operation.
+        *
+        * @throw \RuntimeException if called on a backend that doesn't implements IGroupDetailsBackend
+        *
+        * @return array<string, array{displayName: string}>
+        * @since 28.0.0
+        */
+       public function getGroupsDetails(array $gids): array;
+}
index a102c8c2eecdda8f9d1f5e7ebc1372c9981b8c59..851c10388e0406621f12869d4dfed4106ba2e490 100644 (file)
@@ -41,19 +41,4 @@ interface IGroupDetailsBackend {
         * @since 14.0.0
         */
        public function getGroupDetails(string $gid): array;
-
-
-       /**
-        * @brief Batch method to get the group details of a list of groups
-        *
-        * The default implementation in ABackend will just call getGroupDetail in
-        * a loop. But a GroupBackend implementation should provides a more optimized
-        * override this method to provide a more optimized way to execute this operation.
-        *
-        * @throw \RuntimeException if called on a backend that doesn't implements IGroupDetailsBackend
-        *
-        * @return array<string, array{displayName: string}>
-        * @since 26.0.0
-        */
-       public function getGroupsDetails(array $gids): array;
 }
index 50374e5a9491f96873618bc272047dbbb429867b..599a0eb2ff077abf4d8bda7d3b2ff2a7b170d4fb 100644 (file)
@@ -107,19 +107,6 @@ interface GroupInterface {
         */
        public function groupExists($gid);
 
-       /**
-        * @brief Batch method to check if a list of groups exists
-        *
-        * The default implementation in ABackend will just call groupExists in
-        * a loop. But a GroupBackend implementation should provides a more optimized
-        * override this method to provide a more optimized way to execute this operation.
-        *
-        * @param list<string> $gids
-        * @return list<string> the list of group that exists
-        * @since 25.0.0
-        */
-       public function groupsExists(array $gids): array;
-
        /**
         * @brief Get a list of user ids in a group matching the given search parameters.
         *