Forráskód Böngészése

fix duplicated be_users at first reset-perms run

Olivier Massot 4 éve
szülő
commit
e75a87abf8
1 módosított fájl, 30 hozzáadás és 25 törlés
  1. 30 25
      ot_admin/Classes/Controller/SiteController.php

+ 30 - 25
ot_admin/Classes/Controller/SiteController.php

@@ -2286,36 +2286,41 @@ class SiteController extends ActionController
             $this->getBaseBeGroupUid(self::BEGROUP_ADMIN_PREMIUM)
         ];
 
-        $editorsGroupUid = $this->findEditorsBeGroupUid($rootUid);
+        $adminUid = null;
 
-        $queryBuilder = $this->connectionPool->getQueryBuilderForTable('be_users');
-        if (!$withRestrictions) {
-            $queryBuilder->getRestrictions()->removeAll();
-        }
-        $beUsers = $queryBuilder
-            ->select('uid', 'usergroup')
-            ->from('be_users')
-            ->where('FIND_IN_SET(' . $rootUid . ', db_mountpoints) > 0')
-            ->execute()
-            ->fetchAll();
+        try {
+            $editorsGroupUid = $this->findEditorsBeGroupUid($rootUid);
 
-        $adminUid = null;
-        foreach ($beUsers as $beUser) {
-            // the admin shall be both in the website editors group and in the Admin group
-            $isAdmin = false;
-            $isInThisWebsiteGroup = false;
-            foreach (explode(',', $beUser['usergroup']) as $group) {
-                if (in_array($group, $adminGroups)) {
-                    $isAdmin = true;
-                }
-                if ($group == $editorsGroupUid) {
-                    $isInThisWebsiteGroup = true;
-                }
+            $queryBuilder = $this->connectionPool->getQueryBuilderForTable('be_users');
+            if (!$withRestrictions) {
+                $queryBuilder->getRestrictions()->removeAll();
             }
+            $beUsers = $queryBuilder
+                ->select('uid', 'usergroup')
+                ->from('be_users')
+                ->where('FIND_IN_SET(' . $rootUid . ', db_mountpoints) > 0')
+                ->execute()
+                ->fetchAll();
+
+            foreach ($beUsers as $beUser) {
+                // the admin shall be both in the website editors group and in the Admin group
+                $isAdmin = false;
+                $isInThisWebsiteGroup = false;
+                foreach (explode(',', $beUser['usergroup']) as $group) {
+                    if (in_array($group, $adminGroups)) {
+                        $isAdmin = true;
+                    }
+                    if ($group == $editorsGroupUid) {
+                        $isInThisWebsiteGroup = true;
+                    }
+                }
 
-            if ($isAdmin && $isInThisWebsiteGroup) {
-                $adminUid = $beUser['uid'];
+                if ($isAdmin && $isInThisWebsiteGroup) {
+                    $adminUid = $beUser['uid'];
+                }
             }
+        } catch (NoSuchRecordException $e) {
+            // the editors group does not exist
         }
 
         // Try to find if there is a be_user who still is in the v8.7 architecture