|
|
@@ -15,6 +15,7 @@ use Opentalent\OtCore\Exception\ApiRequestException;
|
|
|
use Opentalent\OtCore\Utility\FileUtility;
|
|
|
use PDO;
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
+use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
|
|
|
use TYPO3\CMS\Core\Crypto\Random;
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
|
|
@@ -615,31 +616,89 @@ class SiteController extends ActionController
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Update the `sys_template`.`constants` field of the given
|
|
|
- * organization's website with the data fetched from the opentalent DB.
|
|
|
+ * 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
|
|
|
+ * - Update the `sys_template`.`constants` field
|
|
|
+ * - (deep update only) Reset the users permissions
|
|
|
+ * - [todo] Reset the routing index
|
|
|
+ * - 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)
|
|
|
* @return int
|
|
|
+ * @throws NoSuchCacheException
|
|
|
+ * @throws NoSuchRecordException
|
|
|
* @throws NoSuchWebsiteException
|
|
|
+ * @throws \Doctrine\DBAL\ConnectionException
|
|
|
+ * @throws \Doctrine\DBAL\DBALException
|
|
|
+ * @throws \Throwable
|
|
|
*/
|
|
|
- public function updateSiteConstantsAction(int $organizationId): int
|
|
|
+ public function updateSiteAction(int $organizationId, bool $deep=false): int
|
|
|
{
|
|
|
$rootUid = $this->findRootUidFor($organizationId);
|
|
|
|
|
|
+ $organization = $this->fetchOrganization($organizationId);
|
|
|
+ $organizationDomain = $organization->getSubDomain() . '.opentalent.fr';
|
|
|
+
|
|
|
// This extra-data can not be retrieved from the API for now, but
|
|
|
// this shall be set up as soon as possible, to avoid requesting
|
|
|
// the prod-back DB directly.
|
|
|
$organizationExtraData = $this->fetchOrganizationExtraData($organizationId);
|
|
|
|
|
|
- $constants = $this->getTemplateConstants($organizationId, $organizationExtraData);
|
|
|
+ // start transactions
|
|
|
+ $this->connectionPool->getConnectionByName('Default')->beginTransaction();
|
|
|
|
|
|
- $queryBuilder = $this->connectionPool->getQueryBuilderForTable('sys_template');
|
|
|
- $queryBuilder
|
|
|
- ->update('sys_template')
|
|
|
- ->set('constants', $constants)
|
|
|
- ->where($queryBuilder->expr()->eq('pid', $rootUid))
|
|
|
- ->execute();
|
|
|
+ // keep tracks of the created folders and files to be able to remove them during a rollback
|
|
|
+ try {
|
|
|
+ // ## Update the pages table (structure id, structure domain)
|
|
|
+ $sitePages = $this->otPageRepository->getAllSitePages($rootUid);
|
|
|
+ foreach ($sitePages as $page) {
|
|
|
+ $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
|
|
|
+ $queryBuilder->update('pages')
|
|
|
+ ->set('tx_opentalent_structure_id', $organizationId)
|
|
|
+ ->set('tx_opentalent_structure_domain', $organizationDomain)
|
|
|
+ ->where($queryBuilder->expr()->eq('uid', $page['uid']))
|
|
|
+ ->execute();
|
|
|
+ }
|
|
|
|
|
|
+ // ## Update the config.yaml file
|
|
|
+ if ($deep) {
|
|
|
+ $this->writeConfigFile($organizationId, $rootUid, $organizationDomain, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ## Update the `sys_template`.`constants` field
|
|
|
+ $constants = $this->getTemplateConstants($organizationId, $organizationExtraData);
|
|
|
+
|
|
|
+ $queryBuilder = $this->connectionPool->getQueryBuilderForTable('sys_template');
|
|
|
+ $queryBuilder
|
|
|
+ ->update('sys_template')
|
|
|
+ ->set('constants', $constants)
|
|
|
+ ->where($queryBuilder->expr()->eq('pid', $rootUid))
|
|
|
+ ->execute();
|
|
|
+
|
|
|
+ // ## Reset the users permissions
|
|
|
+ if ($deep) {
|
|
|
+ $this->resetBeUserPermsAction($organizationId, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ## Reset the routing index
|
|
|
+ // TODO: complete
|
|
|
+
|
|
|
+ // Try to commit the result
|
|
|
+ $commitSuccess = $this->connectionPool->getConnectionByName('Default')->commit();
|
|
|
+ if (!$commitSuccess) {
|
|
|
+ throw new \RuntimeException('Something went wrong while committing the result');
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch(\Throwable $e) {
|
|
|
+ // rollback
|
|
|
+ $this->connectionPool->getConnectionByName('Default')->rollback();
|
|
|
+ throw $e;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ## Clear the Typo3 cache for the website
|
|
|
OtCacheManager::clearSiteCache($rootUid, true);
|
|
|
return $rootUid;
|
|
|
}
|
|
|
@@ -1770,7 +1829,8 @@ class SiteController extends ActionController
|
|
|
'slug' => $slug,
|
|
|
'backend_layout' => 'flux__grid',
|
|
|
'backend_layout_next_level' => 'flux__grid',
|
|
|
- 'tx_opentalent_structure_id' => $organization->getId()
|
|
|
+ 'tx_opentalent_structure_id' => $organization->getId(),
|
|
|
+ 'tx_opentalent_structure_domain' => $organization->getSubDomain() . '.opentalent.fr',
|
|
|
];
|
|
|
|
|
|
if ($template) {
|
|
|
@@ -1808,7 +1868,8 @@ class SiteController extends ActionController
|
|
|
self::TEMPLATE_HOME,
|
|
|
[
|
|
|
'is_siteroot' => 1,
|
|
|
- 'TSconfig' => 'TCAdefaults.pages.tx_opentalent_structure_id =' . $organization->getId(),
|
|
|
+ 'TSconfig' => 'TCAdefaults.pages.tx_opentalent_structure_id =' . $organization->getId() . '\n' .
|
|
|
+ 'TCAdefaults.pages.tx_opentalent_structure_domain = ' . $organization->getSubDomain() . '.opentalent.fr',
|
|
|
'tx_opentalent_template' => self::DEFAULT_THEME,
|
|
|
'tx_opentalent_template_preferences' => '{"themeColor":"' . self::DEFAULT_COLOR . '","displayCarousel":"1"}'
|
|
|
]
|
|
|
@@ -2046,9 +2107,8 @@ class SiteController extends ActionController
|
|
|
* @param int $rootUid
|
|
|
* @param string $domain
|
|
|
* @param bool $forceRecreate
|
|
|
- * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
|
|
|
*/
|
|
|
- private function writeConfigFile(int $organizationId, int $rootUid, string $domain, bool $forceRecreate = false): string
|
|
|
+ private function writeConfigFile(int $organizationId, int $rootUid, string $domain, bool $forceRecreate = false): void
|
|
|
{
|
|
|
$existing = $this->findConfigFileAndContentFor($rootUid);
|
|
|
$configFilename = $existing[0];
|
|
|
@@ -2122,11 +2182,12 @@ class SiteController extends ActionController
|
|
|
}
|
|
|
|
|
|
// Flush cache:
|
|
|
- $cacheSystem = $this->cacheManager->getCache('cache_core');
|
|
|
- $cacheSystem->remove('site-configuration');
|
|
|
- $cacheSystem->remove('pseudo-sites');
|
|
|
-
|
|
|
- return $configFilename;
|
|
|
+ try {
|
|
|
+ $cacheSystem = $this->cacheManager->getCache('cache_core');
|
|
|
+ $cacheSystem->remove('site-configuration');
|
|
|
+ $cacheSystem->remove('pseudo-sites');
|
|
|
+ } catch (NoSuchCacheException $e) {
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|