|
|
@@ -130,6 +130,50 @@ class SiteController extends ActionController
|
|
|
$this->createdFiles = [];
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Return the main informations about the organization's website
|
|
|
+ *
|
|
|
+ * @param int $organizationId
|
|
|
+ * @return array
|
|
|
+ * @throws NoSuchWebsiteException
|
|
|
+ */
|
|
|
+ public function getSiteInfosAction(int $organizationId) {
|
|
|
+ $rootUid = $this->findRootUidFor($organizationId);
|
|
|
+ $config = $this->findConfigFor($organizationId, $rootUid);
|
|
|
+ $extraData = $this->fetchOrganizationExtraData($organizationId);
|
|
|
+
|
|
|
+ $rootPage = $this->otPageRepository->getPage($rootUid);
|
|
|
+
|
|
|
+ $site = [
|
|
|
+ 'rootUid' => $rootUid,
|
|
|
+ 'siteTitle' => $rootPage['title'],
|
|
|
+ 'baseUrl' => $config['base'],
|
|
|
+ 'template' => $rootPage['tx_opentalent_template'],
|
|
|
+ 'preferences' => $rootPage['tx_opentalent_template_preferences'],
|
|
|
+ 'matomo_id' => $rootPage['tx_opentalent_matomo_id'],
|
|
|
+ 'deleted' => $rootPage['deleted'],
|
|
|
+ 'hiddenOrRestricted' => (int)($rootPage['hidden'] || $rootPage['fe_group'] < 0),
|
|
|
+ 'mountedForBeUsers' => []
|
|
|
+ ];
|
|
|
+
|
|
|
+ // Owners
|
|
|
+ $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
|
|
|
+ $queryBuilder->getRestrictions()->removeAll();
|
|
|
+ $beUsers = $queryBuilder
|
|
|
+ ->select('uid', 'username')
|
|
|
+ ->from('be_users')
|
|
|
+ ->where('FIND_IN_SET(' . $rootUid . ', db_mountpoints) > 0')
|
|
|
+ ->execute()
|
|
|
+ ->fetchAll();
|
|
|
+
|
|
|
+ foreach ($beUsers as $beUser) {
|
|
|
+ $site['mountedForBeUsers'][] = $beUser;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $site;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Creates a new website for the given organization, and
|
|
|
* returns the root page uid of the newly created site
|
|
|
@@ -547,8 +591,10 @@ class SiteController extends ActionController
|
|
|
*
|
|
|
* @param int $organizationId
|
|
|
* @return int
|
|
|
+ * @throws NoSuchWebsiteException
|
|
|
*/
|
|
|
- public function updateSiteConstantsAction(int $organizationId) {
|
|
|
+ public function updateSiteConstantsAction(int $organizationId): int
|
|
|
+ {
|
|
|
$rootUid = $this->findRootUidFor($organizationId);
|
|
|
|
|
|
// This extra-data can not be retrieved from the API for now, but
|
|
|
@@ -564,6 +610,8 @@ class SiteController extends ActionController
|
|
|
->set('constants', $constants)
|
|
|
->where($queryBuilder->expr()->eq('pid', $rootUid))
|
|
|
->execute();
|
|
|
+
|
|
|
+ OtCacheManager::clearSiteCache($rootUid, true);
|
|
|
return $rootUid;
|
|
|
}
|
|
|
|
|
|
@@ -990,8 +1038,7 @@ class SiteController extends ActionController
|
|
|
$extraData = $this->fetchOrganizationExtraData($organizationId);
|
|
|
|
|
|
// load site's settings (uncomment if needed)
|
|
|
- // $config_dir = $_ENV['TYPO3_PATH_APP'] . "/config/sites/" . $organization->getSubDomain() . '_' . $organizationId;
|
|
|
- // $config = Yaml::parseFile($config_dir . "/config.yaml");
|
|
|
+ // $config = $this->findConfigFor($organizationId, $rootUid);
|
|
|
|
|
|
// Check site's title
|
|
|
if (trim($rootPage['title']) != trim($organization->getName())) {
|
|
|
@@ -1454,11 +1501,48 @@ class SiteController extends ActionController
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Write the .../sites/.../config.yml file of the given site
|
|
|
+ * Try to find the config file of the website in the less resource-consuming way
|
|
|
+ * and parse it.
|
|
|
+ *
|
|
|
+ * @param int $organizationId
|
|
|
+ * @param int $rootUid
|
|
|
+ * @return array Configuration of the website
|
|
|
+ */
|
|
|
+ protected function findConfigFor(int $organizationId, int $rootUid) {
|
|
|
+
|
|
|
+ $configs_directory = $_ENV['TYPO3_PATH_APP'] . "/config/sites/";
|
|
|
+ $candidates = scandir($configs_directory);
|
|
|
+
|
|
|
+ // try to filter by directory name
|
|
|
+ foreach ($candidates as $subdir) {
|
|
|
+ if (preg_match('/\.*_' . $organizationId . '$/', $subdir)) {
|
|
|
+ $filename = $configs_directory . $subdir . '/config.yaml';
|
|
|
+ $yamlConfig = Yaml::parseFile($filename);
|
|
|
+
|
|
|
+ if ($yamlConfig['rootPageId'] === $rootUid) {
|
|
|
+ return $yamlConfig;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // it wasn't found the easy way, let's look to each file... :(
|
|
|
+ foreach ($candidates as $subdir) {
|
|
|
+ $yamlConfig = Yaml::parseFile($filename);
|
|
|
+ if ($yamlConfig['rootPageId'] === $rootUid) {
|
|
|
+ return $yamlConfig;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new \RuntimeException("No config file found for this website");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Write the .../sites/.../config.yaml file of the given site
|
|
|
*
|
|
|
* @param int $organizationId
|
|
|
* @param int $rootUid
|
|
|
* @param string $domain
|
|
|
+ * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
|
|
|
*/
|
|
|
private function writeConfigFile(int $organizationId, int $rootUid, string $domain) {
|
|
|
|