Browse Source

throw an error when two websites exist for one structure

Olivier Massot 4 years ago
parent
commit
7ea53a9f55
1 changed files with 7 additions and 2 deletions
  1. 7 2
      ot_admin/Classes/Controller/SiteController.php

+ 7 - 2
ot_admin/Classes/Controller/SiteController.php

@@ -1633,14 +1633,19 @@ class SiteController extends ActionController
     {
     {
         $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
         $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
         $queryBuilder->getRestrictions()->removeAll();
         $queryBuilder->getRestrictions()->removeAll();
-        $rootUid = $queryBuilder
+        $rows = $queryBuilder
             ->select('uid')
             ->select('uid')
             ->from('pages')
             ->from('pages')
             ->where('is_siteroot=1')
             ->where('is_siteroot=1')
             ->andWhere($queryBuilder->expr()->eq('tx_opentalent_structure_id', $organizationId))
             ->andWhere($queryBuilder->expr()->eq('tx_opentalent_structure_id', $organizationId))
             ->execute()
             ->execute()
-            ->fetchColumn(0);
+            ->fetchAll();
+
+        if (count($rows) > 1) {
+            throw new \RuntimeException("More than one website match this organization id");
+        }
 
 
+        $rootUid = (int)$rows[0]['uid'];
         if ($rootUid > 0) {
         if ($rootUid > 0) {
             return $rootUid;
             return $rootUid;
         }
         }