|
|
@@ -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);
|
|
|
}
|
|
|
}
|
|
|
|