Переглянути джерело

handle the deleted root page case in getWebsiteRootUid

Olivier Massot 4 роки тому
батько
коміт
a0fff1bfaa
1 змінених файлів з 7 додано та 2 видалено
  1. 7 2
      ot_core/Classes/Website/OtWebsiteRepository.php

+ 7 - 2
ot_core/Classes/Website/OtWebsiteRepository.php

@@ -3,6 +3,7 @@
 namespace Opentalent\OtCore\Website;
 
 use Opentalent\OtCore\Exception\InvalidWebsiteConfigurationException;
+use Opentalent\OtCore\Exception\NoSuchRecordException;
 use Opentalent\OtCore\Exception\NoSuchWebsiteException;
 use Opentalent\OtCore\Utility\RouteNormalizer;
 use Symfony\Component\Yaml\Yaml;
@@ -111,7 +112,7 @@ class OtWebsiteRepository
             ->execute()
             ->fetch();
         if (!isset($website['uid'])) {
-            throw new NoSuchWebsiteException('No website found for page ' . $pageUid);
+            throw new NoSuchWebsiteException('No website found for identifier ' . $identifier);
         }
         return $website;
     }
@@ -128,13 +129,17 @@ class OtWebsiteRepository
         if (!$withRestrictions) {
             $queryBuilder->getRestrictions()->removeAll();
         }
-        return $queryBuilder
+        $rootUid = $queryBuilder
             ->select('uid')
             ->from('pages')
             ->where($queryBuilder->expr()->eq('ot_website_uid', $websiteUid))
             ->andWhere($queryBuilder->expr()->eq('is_siteroot', 1))
             ->execute()
             ->fetchColumn(0);
+        if (!$rootUid > 0) {
+            throw new NoSuchRecordException('No root page found for website ' . $websiteUid);
+        }
+        return $rootUid;
     }
 
     /**