浏览代码

change the update options, add the config_id field to the updated ones

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

+ 9 - 9
ot_admin/Classes/Command/UpdateSiteCommand.php

@@ -48,10 +48,10 @@ class UpdateSiteCommand extends Command
                 "The organization's id in the opentalent DB"
             )
             ->addOption(
-                'deep',
-                'd',
+                'hard',
+                null,
                 InputOption::VALUE_NONE,
-                "Performs a deep update (recreate the site config file, reset the be_users permissions)"
+                "Performs an hard update (recreate the site config file, reset the be_users permissions)"
             );
     }
 
@@ -66,7 +66,7 @@ class UpdateSiteCommand extends Command
     {
         $org_id = $input->getArgument('organization-id');
         $all = $input->getOption('all');
-        $deep = $input->getOption('deep');
+        $hard = $input->getOption('hard');
 
         if ($all && $org_id) {
             throw new \InvalidArgumentException("You can not pass both an organization id and the --all option");
@@ -79,7 +79,7 @@ class UpdateSiteCommand extends Command
 
         $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
 
-        $msg_deep = $deep ? 'deeply ' : '';
+        $msg_hard = $hard ? 'hardly ' : '';
 
         if ($all) {
             $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
@@ -97,7 +97,7 @@ class UpdateSiteCommand extends Command
             foreach ($sites as $site) {
                 $org_id = $site['organization_id'];
                 try {
-                    $siteController->updateSiteAction($org_id, $deep);
+                    $siteController->updateSiteAction($org_id, $hard);
                 } catch (\Throwable $e) {
                     $io->error('Organization Id: ' . $org_id . ' - ' . $e->getMessage());
                 }
@@ -105,10 +105,10 @@ class UpdateSiteCommand extends Command
             }
             $io->progressFinish();
 
-            $io->success(sprintf("The websites have all been " . $msg_deep . "updated"));
+            $io->success(sprintf("The websites have all been " . $msg_hard . "updated"));
         } else {
-            $rootUid = $siteController->updateSiteAction($org_id, $deep);
-            $io->success(sprintf("The website with root uid " . $rootUid . " has been " . $msg_deep . "updated"));
+            $rootUid = $siteController->updateSiteAction($org_id, $hard);
+            $io->success(sprintf("The website with root uid " . $rootUid . " has been " . $msg_hard . "updated"));
         }
     }
 }

+ 20 - 18
ot_admin/Classes/Controller/SiteController.php

@@ -5,6 +5,7 @@ namespace Opentalent\OtAdmin\Controller;
 use http\Exception\RuntimeException;
 use Opentalent\OtAdmin\Domain\Entity\SiteInfos;
 use Opentalent\OtAdmin\Domain\Entity\SiteStatus;
+use Opentalent\OtCore\Exception\NoSuchOrganizationException;
 use Opentalent\OtCore\Exception\NoSuchRecordException;
 use Opentalent\OtCore\Exception\NoSuchWebsiteException;
 use Opentalent\OtCore\Cache\OtCacheManager;
@@ -624,14 +625,13 @@ class SiteController extends ActionController
      * Performs an update of the organization's website based on data fetched from the opentalent DB:
      *
      * - Update the pages table (structure id, structure domain)
-     * - (deep update only) Update the config.yaml file
+     * - (hard update only) Update the config.yaml file
      * - Update the `sys_template`.`constants` and the `pages`.`TSConfig` fields
-     * - (deep update only) Reset the users permissions
-     * - [todo] Reset the routing index
+     * - (hard update only) Reset the users permissions
      * - Clear the Typo3 cache for the website
      *
      * @param int $organizationId
-     * @param bool $deep Performs a deep update (recreate the site config file, reset the be_users permissions)
+     * @param bool $hard Performs an hard update (recreate the site config file, reset the be_users permissions)
      * @return int
      * @throws NoSuchCacheException
      * @throws NoSuchRecordException
@@ -640,7 +640,7 @@ class SiteController extends ActionController
      * @throws \Doctrine\DBAL\DBALException
      * @throws \Throwable
      */
-    public function updateSiteAction(int $organizationId, bool $deep=false): int
+    public function updateSiteAction(int $organizationId, bool $hard=false): int
     {
         $website = $this->otWebsiteRepository->getWebsiteByOrganizationId($organizationId);
         $rootUid = $this->otWebsiteRepository->getWebsiteRootUid($website['uid']);
@@ -652,6 +652,9 @@ class SiteController extends ActionController
         // the prod-back DB directly.
         $organizationExtraData = $this->fetchOrganizationExtraData($organizationId);
 
+        // Get the website config identifier if exists
+        $identifier = $this->otWebsiteRepository->findConfigIdentifierFor($rootUid);
+
         // start transactions
         $this->connectionPool->getConnectionByName('Default')->beginTransaction();
 
@@ -660,25 +663,27 @@ class SiteController extends ActionController
 
             // ## Update the ot_website table
             $queryBuilder = $this->connectionPool->getQueryBuilderForTable('ot_websites');
-            $queryBuilder->update('ot_websites')
+            $q = $queryBuilder->update('ot_websites')
                 ->set('subdomain', $organization->getSubDomain())
-                ->set('organization_name', $organization->getName())
-                ->where($queryBuilder->expr()->eq('uid', $website['uid']))
-                ->execute();
+                ->set('organization_name', $organization->getName());
+            if ($identifier) {
+                $q->set('config_identifier', $identifier);
+            }
+            $q->where($queryBuilder->expr()->eq('uid', $website['uid']))
+              ->execute();
             
-            // ## Update the root page's subpages
+            // ## Update the subpages of the rootpage
             $sitePages = $this->otPageRepository->getAllSubpagesForPage($rootUid);
             foreach ($sitePages as $page) {
                 $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
                 $queryBuilder->update('pages')
                     ->set('ot_website_uid', $website['uid'])
-                    ->set('TSconfig', null)
                     ->where($queryBuilder->expr()->eq('uid', $page['uid']))
                     ->execute();
             }
 
             // ## Update the config.yaml file
-            if ($deep) {
+            if ($hard) {
                 $organizationDomain = $this->otWebsiteRepository->resolveWebsiteDomain($website);
                 $this->writeConfigFile($organizationId, $rootUid, $organizationDomain, true);
             }
@@ -701,14 +706,10 @@ class SiteController extends ActionController
                 ->execute();
 
             // ## Reset the users permissions
-            if ($deep) {
+            if ($hard) {
                 $this->resetBeUserPermsAction($organizationId, true);
             }
 
-//            // ## Reset the routing index
-//            $routingIndexer = GeneralUtility::makeInstance(ObjectManager::class)->get(Indexer::class);
-//            $routingIndexer->indexRoutesForWebsite($rootUid);
-
             // Try to commit the result
             $commitSuccess = $this->connectionPool->getConnectionByName('Default')->commit();
             if (!$commitSuccess) {
@@ -1732,6 +1733,7 @@ class SiteController extends ActionController
      *
      * @param $organizationId
      * @return Organization
+     * @throws NoSuchOrganizationException
      */
     private function fetchOrganization($organizationId): Organization
     {
@@ -1739,7 +1741,7 @@ class SiteController extends ActionController
         try {
             return $organizationRepository->findById($organizationId);
         } catch (ApiRequestException $e) {
-            throw new \RuntimeException('Unable to fetch the organization with id: ' . $organizationId);
+            throw new NoSuchOrganizationException('Unable to fetch the organization with id: ' . $organizationId);
         }
     }
 

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

@@ -23,7 +23,7 @@ class OrganizationRepository extends BaseApiRepository
         $params = [];
         $params['filter[where][id]'] = $id;
         $organization = $this->getApiFirstRecord($params);
-        if($organization == null) {
+        if ($organization == null) {
             throw new ApiRequestException('Organization with id ' . $id . ' does not exist');
         }
         return $organization;

+ 15 - 0
ot_core/Classes/Exception/NoSuchOrganizationException.php

@@ -0,0 +1,15 @@
+<?php
+
+
+namespace Opentalent\OtCore\Exception;
+
+
+use Exception;
+
+/**
+ * Class NoSuchOrganizationException
+ * Raise this exception when a non-existing organization is fetched via the Opentalent API
+ *
+ * @package Opentalent\OtCore\Exception
+ */
+class NoSuchOrganizationException extends Exception {}

+ 15 - 0
ot_core/Classes/Website/OtWebsiteRepository.php

@@ -427,4 +427,19 @@ class OtWebsiteRepository
         $pathAndConfig = $this->findConfigFileAndContentFor($rootUid);
         return $pathAndConfig[0];
     }
+
+    /**
+     * Find the site configuration identifier of the given website
+     * @param int $rootUid
+     * @return string|null   Config identifier
+     */
+    public function findConfigIdentifierFor(int $rootUid): ?string
+    {
+        $path = $this->findConfigFilePathFor($rootUid);
+        if ($path) {
+            return basename(dirname($path));
+        } else {
+            return null;
+        }
+    }
 }