Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Classes/Controller/SiteGeneratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions Classes/Dto/SiteGeneratorDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ class SiteGeneratorDto extends BaseDto
*/
protected $feGroupPid = 0;

/**
* @var bool
*/
protected $groupHomePath = false;

/**
* Domain
*
Expand Down Expand Up @@ -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;
}
}
79 changes: 79 additions & 0 deletions Classes/Wizard/StateBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) . '/';
}
}
23 changes: 17 additions & 6 deletions Classes/Wizard/StateCreateBeGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand All @@ -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
Expand Down
31 changes: 28 additions & 3 deletions Classes/Wizard/StateCreateFileMount.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
23 changes: 14 additions & 9 deletions Classes/Wizard/StateCreateFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,6 +31,8 @@ class StateCreateFolder extends StateBase implements SiteGeneratorStateInterface
*/
private $resourceFactory;

private string $folderName;

public function __construct(ResourceFactory $resourceFactory)
{
parent::__construct();
Expand All @@ -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 {
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Classes/Wizard/StateCreateGroupHomeFolder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Oktopuce\SiteGenerator\Wizard;

use TYPO3\CMS\Core\Resource\ResourceFactory;

class StateCreateGroupHomeFolder extends StateCreateFolder {}
4 changes: 4 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ services:
public: true
shared: false

Oktopuce\SiteGenerator\Wizard\StateCreateGroupHomeFolder:
public: true
shared: false

Oktopuce\SiteGenerator\Hook\BackendControllerHook:
public: true
shared: false
1 change: 1 addition & 0 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.tx_sitegenerator {
30 = Oktopuce\SiteGenerator\Wizard\StateCreateFileMount
40 = Oktopuce\SiteGenerator\Wizard\StateCreateFeGroup
50 = Oktopuce\SiteGenerator\Wizard\StateCreateBeGroup
55 = Oktopuce\SiteGenerator\Wizard\StateCreateGroupHomeFolder
60 = Oktopuce\SiteGenerator\Wizard\StateSetPageBeGroup
70 = Oktopuce\SiteGenerator\Wizard\StateSiteConfiguration
80 = Oktopuce\SiteGenerator\Wizard\StateUpdateHomePage
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/Language/fr.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
<source>New folders will be created in fileadmin like : "baseFolderName > Titre du site > SubFolderName"</source>
<target>De nouveaux dossiers seront créés dans fileadmin comme : "baseFolderName > Site Name > SubFolderName"</target>
</trans-unit>
<trans-unit id="form.SecondStepData.newFolderCreationFromGroupHomePath">
<source>New folders will be created in fileadmin like : "groupHomePath > User group uid > SubFolderName"</source>
<target>De nouveaux dossiers seront créés dans fileadmin comme : "groupHomePath > User group uid > SubFolderName"</target>
</trans-unit>
<trans-unit id="form.SecondStepData.baseFolderName">
<source>Base folder name</source>
<target>Nom du dossier de base</target>
Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<trans-unit id="form.SecondStepData.newFolderCreation">
<source>New folders will be created in fileadmin like : "baseFolderName > Site title > SubFolderName"</source>
</trans-unit>
<trans-unit id="form.SecondStepData.newFolderCreationFromGroupHomePath">
<source>New folders will be created in fileadmin like : "groupHomePath > User group uid > SubFolderName"</source>
</trans-unit>
<trans-unit id="form.SecondStepData.baseFolderName">
<source>Base folder name</source>
</trans-unit>
Expand Down Expand Up @@ -112,6 +115,9 @@
<trans-unit id="wizard.fileMount.error">
<source>Create file mount error.</source>
</trans-unit>
<trans-unit id="wizard.fileMount.error.groupHomePathNotValid">
<source>Create file mount error. The groupHomePath is not valid.</source>
</trans-unit>
<trans-unit id="wizard.folderCreation.error">
<source>Directory creation error for "%s".</source>
</trans-unit>
Expand Down
1 change: 1 addition & 0 deletions Resources/Private/Layouts/Default.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<f:asset.css identifier="site_generator" href="EXT:site_generator/Resources/Public/Css/Style.css" />
<form action="{moduleUrl}" method="post" id="SiteGeneratorController" enctype="multipart/form-data" xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers">
<f:form.hidden name="id" value="{id}" />

Expand Down
Loading