diff --git a/Classes/Controller/SiteGeneratorController.php b/Classes/Controller/SiteGeneratorController.php index 31ce65a..ba223cb 100644 --- a/Classes/Controller/SiteGeneratorController.php +++ b/Classes/Controller/SiteGeneratorController.php @@ -102,9 +102,9 @@ public function __construct( ConfigurationManagerInterface $configurationManager, SiteGeneratorWizard $siteGeneratorWizard ) { + // Get translations $this->getLanguageService()->includeLLFile('EXT:site_generator/Resources/Private/Language/locallang.xlf'); - $this->configurationManager = $configurationManager; $this->settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'SiteGenerator'); @@ -317,12 +317,16 @@ protected function getDataSecondStepAction(): string { $nextStep = $this->buildUriFromRoute('wizard_sitegenerator'); + $groupHomePathArray = explode(':', $GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath']); + $groupHomePathValid = count($groupHomePathArray) === 2 && is_numeric($groupHomePathArray[0]); + $viewVariables = [ 'moduleUrl' => $nextStep, 'siteDto' => $this->siteGeneratorDto, 'siteDtoSaved' => json_encode(serialize($this->siteGeneratorDto)), 'action' => 'generate_site', 'returnurl' => $this->conf['returnurl'], + 'groupHomePathValid' => $groupHomePathValid ]; // Add event to assign more variables to the view (usefull when using your own template) diff --git a/Classes/Dto/SiteGeneratorDto.php b/Classes/Dto/SiteGeneratorDto.php index 3eee034..a48b896 100644 --- a/Classes/Dto/SiteGeneratorDto.php +++ b/Classes/Dto/SiteGeneratorDto.php @@ -84,6 +84,11 @@ class SiteGeneratorDto extends BaseDto */ protected $feGroupPid = 0; + /** + * @var bool + */ + protected $groupHomePath = false; + /** * Domain * @@ -274,4 +279,19 @@ public function getFeGroupPid(): int return $this->feGroupPid; } + /** + * @return bool + */ + public function getGroupHomePath(): bool + { + return $this->groupHomePath; + } + + /** + * @param bool $groupHomePath + */ + public function setGroupHomePath(bool $groupHomePath): void + { + $this->groupHomePath = $groupHomePath; + } } diff --git a/Classes/Wizard/StateBase.php b/Classes/Wizard/StateBase.php index 52bb5f6..fa18b2c 100644 --- a/Classes/Wizard/StateBase.php +++ b/Classes/Wizard/StateBase.php @@ -13,6 +13,7 @@ namespace Oktopuce\SiteGenerator\Wizard; +use Oktopuce\SiteGenerator\Dto\BaseDto; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Log\LogManager; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; @@ -68,4 +69,82 @@ public function getExtensionConfiguration(): array { return ($this->extensionConfiguration == null ? $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['site_generator'] : []); } + + /** + * @return mixed|string + * @throws \Exception + */ + protected function getStorageUidFromGroupHomePath() { + return $this->getGroupHomePathArray()[0]; + } + + /** + * @return mixed|string + * @throws \Exception + */ + protected function getFolderFromGroupHomePath() { + return trim($this->getGroupHomePathArray()[1], '/'); + } + + /** + * @return false|string[] + * @throws \Exception + */ + protected function getGroupHomePathArray() { + $groupHomePathArray = explode(':', $GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath']); + if (count($groupHomePathArray) === 2 && is_numeric($groupHomePathArray[0])) { + return $groupHomePathArray; + } else { + throw new \Exception('The Installation-Wide Option [BE][groupHomePath] was not configured correctly. Should be a combined folder identifier. Eg. 2:groups/'); + } + } + + /** + * @param $siteData + * @return string + * @throws \Exception + */ + public function getSiteFolder($siteData) { + if($siteData->getGroupHomePath()) { + if($siteData->getBeGroupId()) { + return (string) $siteData->getBeGroupId(); + } else { + throw new \Exception('The extension configuration siteFolderName was set to userGroupUid, but the usergroup uid was not found. Please check order of the states. StateCreateBeGroup should come before StateCreateGroupHomeFolder.'); + } + } else { + return strtolower($siteData->getTitleSanitize()); + } + } + + public function getBaseFolderName(BaseDto $siteData) { + if($siteData->getGroupHomePath()) { + return $this->getFolderFromGroupHomePath(); + } else { + return $siteData->getBaseFolderName(); + } + } + + /** + * @param SiteGeneratorWizard $context + * @return int|void + * @throws \Exception + */ + public function getStorageUid(SiteGeneratorWizard $context) { + if($context->getSiteData()->getGroupHomePath()) { + return $this->getStorageUidFromGroupHomePath(); + } else { + $settings = $context->getSettings(); + return (int)$settings['siteGenerator']['wizard']['storageUid']; + } + } + + /** + * @param SiteGeneratorWizard $context + * @return string + * @throws \Exception + */ + public function getSiteFolderCombinedIdentifier(SiteGeneratorWizard $context) { + $siteData = $context->getSiteData(); + return $this->getStorageUid($context) . ':' . $this->getBaseFolderName($siteData) . '/' . $this->getSiteFolder($siteData) . '/'; + } } diff --git a/Classes/Wizard/StateCreateBeGroup.php b/Classes/Wizard/StateCreateBeGroup.php index 31a21d4..de2dafd 100644 --- a/Classes/Wizard/StateCreateBeGroup.php +++ b/Classes/Wizard/StateCreateBeGroup.php @@ -32,20 +32,21 @@ class StateCreateBeGroup extends StateBase implements SiteGeneratorStateInterfac public function process(SiteGeneratorWizard $context): void { // Create BE group - $groupId = $this->createBeGroup($context->getSiteData()); - - $context->getSiteData()->setBeGroupId($groupId); + $groupId = $this->createBeGroup($context); } /** * Create BE group with file mount, DB mount, access lists * - * @param BaseDto $siteData New site data + * @param SiteGeneratorWizard $context * @throws \Exception * @return int The uid of the group created */ - protected function createBeGroup(BaseDto $siteData): int + protected function createBeGroup(SiteGeneratorWizard $context): int { + // New site data + $siteData = $context->getSiteData(); + // Get extension configuration $extensionConfiguration = $this->getExtensionConfiguration(); @@ -61,7 +62,7 @@ protected function createBeGroup(BaseDto $siteData): int 'tables_select' => ($extensionConfiguration['tablesSelect'] ?: null), 'tables_modify' => ($extensionConfiguration['tablesModify'] ?: null), 'explicit_allowdeny' => ($extensionConfiguration['explicitAllowdeny'] ?: null), - 'TSconfig' => 'options.defaultUploadFolder = 1:' . ($siteData->getBaseFolderName() ? $siteData->getBaseFolderName() . '/' : '') . strtolower($siteData->getTitleSanitize()) . '/' +// 'TSconfig' => 'options.defaultUploadFolder = 1:' . ($siteData->getBaseFolderName() ? $siteData->getBaseFolderName() . '/' : '') . strtolower($siteData->getTitleSanitize()) . '/' ]; // Set common mountpoint @@ -83,6 +84,16 @@ protected function createBeGroup(BaseDto $siteData): int // Retrieve uid of user group created $groupId = $tce->substNEWwithIDs[$newUniqueId]; + // Update the TSconfig field + $context->getSiteData()->setBeGroupId($groupId); + unset($data); + $data['be_groups'][$groupId] = [ + 'TSconfig' => 'options.defaultUploadFolder = ' . $this->getSiteFolderCombinedIdentifier($context) + ]; + $tce->start($data, []); + $tce->process_datamap(); + + if ($groupId > 0) { $this->log(LogLevel::NOTICE, 'Create BE group successful (uid = ' . $groupId); // @extensionScannerIgnoreLine diff --git a/Classes/Wizard/StateCreateFileMount.php b/Classes/Wizard/StateCreateFileMount.php index c03b922..c56a426 100644 --- a/Classes/Wizard/StateCreateFileMount.php +++ b/Classes/Wizard/StateCreateFileMount.php @@ -28,15 +28,40 @@ class StateCreateFileMount extends StateBase implements SiteGeneratorStateInterf * * @param SiteGeneratorWizard $context * @return void - */ + * @throws \Exception + */ public function process(SiteGeneratorWizard $context): void { - // Create file mount for site - $mountId = $this->createFileMount($context->getSiteData()); + if($context->getSiteData()->getGroupHomePath()) { + // Get file mount id from global 'groupHomePath' + $mountId = $this->getFromHomePath(); + } else { + // Create file mount for site + $mountId = $this->createFileMount($context->getSiteData()); + } $context->getSiteData()->setMountId($mountId); } + /** + * Get file mount id from global 'groupHomePath' + * + * @throws \Exception + * @return int The uid from the groupHomePath + */ + protected function getFromHomePath(): int + { + // Get mount id from global 'groupHomePath' + [$groupHomeStorageUid, $groupHomeFilter] = explode(':', $GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath'], 2); + + if ((int)$groupHomeStorageUid <= 0 || is_null($groupHomeFilter)) { + $this->log(LogLevel::ERROR, 'Create file mount error. The groupHomePath is not valid.'); + throw new \Exception($this->translate('wizard.fileMount.error.groupHomePathNotValid')); + } + + return (int)$groupHomeStorageUid; + } + /** * Create file mount for site * diff --git a/Classes/Wizard/StateCreateFolder.php b/Classes/Wizard/StateCreateFolder.php index be97b1b..71f77a9 100644 --- a/Classes/Wizard/StateCreateFolder.php +++ b/Classes/Wizard/StateCreateFolder.php @@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Log\LogLevel; use Oktopuce\SiteGenerator\Dto\BaseDto; +use function Symfony\Component\String\s; /** * StateCreateFolder @@ -30,6 +31,8 @@ class StateCreateFolder extends StateBase implements SiteGeneratorStateInterface */ private $resourceFactory; + private string $folderName; + public function __construct(ResourceFactory $resourceFactory) { parent::__construct(); @@ -40,32 +43,34 @@ public function __construct(ResourceFactory $resourceFactory) * Create site folder in fileadmin : base Folder / site title / sub folder * * @param SiteGeneratorWizard $context - * @return void + * @throws \Exception */ public function process(SiteGeneratorWizard $context): void { - $settings = $context->getSettings(); - + $siteData = $context->getSiteData(); // Create folders in storage - $this->createFolders($context->getSiteData(), (int)$settings['siteGenerator']['wizard']['storageUid']); + if ((get_class($this) == 'Oktopuce\SiteGenerator\Wizard\StateCreateGroupHomeFolder' && $siteData->getGroupHomePath()) or + (get_class($this) == 'Oktopuce\SiteGenerator\Wizard\StateCreateFolder' && !$siteData->getGroupHomePath())) { + $this->createFolders($siteData, $context); + } } /** * Create folder "fileadmin/base_folder/sites_title", with sub-folders "documents" and "images" * * @param BaseDto $siteData New site data - * @param int $storageUid The uid of storage to use + * @param SiteGeneratorWizard $context The uid of storage to use * @throws \Exception * * @return void */ - protected function createFolders(BaseDto $siteData, int $storageUid): void + protected function createFolders(BaseDto $siteData, SiteGeneratorWizard $context): void { // Get base folder and sub-folders name to create - $baseFolderName = $siteData->getBaseFolderName(); + $baseFolderName = $this->getBaseFolderName($siteData); $subFolderNames = GeneralUtility::trimExplode(',', $siteData->getSubFolderNames(), true); - if ($storageUid) { + if ($storageUid = $this->getStorageUid($context)) { $storage = $this->resourceFactory->getStorageObject($storageUid); try { @@ -84,7 +89,7 @@ protected function createFolders(BaseDto $siteData, int $storageUid): void } // Create site folder from site title - $newFolder = strtolower($siteData->getTitleSanitize()); + $newFolder = $this->getSiteFolder($siteData); $currentFolder .= '/' . $newFolder; if (!$storage->hasFolderInFolder($newFolder, $baseFolder)) { // Create sub-folder for current site diff --git a/Classes/Wizard/StateCreateGroupHomeFolder.php b/Classes/Wizard/StateCreateGroupHomeFolder.php new file mode 100644 index 0000000..4814c41 --- /dev/null +++ b/Classes/Wizard/StateCreateGroupHomeFolder.php @@ -0,0 +1,7 @@ +New folders will be created in fileadmin like : "baseFolderName > Titre du site > SubFolderName" De nouveaux dossiers seront créés dans fileadmin comme : "baseFolderName > Site Name > SubFolderName" + + New folders will be created in fileadmin like : "groupHomePath > User group uid > SubFolderName" + De nouveaux dossiers seront créés dans fileadmin comme : "groupHomePath > User group uid > SubFolderName" + Base folder name Nom du dossier de base diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 3f8b367..a563b3b 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -36,6 +36,9 @@ New folders will be created in fileadmin like : "baseFolderName > Site title > SubFolderName" + + New folders will be created in fileadmin like : "groupHomePath > User group uid > SubFolderName" + Base folder name @@ -112,6 +115,9 @@ Create file mount error. + + Create file mount error. The groupHomePath is not valid. + Directory creation error for "%s". diff --git a/Resources/Private/Layouts/Default.html b/Resources/Private/Layouts/Default.html index dae43d7..5fbf133 100644 --- a/Resources/Private/Layouts/Default.html +++ b/Resources/Private/Layouts/Default.html @@ -1,3 +1,4 @@ +
diff --git a/Resources/Private/Templates/SiteGenerator/GetDataSecondStep.html b/Resources/Private/Templates/SiteGenerator/GetDataSecondStep.html index 24adaf8..90c401e 100644 --- a/Resources/Private/Templates/SiteGenerator/GetDataSecondStep.html +++ b/Resources/Private/Templates/SiteGenerator/GetDataSecondStep.html @@ -39,15 +39,39 @@

-
- -
-
- -
- -
-
+ + +
+ + +
+ +
+
+
+ +
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+ +
+ +
+
+
+
diff --git a/Resources/Public/Css/Style.css b/Resources/Public/Css/Style.css new file mode 100644 index 0000000..66cf4b9 --- /dev/null +++ b/Resources/Public/Css/Style.css @@ -0,0 +1,15 @@ +body { + background: black!important; +} +input[name="tx_sitegenerator[groupHomePath]"]:checked ~ .siteFolder-groupHomePath { + display:block; +} +input[name="tx_sitegenerator[groupHomePath]"]:checked ~ .siteFolder-siteTitle { + display:none; +} +input[name="tx_sitegenerator[groupHomePath]"] ~ .siteFolder-groupHomePath { + display:none; +} +input[name="tx_sitegenerator[groupHomePath]"] ~ .siteFolder-siteTitle { + display:block; +} diff --git a/ext_conf_template.txt b/ext_conf_template.txt index b8cdb1a..29548e9 100644 --- a/ext_conf_template.txt +++ b/ext_conf_template.txt @@ -30,6 +30,9 @@ groupPrefix = Group # cat=Folder/140/10_BaseFolderName; type=string; label=Site base folder: The name for sites base folder (can be overridden in form) baseFolderName = Website +# cat=Folder/140/10_SiteFolder; type=options[Website title=siteTitle,Backend usergroup uid=userGroupUid]; label=Site folder: The name for site folder. Site title or group uid for used with grouphomepath feature. +siteFolderName = siteTitle + # cat=Folder/140/10_SubFolderNames; type=string; label=Sub-folders to create: The names of the sub-folders to create (comma separated, can be overridden in form) subFolderNames = documents,images