浏览代码

various fixes

Olivier Massot 4 年之前
父节点
当前提交
f3d9a5c0b0

+ 3 - 2
ot_core/Classes/Domain/Repository/BaseApiRepository.php

@@ -106,10 +106,11 @@ abstract class BaseApiRepository implements LoggerAwareInterface
      *
      * @param string $uri
      * @param array $params
-     * @return array
+     * @return object
      * @throws ApiRequestException
      */
-    protected function getApiFirstRecord(string $uri, $params = []) {
+    protected function getApiFirstRecord(string $uri, $params = []): object
+    {
         $params['page'] = '1';
         $params['totalItems'] = '1';
         $collection = $this->getApiRecords($uri, $params);

+ 5 - 5
ot_core/Classes/Domain/Repository/OrganizationRepository.php

@@ -15,10 +15,10 @@ class OrganizationRepository extends BaseApiRepository
      * Get the organization by Id
      *
      * @param int $id The id of the organization
-     * @return array
+     * @return object
      * @throws ApiRequestException
      */
-    public function findById($id): array
+    public function findById($id): object
     {
         $params = [];
         $params['filter[where][id]'] = $id;
@@ -33,17 +33,17 @@ class OrganizationRepository extends BaseApiRepository
      * Get the organization by name
      *
      * @param string name          The name of the organization
-     * @return array
+     * @return object
      * @throws \Exception
      * @throws ApiRequestException
      */
-    public function findByName($name): array
+    public function findByName($name): object
     {
         $params = [];
         $params['filter[where][name]'] = $name;
         $organization = $this->getApiFirstRecord($this::URI, $params);
         if($organization == null) {
-            throw new \Exception('Organization with name "' . $name . '" does not exist');
+            throw new ApiRequestException('Organization with name "' . $name . '" does not exist');
         }
         return $organization;
     }

+ 4 - 2
ot_core/Classes/Page/OtPageRepository.php

@@ -80,7 +80,7 @@ class OtPageRepository
      * @return array
      */
     public function getRootPageFor($pageUid) {
-        $rootLine = $this->pageService->getRootLine($pageUid);
+        $rootLine = $this->pageService->getRootLine($pageUid, false, true);
 
         for (end($rootLine); key($rootLine)!==null; prev($rootLine)){
             $page = current($rootLine);
@@ -123,8 +123,10 @@ class OtPageRepository
      */
     public function getAllSitePages(int $pageUid, bool $withRestrictions=false) {
         $rootPage = $this->getRootPageFor($pageUid);
+        if (!$rootPage) {
+            return [];
+        }
         return array_merge([$rootPage], $this->getAllSubpagesForPage($rootPage['uid']));
-
     }
 
     /**