New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Extend the task "install:fixfolderstructure" to create configured extension directories #290
Merged
Merged
[FEATURE] Extend the task "install:fixfolderstructure" to create configured extension directories #290
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c58a3cc
Add task to create configured directories for installed extensions
websi 94e2f2e
[FEATURE] Extend the task "install:fixfolderstructure" to create conf…
websi dc292cf
Remove empty line
websi 43f7811
Remove errors reported by StyleCI
websi 14be04d
Merge branch 'master' into extension_directories
websi af8ae5b
Remove errors reported by StyleCI
websi ecc1353
Revert "Remove errors reported by StyleCI"
websi 9009c6e
Revert "Remove errors reported by StyleCI"
websi 23b730f
[FEATURE] Extend the task "install:fixfolderstructure" to create conf…
websi 77e84e2
Merge branch 'master' into extension_directories
helhum d60ba99
Update PHPDoc. Remove not needed documentation for "throws"
websi 24905ea
Fix coding style
helhum 0dbe90c
Improve docheader and apply changes to reference manual
helhum 5a7226e
Move folder structure class to install namespace
helhum c5a31d6
Streamline structure creation
helhum 6ee7831
use package manager api directly
helhum b71d3cc
fix class comments
helhum File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
<?php | ||
namespace Helhum\Typo3Console\FolderStructure; | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Core\Utility\StringUtility; | ||
use TYPO3\CMS\Extensionmanager\Utility\EmConfUtility; | ||
use TYPO3\CMS\Install\FolderStructure\DirectoryNode; | ||
use TYPO3\CMS\Install\FolderStructure\RootNode; | ||
use TYPO3\CMS\Install\FolderStructure\StructureFacade; | ||
|
||
/** | ||
* Factory returns extension folder structure object hierarchy | ||
*/ | ||
class ExtensionFactory extends \TYPO3\CMS\Install\FolderStructure\DefaultFactory | ||
{ | ||
/** | ||
* Get default structure object hierarchy | ||
* | ||
* @throws \InvalidArgumentException | ||
* @return StructureFacade | ||
*/ | ||
public function getStructure() | ||
{ | ||
$structure = $this->getDefaultStructureDefinition(); | ||
$structure['children'] = $this->appendStructureDefinition($structure['children'], $this->getExtensionStructureDefinition()); | ||
$rootNode = GeneralUtility::makeInstance(RootNode::class, $structure, null); | ||
return GeneralUtility::makeInstance(StructureFacade::class, $rootNode); | ||
} | ||
|
||
|
||
/** | ||
* Default definition of folder and file structure with dynamic | ||
* permission settings | ||
* | ||
* @return array | ||
*/ | ||
protected function getExtensionStructureDefinition() | ||
{ | ||
/** @var EmConfUtility $emConfUtility */ | ||
$emConfUtility = GeneralUtility::makeInstance(EmConfUtility::class); | ||
$extensions = ExtensionManagementUtility::getLoadedExtensionListArray(); | ||
$structureBase = []; | ||
|
||
foreach ($extensions as $extension) { | ||
$extensionConfiguration = $emConfUtility->includeEmConf([ | ||
'key' => $extension, | ||
'siteRelPath' => ExtensionManagementUtility::siteRelPath($extension) | ||
]); | ||
if ($extensionConfiguration === false) { | ||
continue; | ||
} | ||
|
||
if (isset($extensionConfiguration['uploadfolder']) && (bool)$extensionConfiguration['uploadfolder']) { | ||
$structureBase[] = $this->getExtensionUploadDirectory($extension); | ||
} | ||
|
||
if (!empty($extensionConfiguration['createDirs'])) { | ||
foreach (GeneralUtility::trimExplode(',', $extensionConfiguration['createDirs']) as $directoryToCreate) { | ||
$directory = GeneralUtility::resolveBackPath(PATH_site . $directoryToCreate); | ||
if (StringUtility::beginsWith($directory, PATH_site)) { | ||
// Only create directories within TYPO3 root. | ||
$structureBase[] = $this->getDirectoryNodeByPath(substr($directory, strlen(PATH_site))); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
return $structureBase; | ||
} | ||
|
||
/** | ||
* Extension uploads directory. | ||
* | ||
* | ||
* @param string $extension Extension key | ||
* @return array | ||
*/ | ||
protected function getExtensionUploadDirectory($extension) | ||
{ | ||
return $this->getDirectoryNodeByPath('uploads/tx_' . str_replace('_', '', $extension)); | ||
} | ||
|
||
/** | ||
* Build directory nodes by given $path | ||
* | ||
* @param string $path Path to directory | ||
* @return array | ||
*/ | ||
protected function getDirectoryNodeByPath($path) | ||
{ | ||
$baseNode = []; | ||
$parts = GeneralUtility::trimExplode('/', $path, true); | ||
$node = &$baseNode; | ||
foreach ($parts as $part) { | ||
$node[0] = [ | ||
'name' => $part, | ||
'type' => DirectoryNode::class, | ||
'targetPermission' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask'], | ||
'children' => [] | ||
]; | ||
// Add next directory as children of current node | ||
$node = &$node[0]['children']; | ||
} | ||
return isset($baseNode[0]) ? $baseNode[0] : []; | ||
} | ||
|
||
/** | ||
* Append $original structure definition with $additional structure definition. | ||
* Only add missing nodes. | ||
* | ||
* @param array $original | ||
* @param array $additional | ||
* @return array | ||
*/ | ||
protected function appendStructureDefinition(array $original, array $additional) | ||
{ | ||
foreach ($additional as $additionalStructure) { | ||
$structureKey = false; | ||
foreach ($original as $key => $originalStructure) { | ||
if ($originalStructure['name'] === $additionalStructure['name']) { | ||
$structureKey = $key; | ||
} | ||
} | ||
|
||
if ($structureKey === false) { | ||
// Append key to original | ||
$original[] = $additionalStructure; | ||
} else { | ||
// Append children, if necessary | ||
if (isset($additionalStructure['children'])) { | ||
if (isset($original[$structureKey]['children'])) { | ||
$original[$structureKey]['children'] = $this->appendStructureDefinition( | ||
$original[$structureKey]['children'], | ||
$additionalStructure['children'] | ||
); | ||
} else { | ||
$original[$structureKey]['children'] = $additionalStructure['children']; | ||
} | ||
} | ||
} | ||
} | ||
return $original; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this still the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, can be removed.