瀏覽代碼

fix restrictions appliance on otwebsiterepo

Olivier Massot 4 年之前
父節點
當前提交
86be72aeeb
共有 1 個文件被更改,包括 39 次插入33 次删除
  1. 39 33
      ot_core/Classes/Website/OtWebsiteRepository.php

+ 39 - 33
ot_core/Classes/Website/OtWebsiteRepository.php

@@ -35,14 +35,14 @@ class OtWebsiteRepository
     public function getAll(bool $withRestrictions = true): array
     {
         $queryBuilder = $this->connectionPool->getQueryBuilderForTable('ot_websites');
-        if (!$withRestrictions) {
-            $queryBuilder->getRestrictions()->removeAll();
-        }
-        return $queryBuilder
+        $q = $queryBuilder
             ->select('*')
-            ->from('ot_websites')
-            ->execute()
-            ->fetchAll();
+            ->from('ot_websites');
+        if ($withRestrictions) {
+            $q->where($q->expr()->eq('deleted', 0));
+        }
+        return $q->execute()
+                 ->fetchAll();
     }
 
     /**
@@ -53,15 +53,15 @@ class OtWebsiteRepository
     public function getWebsiteByUid(int $uid, bool $withRestrictions = true): array
     {
         $queryBuilder = $this->connectionPool->getQueryBuilderForTable('ot_websites');
-        if (!$withRestrictions) {
-            $queryBuilder->getRestrictions()->removeAll();
-        }
-        $website = $queryBuilder
+        $q = $queryBuilder
             ->select('*')
             ->from('ot_websites')
-            ->where($queryBuilder->expr()->eq('uid', $uid))
-            ->execute()
-            ->fetch();
+            ->where($queryBuilder->expr()->eq('uid', $uid));
+        if ($withRestrictions) {
+            $q->andWhere($q->expr()->eq('deleted', 0));
+        }
+        $website = $q->execute()->fetch();
+
         if (!isset($website['uid'])) {
             throw new NoSuchWebsiteException('No website found with uid ' . $uid);
         }
@@ -76,15 +76,15 @@ class OtWebsiteRepository
     public function getWebsiteByOrganizationId(int $organizationId, bool $withRestrictions = true): array
     {
         $queryBuilder = $this->connectionPool->getQueryBuilderForTable('ot_websites');
-        if (!$withRestrictions) {
-            $queryBuilder->getRestrictions()->removeAll();
-        }
-        $website = $queryBuilder
+        $q = $queryBuilder
             ->select('*')
             ->from('ot_websites')
-            ->where($queryBuilder->expr()->eq('organization_id', $organizationId))
-            ->execute()
-            ->fetch();
+            ->where($queryBuilder->expr()->eq('organization_id', $organizationId));
+        if ($withRestrictions) {
+            $q->andWhere($q->expr()->eq('deleted', 0));
+        }
+        $website = $q->execute()->fetch();
+
         if (!isset($website['uid'])) {
             throw new NoSuchWebsiteException('No website found for organization ' . $organizationId);
         }
@@ -102,13 +102,15 @@ class OtWebsiteRepository
         if (!$withRestrictions) {
             $queryBuilder->getRestrictions()->removeAll();
         }
-        $website = $queryBuilder
+        $q = $queryBuilder
             ->select('w.*')
             ->from('ot_websites', 'w')
             ->innerJoin('w', 'pages', 'p', $queryBuilder->expr()->eq('p.ot_website_uid', 'w.uid'))
-            ->where($queryBuilder->expr()->eq('p.uid', $pageUid))
-            ->execute()
-            ->fetch();
+            ->where($queryBuilder->expr()->eq('p.uid', $pageUid));
+        if ($withRestrictions) {
+            $q->andWhere($q->expr()->eq('w.deleted', 0));
+        }
+        $website = $q->execute()->fetch();
         if (!isset($website['uid'])) {
             throw new NoSuchWebsiteException('No website found for page ' . $pageUid);
         }
@@ -148,13 +150,15 @@ class OtWebsiteRepository
         if (!$withRestrictions) {
             $queryBuilder->getRestrictions()->removeAll();
         }
-        $rootUid = $queryBuilder
+        $q = $queryBuilder
             ->select('uid')
             ->from('pages')
             ->where($queryBuilder->expr()->eq('ot_website_uid', $websiteUid))
-            ->andWhere($queryBuilder->expr()->eq('is_siteroot', 1))
-            ->execute()
-            ->fetchColumn(0);
+            ->andWhere($queryBuilder->expr()->eq('is_siteroot', 1));
+        if ($withRestrictions) {
+            $q->andWhere($q->expr()->eq('deleted', 0));
+        }
+        $rootUid = $q->execute()->fetchColumn(0);
         if (!$rootUid > 0) {
             throw new NoSuchRecordException('No root page found for website ' . $websiteUid);
         }
@@ -176,14 +180,16 @@ class OtWebsiteRepository
         if (!$withRestrictions) {
             $queryBuilder->getRestrictions()->removeAll();
         }
-        $rootUid = $queryBuilder
+        $q = $queryBuilder
             ->select('p.uid')
             ->from('pages', 'p')
             ->innerJoin('p', 'ot_websites', 'w', $queryBuilder->expr()->eq('p.ot_website_uid', 'w.uid'))
             ->where($queryBuilder->expr()->eq('w.organization_id', $organizationId))
-            ->andWhere($queryBuilder->expr()->eq('p.is_siteroot', 1))
-            ->execute()
-            ->fetchColumn(0);
+            ->andWhere($queryBuilder->expr()->eq('p.is_siteroot', 1));
+        if ($withRestrictions) {
+            $q->andWhere($q->expr()->eq('deleted', 0));
+        }
+        $rootUid = $q->execute()->fetchColumn(0);
         if (!$rootUid) {
             throw new NoSuchWebsiteException("No website found for organization " . $organizationId);
         }