|
@@ -490,7 +490,7 @@ class SiteController extends ActionController
|
|
|
->execute();
|
|
->execute();
|
|
|
|
|
|
|
|
// Create the site config.yaml file
|
|
// Create the site config.yaml file
|
|
|
- $this->writeConfigFile($organizationId, $rootUid, $domain);
|
|
|
|
|
|
|
+ $this->writeConfigFile($organizationId, $rootUid, $domain, true);
|
|
|
|
|
|
|
|
// Create the user_upload directory and update the sys_filemounts table
|
|
// Create the user_upload directory and update the sys_filemounts table
|
|
|
$uploadRelPath = "/user_upload/" . $organizationId;
|
|
$uploadRelPath = "/user_upload/" . $organizationId;
|
|
@@ -1184,6 +1184,36 @@ class SiteController extends ActionController
|
|
|
$warnings);
|
|
$warnings);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Set a new domain for the website.
|
|
|
|
|
+ * If $redirect is true, also add a redirection from the former domain to the new one
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param int $organizationId
|
|
|
|
|
+ * @param string $newDomain
|
|
|
|
|
+ * @param bool $redirect
|
|
|
|
|
+ * @return int
|
|
|
|
|
+ * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
|
|
|
|
|
+ * @throws NoSuchWebsiteException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function setSiteDomainAction(int $organizationId, string $newDomain, bool $redirect = true): int
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!preg_match(
|
|
|
|
|
+ "/([a-z0-9A-Z]\.)*[a-z0-9-]+\.([a-z0-9]{2,24})+(\.co\.([a-z0-9]{2,24})|\.([a-z0-9]{2,24}))*\/?/",
|
|
|
|
|
+ $newDomain
|
|
|
|
|
+ ) && !preg_match(
|
|
|
|
|
+ "/[a-z0-9A-Z-]+\//",
|
|
|
|
|
+ $newDomain
|
|
|
|
|
+ )
|
|
|
|
|
+ ) {
|
|
|
|
|
+ throw new \RuntimeException("The given domain does not seems to be a valid domain: " . $newDomain);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $rootUid = $this->findRootUidFor($organizationId);
|
|
|
|
|
+ $this->writeConfigFile($organizationId, $rootUid, $newDomain);
|
|
|
|
|
+
|
|
|
|
|
+ return $rootUid;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Retrieve the Organization object from the repository and then,
|
|
* Retrieve the Organization object from the repository and then,
|
|
|
* from the Opentalent API
|
|
* from the Opentalent API
|
|
@@ -1506,9 +1536,9 @@ class SiteController extends ActionController
|
|
|
*
|
|
*
|
|
|
* @param int $organizationId
|
|
* @param int $organizationId
|
|
|
* @param int $rootUid
|
|
* @param int $rootUid
|
|
|
- * @return array Configuration of the website
|
|
|
|
|
|
|
+ * @return array Path of the configuration file and parsed configuration of the website
|
|
|
*/
|
|
*/
|
|
|
- protected function findConfigFor(int $organizationId, int $rootUid) {
|
|
|
|
|
|
|
+ protected function findConfigFileAndContentFor(int $organizationId, int $rootUid) {
|
|
|
|
|
|
|
|
$configs_directory = $_ENV['TYPO3_PATH_APP'] . "/config/sites/";
|
|
$configs_directory = $_ENV['TYPO3_PATH_APP'] . "/config/sites/";
|
|
|
$candidates = scandir($configs_directory);
|
|
$candidates = scandir($configs_directory);
|
|
@@ -1520,7 +1550,7 @@ class SiteController extends ActionController
|
|
|
$yamlConfig = Yaml::parseFile($filename);
|
|
$yamlConfig = Yaml::parseFile($filename);
|
|
|
|
|
|
|
|
if ($yamlConfig['rootPageId'] === $rootUid) {
|
|
if ($yamlConfig['rootPageId'] === $rootUid) {
|
|
|
- return $yamlConfig;
|
|
|
|
|
|
|
+ return [$filename, $yamlConfig];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1529,77 +1559,114 @@ class SiteController extends ActionController
|
|
|
foreach ($candidates as $subdir) {
|
|
foreach ($candidates as $subdir) {
|
|
|
$yamlConfig = Yaml::parseFile($filename);
|
|
$yamlConfig = Yaml::parseFile($filename);
|
|
|
if ($yamlConfig['rootPageId'] === $rootUid) {
|
|
if ($yamlConfig['rootPageId'] === $rootUid) {
|
|
|
- return $yamlConfig;
|
|
|
|
|
|
|
+ return [$filename, $yamlConfig];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- throw new \RuntimeException("No config file found for this website");
|
|
|
|
|
|
|
+ return [null, []];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Similar to findConfigFileAndContentFor(), but only returns the parsed configuration
|
|
|
|
|
+ * @param int $organizationId
|
|
|
|
|
+ * @param int $rootUid
|
|
|
|
|
+ * @return array Configuration of the website
|
|
|
|
|
+ */
|
|
|
|
|
+ protected function findConfigFor(int $organizationId, int $rootUid) {
|
|
|
|
|
+ $pathAndConfig = $this->findConfigFileAndContentFor($organizationId, $rootUid);
|
|
|
|
|
+ return $pathAndConfig[1];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Write the .../sites/.../config.yaml file of the given site
|
|
|
|
|
|
|
+ * Similar to findConfigFileAndContentFor(), but only returns the config file path
|
|
|
|
|
+ * @param int $organizationId
|
|
|
|
|
+ * @param int $rootUid
|
|
|
|
|
+ * @return string Path of the config file of the given website
|
|
|
|
|
+ */
|
|
|
|
|
+ protected function findConfigFilePathFor(int $organizationId, int $rootUid) {
|
|
|
|
|
+ $pathAndConfig = $this->findConfigFileAndContentFor($organizationId, $rootUid);
|
|
|
|
|
+ return $pathAndConfig[0];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Create or update the .../sites/.../config.yaml file of the given site
|
|
|
*
|
|
*
|
|
|
* @param int $organizationId
|
|
* @param int $organizationId
|
|
|
* @param int $rootUid
|
|
* @param int $rootUid
|
|
|
* @param string $domain
|
|
* @param string $domain
|
|
|
|
|
+ * @param bool $forceRecreate
|
|
|
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
|
|
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
|
|
|
*/
|
|
*/
|
|
|
- private function writeConfigFile(int $organizationId, int $rootUid, string $domain) {
|
|
|
|
|
|
|
+ private function writeConfigFile(int $organizationId, int $rootUid, string $domain, bool $forceRecreate = false) {
|
|
|
|
|
+
|
|
|
|
|
+ $existing = $this->findConfigFileAndContentFor($organizationId, $rootUid);
|
|
|
|
|
+ $configFilename = $existing[0];
|
|
|
|
|
+ $config = $existing[1];
|
|
|
|
|
|
|
|
$subdomain = explode('.', $domain)[0];
|
|
$subdomain = explode('.', $domain)[0];
|
|
|
|
|
|
|
|
- $config_dir = $_ENV['TYPO3_PATH_APP'] . "/config/sites/" . $subdomain . '_' . $organizationId;
|
|
|
|
|
- $config_filename = $config_dir . "/config.yaml";
|
|
|
|
|
|
|
+ if (!$configFilename) {
|
|
|
|
|
+ $configDir = $_ENV['TYPO3_PATH_APP'] . "/config/sites/" . $subdomain . '_' . $organizationId;
|
|
|
|
|
+ $configFilename = $configDir . "/config.yaml";
|
|
|
|
|
+ $isNew = true;
|
|
|
|
|
|
|
|
- if (file_exists($config_filename)) {
|
|
|
|
|
- throw new \RuntimeException("A file named " . $config_filename . " already exists. Abort.");
|
|
|
|
|
|
|
+ if (file_exists($configFilename)) {
|
|
|
|
|
+ throw new \RuntimeException("A file named " . $configFilename . " already exists. Abort.");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $configDir = dirname($configFilename);
|
|
|
|
|
+ $config['base'] = 'https://' . $domain;
|
|
|
|
|
+ $isNew = false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($isNew || $forceRecreate) {
|
|
|
|
|
+ $config = ['base' => 'https://' . $domain,
|
|
|
|
|
+ 'baseVariants' => [
|
|
|
|
|
+ ['base' => $subdomain . '/',
|
|
|
|
|
+ 'condition' => 'applicationContext == "Development"']
|
|
|
|
|
+ ],
|
|
|
|
|
+ 'errorHandling' => [
|
|
|
|
|
+ ['errorCode' => '404',
|
|
|
|
|
+ 'errorHandler' => 'PHP',
|
|
|
|
|
+ 'errorPhpClassFQCN' => 'Opentalent\OtTemplating\Page\ErrorHandler'],
|
|
|
|
|
+ ['errorCode' => '403',
|
|
|
|
|
+ 'errorHandler' => 'PHP',
|
|
|
|
|
+ 'errorPhpClassFQCN' => 'Opentalent\OtTemplating\Page\ErrorHandler'],
|
|
|
|
|
+ ],
|
|
|
|
|
+ 'flux_content_types' => '',
|
|
|
|
|
+ 'flux_page_templates' => '',
|
|
|
|
|
+ 'languages' => [[
|
|
|
|
|
+ 'title' => 'Fr',
|
|
|
|
|
+ 'enabled' => True,
|
|
|
|
|
+ 'base' => '/',
|
|
|
|
|
+ 'typo3Language' => 'fr',
|
|
|
|
|
+ 'locale' => 'fr_FR',
|
|
|
|
|
+ 'iso-639-1' => 'fr',
|
|
|
|
|
+ 'navigationTitle' => 'Fr',
|
|
|
|
|
+ 'hreflang' => 'fr-FR',
|
|
|
|
|
+ 'direction' => 'ltr',
|
|
|
|
|
+ 'flag' => 'fr',
|
|
|
|
|
+ 'languageId' => '0',
|
|
|
|
|
+ ]],
|
|
|
|
|
+ 'rootPageId' => $rootUid,
|
|
|
|
|
+ 'routes' => []
|
|
|
|
|
+ ];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $config = ['base' => 'https://' . $domain,
|
|
|
|
|
- 'baseVariants'=>[
|
|
|
|
|
- ['base' => $subdomain . '/',
|
|
|
|
|
- 'condition' => 'applicationContext == "Development"']
|
|
|
|
|
- ],
|
|
|
|
|
- 'errorHandling'=>[
|
|
|
|
|
- ['errorCode'=>'404',
|
|
|
|
|
- 'errorHandler'=>'PHP',
|
|
|
|
|
- 'errorPhpClassFQCN'=>'Opentalent\OtTemplating\Page\ErrorHandler'],
|
|
|
|
|
- ['errorCode'=>'403',
|
|
|
|
|
- 'errorHandler'=>'PHP',
|
|
|
|
|
- 'errorPhpClassFQCN'=>'Opentalent\OtTemplating\Page\ErrorHandler'],
|
|
|
|
|
- ],
|
|
|
|
|
- 'flux_content_types'=>'',
|
|
|
|
|
- 'flux_page_templates'=>'',
|
|
|
|
|
- 'languages'=>[[
|
|
|
|
|
- 'title'=>'Fr',
|
|
|
|
|
- 'enabled'=>True,
|
|
|
|
|
- 'base'=>'/',
|
|
|
|
|
- 'typo3Language'=>'fr',
|
|
|
|
|
- 'locale'=>'fr_FR',
|
|
|
|
|
- 'iso-639-1'=>'fr',
|
|
|
|
|
- 'navigationTitle'=>'Fr',
|
|
|
|
|
- 'hreflang'=>'fr-FR',
|
|
|
|
|
- 'direction'=>'ltr',
|
|
|
|
|
- 'flag'=>'fr',
|
|
|
|
|
- 'languageId'=>'0',
|
|
|
|
|
- ]],
|
|
|
|
|
- 'rootPageId'=>$rootUid,
|
|
|
|
|
- 'routes'=>[]
|
|
|
|
|
- ];
|
|
|
|
|
$yamlConfig = Yaml::dump($config, 99, 2);
|
|
$yamlConfig = Yaml::dump($config, 99, 2);
|
|
|
|
|
|
|
|
- if (!file_exists($config_dir)) {
|
|
|
|
|
- $this->mkDir($config_dir);
|
|
|
|
|
|
|
+ if (!file_exists($configDir)) {
|
|
|
|
|
+ $this->mkDir($configDir);
|
|
|
}
|
|
}
|
|
|
- GeneralUtility::writeFile($config_filename, $yamlConfig);
|
|
|
|
|
|
|
+ GeneralUtility::writeFile($configFilename, $yamlConfig);
|
|
|
|
|
|
|
|
// Set the owner and mods, in case www-data is not the one who run this command
|
|
// Set the owner and mods, in case www-data is not the one who run this command
|
|
|
// @see https://www.php.net/manual/fr/function.stat.php
|
|
// @see https://www.php.net/manual/fr/function.stat.php
|
|
|
try {
|
|
try {
|
|
|
$stats = stat($_ENV['TYPO3_PATH_APP'] . '/public/index.php');
|
|
$stats = stat($_ENV['TYPO3_PATH_APP'] . '/public/index.php');
|
|
|
- chown($config_filename, $stats['4']);
|
|
|
|
|
- chgrp($config_filename, $stats['5']);
|
|
|
|
|
- chmod($config_filename, $stats['2']);
|
|
|
|
|
|
|
+ chown($configFilename, $stats['4']);
|
|
|
|
|
+ chgrp($configFilename, $stats['5']);
|
|
|
|
|
+ chmod($configFilename, $stats['2']);
|
|
|
} catch (\TYPO3\CMS\Core\Error\Exception $e) {
|
|
} catch (\TYPO3\CMS\Core\Error\Exception $e) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1609,7 +1676,6 @@ class SiteController extends ActionController
|
|
|
$cacheSystem->remove('pseudo-sites');
|
|
$cacheSystem->remove('pseudo-sites');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* Create the BE user for the website
|
|
* Create the BE user for the website
|
|
|
* The user shall be already created in the Opentalent DB
|
|
* The user shall be already created in the Opentalent DB
|