]> source.dussan.org Git - nextcloud-server.git/commitdiff
enlist only registered sections that also have settings registered to
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Fri, 19 Aug 2016 15:52:33 +0000 (17:52 +0200)
committerJoas Schilling <coding@schilljs.com>
Mon, 22 Aug 2016 06:29:49 +0000 (08:29 +0200)
lib/private/Settings/Manager.php
tests/lib/Settings/ManagerTest.php

index 7574695d709fded3f81c0871cb3f5063010bb195..8451e9659550490b6e015187404bb1570903cc04 100644 (file)
@@ -327,10 +327,6 @@ class Manager implements IManager {
         * @inheritdoc
         */
        public function getAdminSections() {
-               $query = $this->dbc->getQueryBuilder();
-               $query->select(['class', 'priority'])
-                       ->from(self::TABLE_ADMIN_SECTIONS);
-
                // built-in sections
                $sections = [
                         0 => [new Section('server',        $this->l->t('Server settings'), 0)],
@@ -341,7 +337,15 @@ class Manager implements IManager {
                        99 => [new Section('tips-tricks',   $this->l->t('Tips & tricks'), 0)],
                ];
 
+               $query = $this->dbc->getQueryBuilder();
+               $query->selectDistinct('s.class')
+                       ->addSelect('s.priority')
+                       ->from(self::TABLE_ADMIN_SECTIONS, 's')
+                       ->from(self::TABLE_ADMIN_SETTINGS, 'f')
+                       ->where($query->expr()->eq('s.id', 'f.section'))
+               ;
                $result = $query->execute();
+
                while($row = $result->fetch()) {
                        if(!isset($sections[$row['priority']])) {
                                $sections[$row['priority']] = [];
index cd5100eff6d6bb08f5b3ea90e2b5e92032117ef1..4728784167a78fa9a54827880e8d9584f300a1a2 100644 (file)
@@ -136,15 +136,33 @@ class ManagerTest extends TestCase {
 
        public function testGetAdminSections() {
                $qb = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock();
+               $expr = $this->getMockBuilder('OCP\DB\QueryBuilder\IExpressionBuilder')->getMock();
                $qb
                        ->expects($this->once())
                        ->method('select')
-                       ->with(['class', 'priority'])
+                       ->with(['s.class', 's.priority'])
                        ->willReturn($qb);
                $qb
-                       ->expects($this->once())
+                       ->expects($this->exactly(2))
                        ->method('from')
-                       ->with('admin_sections')
+                       ->willReturn($qb);
+               $qb
+                       ->expects($this->at(1))
+                       ->method('from')
+                       ->with('admin_sections', 's')
+                       ->willReturn($qb);
+               $qb
+                       ->expects($this->at(2))
+                       ->method('from')
+                       ->with('admin_settings', 'f')
+                       ->willReturn($qb);
+               $qb
+                       ->expects($this->once())
+                       ->method('expr')
+                       ->willReturn($expr);
+               $qb
+                       ->expects($this->once())
+                       ->method('where')
                        ->willReturn($qb);
                $stmt = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')->getMock();
                $qb